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 10 // UNSUPPORTED: no-localization 11 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME 12 13 // XFAIL: availability-fp_to_chars-missing 14 15 // <format> 16 17 // template<class... Args> 18 // string format(const locale& loc, format-string<Args...> fmt, const Args&... args); 19 // template<class... Args> 20 // wstring format(const locale& loc, wformat-string<Args...> fmt, const Args&... args); 21 22 #include <format> 23 #include <cassert> 24 #include <iostream> 25 #include <vector> 26 27 #include "test_macros.h" 28 #include "format_tests.h" 29 #include "string_literal.h" 30 #include "test_format_string.h" 31 #include "assert_macros.h" 32 #include "concat_macros.h" 33 34 auto test = 35 []<class CharT, class... Args>( 36 std::basic_string_view<CharT> expected, test_format_string<CharT, Args...> fmt, Args&&... args) constexpr { 37 std::basic_string<CharT> out = std::format(std::locale(), fmt, std::forward<Args>(args)...); 38 TEST_REQUIRE( 39 out == expected, 40 TEST_WRITE_CONCATENATED( 41 "\nFormat string ", fmt.get(), "\nExpected output ", expected, "\nActual output ", out, '\n')); 42 }; 43 44 auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, Args&&...) { 45 // After P2216 most exceptions thrown by std::format become ill-formed. 46 // Therefore this tests does nothing. 47 // A basic ill-formed test is done in format.locale.verify.cpp 48 // The exceptions are tested by other functions that don't use the basic-format-string as fmt argument. 49 }; 50 51 int main(int, char**) { 52 format_tests<char, execution_modus::full>(test, test_exception); 53 54 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 55 format_tests_char_to_wchar_t(test); 56 format_tests<wchar_t, execution_modus::full>(test, test_exception); 57 #endif 58 59 return 0; 60 } 61