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// <format>
16
17// template<ranges::input_range R, class charT>
18// requires (K == range_format::string || K == range_format::debug_string)
19// struct range-default-formatter<K, R, charT>
20//
21// template<class... Args>
22// string format(format_string<Args...> fmt, Args&&... args);
23// template<class... Args>
24// wstring format(wformat_string<Args...> fmt, Args&&... args);
25
26#include <format>
27#include <cassert>
28
29#include "format.functions.tests.h"
30#include "test_format_string.h"
31#include "test_macros.h"
32#include "assert_macros.h"
33#include "concat_macros.h"
34
35auto test = []<class CharT, class... Args>(
36 std::basic_string_view<CharT> expected, test_format_string<CharT, Args...> fmt, Args&&... args) {
37 std::basic_string<CharT> out = std::format(fmt, std::forward<Args>(args)...);
38 TEST_REQUIRE(out == expected,
39 TEST_WRITE_CONCATENATED(
40 "\nFormat string ", fmt.get(), "\nExpected output ", expected, "\nActual output ", out, '\n'));
41};
42
43auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, Args&&...) {
44 // After P2216 most exceptions thrown by std::format become ill-formed.
45 // Therefore this tests does nothing.
46};
47
48int main(int, char**) {
49 format_tests<char>(check: test, check_exception: test_exception);
50
51#ifndef TEST_HAS_NO_WIDE_CHARACTERS
52 format_tests<wchar_t>(check: test, check_exception: test_exception);
53#endif
54
55 return 0;
56}
57

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