[llvm][llvm-readobj] Add NT_ARM_GCS Linux core note type (#117545)
[llvm-project.git] / libcxx / test / std / utilities / format / format.tuple / format.functions.vformat.pass.cpp
blobf44e81b52b76aa432fa7eedb43e8715abb007c86
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
12 // XFAIL: availability-fp_to_chars-missing
14 // <format>
16 // template<class charT, formattable<charT>... Ts>
17 // struct formatter<pair-or-tuple<Ts...>, charT>
19 // tested in the format functions
21 // string vformat(string_view fmt, format_args args);
22 // wstring vformat(wstring_view fmt, wformat_args args);
24 #include <format>
25 #include <cassert>
27 #include "test_macros.h"
28 #include "format.functions.tests.h"
29 #include "assert_macros.h"
30 #include "concat_macros.h"
32 auto test = []<class CharT, class... Args>(
33 std::basic_string_view<CharT> expected, std::basic_string_view<CharT> fmt, Args&&... args) {
34 std::basic_string<CharT> out = std::vformat(fmt, std::make_format_args<context_t<CharT>>(args...));
35 TEST_REQUIRE(out == expected,
36 TEST_WRITE_CONCATENATED(
37 "\nFormat string ", fmt, "\nExpected output ", expected, "\nActual output ", out, '\n'));
40 auto test_exception =
41 []<class CharT, class... Args>(
42 [[maybe_unused]] std::string_view what,
43 [[maybe_unused]] std::basic_string_view<CharT> fmt,
44 [[maybe_unused]] Args&&... args) {
45 TEST_VALIDATE_EXCEPTION(
46 std::format_error,
47 [&]([[maybe_unused]] const std::format_error& e) {
48 TEST_LIBCPP_REQUIRE(
49 e.what() == what,
50 TEST_WRITE_CONCATENATED(
51 "\nFormat string ", fmt, "\nExpected exception ", what, "\nActual exception ", e.what(), '\n'));
53 TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args<context_t<CharT>>(args...)));
56 int main(int, char**) {
57 run_tests<char>(test, test_exception);
59 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
60 run_tests<wchar_t>(test, test_exception);
61 #endif
63 return 0;