1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // UNSUPPORTED: c++03, c++11, c++14, c++17 |
10 | // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME |
11 | |
12 | // XFAIL: availability-fp_to_chars-missing |
13 | |
14 | // Note this formatter shows additional information when tests are failing. |
15 | // This aids the development. Since other formatters fail in the same fashion |
16 | // they don't have this additional output. |
17 | |
18 | // <format> |
19 | |
20 | // template<class... Args> |
21 | // string format(format-string<Args...> fmt, const Args&... args); |
22 | // template<class... Args> |
23 | // wstring format(wformat-string<Args...> fmt, const Args&... args); |
24 | |
25 | #include <format> |
26 | #include <cassert> |
27 | #include <vector> |
28 | |
29 | #include "test_macros.h" |
30 | #include "format_tests.h" |
31 | #include "string_literal.h" |
32 | #include "test_format_string.h" |
33 | #include "assert_macros.h" |
34 | #include "concat_macros.h" |
35 | |
36 | auto test = |
37 | []<class CharT, class... Args>( |
38 | std::basic_string_view<CharT> expected, test_format_string<CharT, Args...> fmt, Args&&... args) constexpr { |
39 | std::basic_string<CharT> out = std::format(fmt, std::forward<Args>(args)...); |
40 | TEST_REQUIRE( |
41 | out == expected, |
42 | TEST_WRITE_CONCATENATED( |
43 | "\nFormat string " , fmt.get(), "\nExpected output " , expected, "\nActual output " , out, '\n')); |
44 | }; |
45 | |
46 | auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, Args&&...) { |
47 | // After P2216 most exceptions thrown by std::format become ill-formed. |
48 | // Therefore this tests does nothing. |
49 | // A basic ill-formed test is done in format.verify.cpp |
50 | // The exceptions are tested by other functions that don't use the basic-format-string as fmt argument. |
51 | }; |
52 | |
53 | int main(int, char**) { |
54 | format_tests<char, execution_modus::full>(check: test, check_exception: test_exception); |
55 | |
56 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
57 | format_tests_char_to_wchar_t(check: test); |
58 | format_tests<wchar_t, execution_modus::full>(check: test, check_exception: test_exception); |
59 | #endif |
60 | |
61 | return 0; |
62 | } |
63 | |