Debian Codegraph @

libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.format.pass.cpp

raw
1 //===----------------------------------------------------------------------===//
2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3 // See https://llvm.org/LICENSE.txt for license information.
4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 //
6 //===----------------------------------------------------------------------===//
7
8 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
9
10 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
11
12 // XFAIL: availability-fp_to_chars-missing
13
14 // [container.adaptors.format]
15 // For each of queue, priority_queue, and stack, the library provides the
16 // following formatter specialization where adaptor-type is the name of the
17 // template:
18 //
19 // template<class charT, class T, formattable<charT> Container, class... U>
20 // struct formatter<adaptor-type<T, Container, U...>, charT>
21
22 // template<class... Args>
23 // string format(format_string<Args...> fmt, Args&&... args);
24 // template<class... Args>
25 // wstring format(wformat_string<Args...> fmt, Args&&... args);
26
27 #include <format>
28 #include <cassert>
29
30 #include "format.functions.tests.h"
31 #include "test_format_string.h"
32 #include "test_macros.h"
33 #include "assert_macros.h"
34 #include "concat_macros.h"
35
36 auto test = []<class CharT, class... Args>(
37 std::basic_string_view<CharT> expected, test_format_string<CharT, Args...> fmt, Args&&... args) {
38 std::basic_string<CharT> out = std::format(fmt, std::forward<Args>(args)...);
39 TEST_REQUIRE(out == expected,
40 TEST_WRITE_CONCATENATED(
41 "\nFormat string ", fmt, "\nExpected output ", expected, "\nActual output ", out, '\n'));
42 };
43
44 auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, Args&&...) {
45 // After P2216 most exceptions thrown by std::format become ill-formed.
46 // Therefore this tests does nothing.
47 };
48
49 int main(int, char**) {
50 format_tests<char>(test, test_exception);
51
52 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
53 format_tests<wchar_t>(test, test_exception);
54 #endif
55
56 return 0;
57 }