1//===----------------------------------------------------------------------===//
2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3// See https://llvm.org/LICENSE.txt for license information.
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5//
6//===----------------------------------------------------------------------===//
7
8// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
9
10// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
11
12// XFAIL: availability-fp_to_chars-missing
13
14// <format>
15
16// template<ranges::input_range R, class charT>
17// requires (K == range_format::string || K == range_format::debug_string)
18// struct range-default-formatter<K, R, charT>
19//
20// template<class... Args>
21// string format(format_string<Args...> fmt, Args&&... args);
22// template<class... Args>
23// wstring format(wformat_string<Args...> fmt, Args&&... args);
24
25#include <format>
26#include <cassert>
27
28#include "format.functions.tests.h"
29#include "test_format_string.h"
30#include "test_macros.h"
31#include "assert_macros.h"
32#include "concat_macros.h"
33
34auto test = []<class CharT, class... Args>(
35 std::basic_string_view<CharT> expected, test_format_string<CharT, Args...> fmt, Args&&... args) {
36 std::basic_string<CharT> out = std::format(fmt, std::forward<Args>(args)...);
37 TEST_REQUIRE(out == expected,
38 TEST_WRITE_CONCATENATED(
39 "\nFormat string ", fmt.get(), "\nExpected output ", expected, "\nActual output ", out, '\n'));
40};
41
42auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, Args&&...) {
43 // After P2216 most exceptions thrown by std::format become ill-formed.
44 // Therefore this tests does nothing.
45};
46
47int main(int, char**) {
48 format_tests<char>(check: test, check_exception: test_exception);
49
50#ifndef TEST_HAS_NO_WIDE_CHARACTERS
51 format_tests<wchar_t>(check: test, check_exception: test_exception);
52#endif
53
54 return 0;
55}
56

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