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: libcpp-has-no-incomplete-format 11 // TODO FMT Evaluate gcc-12 status 12 // UNSUPPORTED: gcc-12 13 // TODO FMT Investigate AppleClang ICE 14 // UNSUPPORTED: apple-clang-13 15 16 // <format> 17 18 // string vformat(const locale& loc, string_view fmt, format_args args); 19 // wstring vformat(const locale& loc, wstring_view fmt, wformat_args args); 20 21 #include <format> 22 #include <cassert> 23 #include <vector> 24 25 #include "test_macros.h" 26 #include "format_tests.h" 27 #include "string_literal.h" 28 29 auto test = []<string_literal fmt, class CharT, class... Args>(std::basic_string_view<CharT> expected, 30 const Args&... args) constexpr { 31 std::basic_string<CharT> out = 32 std::vformat(std::locale(), fmt.template sv<CharT>(), std::make_format_args<context_t<CharT>>(args...)); 33 assert(out == expected); 34 }; 35 36 auto test_exception = []<class CharT, class... Args>(std::string_view what, std::basic_string_view<CharT> fmt, 37 const Args&... args) { 38 #ifndef TEST_HAS_NO_EXCEPTIONS 39 try { 40 (void)std::vformat(std::locale(), fmt, std::make_format_args<context_t<CharT>>(args...)); 41 assert(false); 42 } catch ([[maybe_unused]] const std::format_error& e) { 43 LIBCPP_ASSERT(e.what() == what); 44 return; 45 } 46 assert(false); 47 #endif 48 (void)what; 49 (void)fmt; 50 (void)sizeof...(args); 51 }; 52 53 int main(int, char**) { 54 format_tests<char>(test, test_exception); 55 56 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 57 format_tests_char_to_wchar_t(test); 58 format_tests<wchar_t>(test, test_exception); 59 #endif 60 61 return 0; 62 } 63