| 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, c++20 |
| 9 |
|
| 10 |
// UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME |
| 11 |
|
| 12 |
// TODO FMT This test should not require std::to_chars(floating-point) |
| 13 |
// XFAIL: availability-fp_to_chars-missing |
| 14 |
|
| 15 |
// <format> |
| 16 |
|
| 17 |
// template<class charT, formattable<charT>... Ts> |
| 18 |
// struct formatter<pair-or-tuple<Ts...>, charT> |
| 19 |
// |
| 20 |
// tested in the format functions |
| 21 |
// |
| 22 |
// template<class... Args> |
| 23 |
// string format(format-string<Args...> fmt, const Args&... args); |
| 24 |
// template<class... Args> |
| 25 |
// wstring format(wformat-string<Args...> fmt, const Args&... args); |
| 26 |
|
| 27 |
#include <format> |
| 28 |
#include <cassert> |
| 29 |
|
| 30 |
#include "format.functions.tests.h" |
| 31 |
#include "test_format_string.h" |
| 32 |
#include "test_macros.h" |
| 33 |
#include "assert_macros.h" |
| 34 |
#include "concat_macros.h" |
| 35 |
|
| 36 |
auto test = []<class CharT, class... Args>( |
| 37 |
std::basic_string_view<CharT> expected, test_format_string<CharT, Args...> fmt, Args&&... args) { |
| 38 |
std::basic_string<CharT> out = std::format(fmt, std::forward<Args>(args)...); |
| 39 |
TEST_REQUIRE(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.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 |
run_tests<char>(test, test_exception); |
| 53 |
|
| 54 |
#ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 55 |
run_tests<wchar_t>(test, test_exception); |
| 56 |
#endif |
| 57 |
|
| 58 |
return 0; |
| 59 |
} |