[VPlan] Perform DT expensive input DT verification earlier (NFC).
[llvm-project.git] / libcxx / test / std / utilities / format / format.functions / vformat.locale.pass.cpp
blob2cde40d7266645d3af1e1d9ad01a171657225f40
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
10 // UNSUPPORTED: no-localization
11 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
13 // XFAIL: availability-fp_to_chars-missing
15 // <format>
17 // string vformat(const locale& loc, string_view fmt, format_args args);
18 // wstring vformat(const locale& loc, wstring_view fmt, wformat_args args);
20 #include <format>
21 #include <cassert>
22 #include <vector>
24 #include "test_macros.h"
25 #include "format_tests.h"
26 #include "string_literal.h"
27 #include "assert_macros.h"
28 #include "concat_macros.h"
30 auto test = []<class CharT, class... Args>(
31 std::basic_string_view<CharT> expected, std::basic_string_view<CharT> fmt, Args&&... args) constexpr {
32 std::basic_string<CharT> out = std::vformat(std::locale(), fmt, std::make_format_args<context_t<CharT>>(args...));
33 TEST_REQUIRE(out == expected,
34 TEST_WRITE_CONCATENATED(
35 "\nFormat string ", fmt, "\nExpected output ", expected, "\nActual output ", out, '\n'));
38 auto test_exception =
39 []<class CharT, class... Args>(
40 [[maybe_unused]] std::string_view what,
41 [[maybe_unused]] std::basic_string_view<CharT> fmt,
42 [[maybe_unused]] Args&&... args) {
43 TEST_VALIDATE_EXCEPTION(
44 std::format_error,
45 [&]([[maybe_unused]] const std::format_error& e) {
46 TEST_LIBCPP_REQUIRE(
47 e.what() == what,
48 TEST_WRITE_CONCATENATED(
49 "\nFormat string ", fmt, "\nExpected exception ", what, "\nActual exception ", e.what(), '\n'));
51 TEST_IGNORE_NODISCARD std::vformat(std::locale(), fmt, std::make_format_args<context_t<CharT>>(args...)));
54 int main(int, char**) {
55 format_tests<char, execution_modus::full>(test, test_exception);
57 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
58 format_tests_char_to_wchar_t(test);
59 format_tests<wchar_t, execution_modus::full>(test, test_exception);
60 #endif
62 return 0;