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