| 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 | // XFAIL: availability-fp_to_chars-missing |
| 14 | |
| 15 | // [container.adaptors.format] |
| 16 | // For each of queue, priority_queue, and stack, the library provides the |
| 17 | // following formatter specialization where adaptor-type is the name of the |
| 18 | // template: |
| 19 | // |
| 20 | // template<class charT, class T, formattable<charT> Container, class... U> |
| 21 | // struct formatter<adaptor-type<T, Container, U...>, charT> |
| 22 | |
| 23 | // template<class... Args> |
| 24 | // string format(format_string<Args...> fmt, Args&&... args); |
| 25 | // template<class... Args> |
| 26 | // wstring format(wformat_string<Args...> fmt, Args&&... args); |
| 27 | |
| 28 | #include <format> |
| 29 | #include <cassert> |
| 30 | |
| 31 | #include "format.functions.tests.h" |
| 32 | #include "test_format_string.h" |
| 33 | #include "test_macros.h" |
| 34 | #include "assert_macros.h" |
| 35 | #include "concat_macros.h" |
| 36 | |
| 37 | auto test = []<class CharT, class... Args>( |
| 38 | std::basic_string_view<CharT> expected, test_format_string<CharT, Args...> fmt, Args&&... args) { |
| 39 | std::basic_string<CharT> out = std::format(fmt, std::forward<Args>(args)...); |
| 40 | TEST_REQUIRE(out == expected, |
| 41 | TEST_WRITE_CONCATENATED( |
| 42 | "\nFormat string " , fmt, "\nExpected output " , expected, "\nActual output " , out, '\n')); |
| 43 | }; |
| 44 | |
| 45 | auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, Args&&...) { |
| 46 | // After P2216 most exceptions thrown by std::format become ill-formed. |
| 47 | // Therefore this tests does nothing. |
| 48 | }; |
| 49 | |
| 50 | int main(int, char**) { |
| 51 | format_tests<char>(check: test, check_exception: test_exception); |
| 52 | |
| 53 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 54 | format_tests<wchar_t>(check: test, check_exception: test_exception); |
| 55 | #endif |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |