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// <format>
17
18// template<class charT, formattable<charT>... Ts>
19// struct formatter<pair-or-tuple<Ts...>, charT>
20//
21// tested in the format functions
22//
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);
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
37auto 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'));
43};
44
45auto 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.
50};
51
52int main(int, char**) {
53 run_tests<char>(check: test, check_exception: test_exception);
54
55#ifndef TEST_HAS_NO_WIDE_CHARACTERS
56 run_tests<wchar_t>(check: test, check_exception: test_exception);
57#endif
58
59 return 0;
60}
61

source code of libcxx/test/std/utilities/format/format.tuple/format.functions.format.pass.cpp