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