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: GCC-ALWAYS_INLINE-FIXME |
11 | |
12 | // XFAIL: availability-fp_to_chars-missing |
13 | |
14 | // <format> |
15 | |
16 | // template<class... Args> |
17 | // size_t formatted_size(format-string<Args...> fmt, const Args&... args); |
18 | // template<class... Args> |
19 | // size_t formatted_size(wformat-string<Args...> fmt, const 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 | #include "test_format_string.h" |
29 | |
30 | auto test = |
31 | []<class CharT, class... Args>( |
32 | std::basic_string_view<CharT> expected, test_format_string<CharT, Args...> fmt, Args&&... args) constexpr { |
33 | std::size_t size = std::formatted_size(fmt, std::forward<Args>(args)...); |
34 | assert(size == expected.size()); |
35 | }; |
36 | |
37 | auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, Args&&...) { |
38 | // After P2216 most exceptions thrown by std::formatted_siz3 become ill-formed. |
39 | // Therefore this tests does nothing. |
40 | // A basic ill-formed test is done in formatted_size.verify.cpp |
41 | // The exceptions are tested by other functions that don't use the basic-format-string as fmt argument. |
42 | }; |
43 | |
44 | int main(int, char**) { |
45 | format_tests<char, execution_modus::partial>(check: test, check_exception: test_exception); |
46 | |
47 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
48 | format_tests_char_to_wchar_t(check: test); |
49 | format_tests<wchar_t, execution_modus::partial>(check: test, check_exception: test_exception); |
50 | #endif |
51 | |
52 | return 0; |
53 | } |
54 | |