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
9// UNSUPPORTED: no-localization
10// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
11
12// XFAIL: availability-fp_to_chars-missing
13
14// <format>
15
16// template<class... Args>
17// string format(const locale& loc, format-string<Args...> fmt, const Args&... args);
18// template<class... Args>
19// wstring format(const locale& loc, wformat-string<Args...> fmt, const Args&... args);
20
21#include <format>
22#include <cassert>
23#include <iostream>
24#include <vector>
25
26#include "test_macros.h"
27#include "format_tests.h"
28#include "string_literal.h"
29#include "test_format_string.h"
30#include "assert_macros.h"
31#include "concat_macros.h"
32
33auto test =
34 []<class CharT, class... Args>(
35 std::basic_string_view<CharT> expected, test_format_string<CharT, Args...> fmt, Args&&... args) constexpr {
36 std::basic_string<CharT> out = std::format(std::locale(), fmt, std::forward<Args>(args)...);
37 TEST_REQUIRE(
38 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 // A basic ill-formed test is done in format.locale.verify.cpp
47 // The exceptions are tested by other functions that don't use the basic-format-string as fmt argument.
48};
49
50int main(int, char**) {
51 format_tests<char, execution_modus::full>(check: test, check_exception: test_exception);
52
53#ifndef TEST_HAS_NO_WIDE_CHARACTERS
54 format_tests_char_to_wchar_t(check: test);
55 format_tests<wchar_t, execution_modus::full>(check: test, check_exception: test_exception);
56#endif
57
58 return 0;
59}
60

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