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// [container.adaptors.format]
16// For each of queue, priority_queue, and stack, the library provides the
17// following formatter specialization where adaptor-type is the name of the
18// template:
19//
20// template<class charT, class T, formattable<charT> Container, class... U>
21// struct formatter<adaptor-type<T, Container, U...>, charT>
22
23// string vformat(string_view fmt, format_args args);
24// wstring vformat(wstring_view fmt, wformat_args args);
25
26#include <format>
27#include <cassert>
28
29#include "format.functions.tests.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, std::basic_string_view<CharT> fmt, Args&&... args) {
36 std::basic_string<CharT> out = std::vformat(fmt, std::make_format_args<context_t<CharT>>(args...));
37 TEST_REQUIRE(out == expected,
38 TEST_WRITE_CONCATENATED(
39 "\nFormat string ", fmt, "\nExpected output ", expected, "\nActual output ", out, '\n'));
40};
41
42auto test_exception =
43 []<class CharT, class... Args>(
44 [[maybe_unused]] std::string_view what,
45 [[maybe_unused]] std::basic_string_view<CharT> fmt,
46 [[maybe_unused]] Args&&... args) {
47 TEST_VALIDATE_EXCEPTION(
48 std::format_error,
49 [&]([[maybe_unused]] const std::format_error& e) {
50 TEST_LIBCPP_REQUIRE(
51 e.what() == what,
52 TEST_WRITE_CONCATENATED(
53 "\nFormat string ", fmt, "\nExpected exception ", what, "\nActual exception ", e.what(), '\n'));
54 },
55 TEST_IGNORE_NODISCARD std::vformat(fmt, std::make_format_args<context_t<CharT>>(args...)));
56 };
57
58int main(int, char**) {
59 format_tests<char>(check: test, check_exception: test_exception);
60
61#ifndef TEST_HAS_NO_WIDE_CHARACTERS
62 format_tests<wchar_t>(check: test, check_exception: test_exception);
63#endif
64
65 return 0;
66}
67

source code of libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.vformat.pass.cpp