1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
11 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
13 // TODO FMT This test should not require std::to_chars(floating-point)
14 // XFAIL: availability-fp_to_chars-missing
18 // template<class charT, formattable<charT>... Ts>
19 // struct formatter<pair-or-tuple<Ts...>, charT>
21 // tested in the format functions
23 // template<class... Args>
24 // string format(format-string<Args...> fmt, const Args&... args);
25 // template<class... Args>
26 // wstring format(wformat-string<Args...> fmt, const Args&... args);
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"
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
.get(), "\nExpected output ", expected
, "\nActual output ", out
, '\n'));
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 // A basic ill-formed test is done in format.verify.cpp
49 // The exceptions are tested by other functions that don't use the basic-format-string as fmt argument.
52 int main(int, char**) {
53 run_tests
<char>(test
, test_exception
);
55 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
56 run_tests
<wchar_t>(test
, test_exception
);