| 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, c++20 |
| 10 | |
| 11 | // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME |
| 12 | |
| 13 | // TODO FMT This test should not require std::to_chars(floating-point) |
| 14 | // XFAIL: availability-fp_to_chars-missing |
| 15 | |
| 16 | // <vector> |
| 17 | |
| 18 | // template<class T, class charT> |
| 19 | // requires is-vector-bool-reference<T> |
| 20 | // struct formatter<T, 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>(check: test, check_exception: test_exception); |
| 51 | |
| 52 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 53 | format_tests<wchar_t>(check: test, check_exception: test_exception); |
| 54 | #endif |
| 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |