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 | // <format> |
15 | |
16 | // template<ranges::input_range R, class charT> |
17 | // struct range-default-formatter<range_format::set, R, charT> |
18 | // |
19 | // template<class... Args> |
20 | // string format(format_string<Args...> fmt, Args&&... args); |
21 | // template<class... Args> |
22 | // wstring format(wformat_string<Args...> fmt, Args&&... args); |
23 | |
24 | #include <format> |
25 | #include <cassert> |
26 | |
27 | #include "format.functions.tests.h" |
28 | #include "test_format_string.h" |
29 | #include "test_macros.h" |
30 | #include "assert_macros.h" |
31 | #include "concat_macros.h" |
32 | |
33 | auto test = []<class CharT, class... Args>( |
34 | std::basic_string_view<CharT> expected, test_format_string<CharT, Args...> fmt, Args&&... args) { |
35 | std::basic_string<CharT> out = std::format(fmt, std::forward<Args>(args)...); |
36 | TEST_REQUIRE(out == expected, |
37 | TEST_WRITE_CONCATENATED( |
38 | "\nFormat string " , fmt.get(), "\nExpected output " , expected, "\nActual output " , out, '\n')); |
39 | }; |
40 | |
41 | auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, Args&&...) { |
42 | // After P2216 most exceptions thrown by std::format become ill-formed. |
43 | // Therefore this tests does nothing. |
44 | }; |
45 | |
46 | int main(int, char**) { |
47 | format_tests<char>(check: test, check_exception: test_exception); |
48 | |
49 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
50 | format_tests<wchar_t>(check: test, check_exception: test_exception); |
51 | #endif |
52 | |
53 | return 0; |
54 | } |
55 | |