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: no-localization |
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(const locale& loc, |
18 | // format-string<Args...> fmt, const Args&... args); |
19 | // template<class... Args> |
20 | // size_t formatted_size(const locale& loc, |
21 | // wformat-string<Args...> fmt, const Args&... args); |
22 | |
23 | #include <format> |
24 | #include <cassert> |
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 | |
32 | auto test = |
33 | []<class CharT, class... Args>( |
34 | std::basic_string_view<CharT> expected, test_format_string<CharT, Args...> fmt, Args&&... args) constexpr { |
35 | std::size_t size = std::formatted_size(std::locale(), fmt, std::forward<Args>(args)...); |
36 | assert(size == expected.size()); |
37 | }; |
38 | |
39 | auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, Args&&...) { |
40 | // After P2216 most exceptions thrown by std::formatted_siz3 become ill-formed. |
41 | // Therefore this tests does nothing. |
42 | // A basic ill-formed test is done in formatted_size.locale.verify.cpp |
43 | // The exceptions are tested by other functions that don't use the basic-format-string as fmt argument. |
44 | }; |
45 | |
46 | int main(int, char**) { |
47 | format_tests<char, execution_modus::partial>(check: test, check_exception: test_exception); |
48 | |
49 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
50 | format_tests_char_to_wchar_t(check: test); |
51 | format_tests<wchar_t, execution_modus::partial>(check: test, check_exception: test_exception); |
52 | #endif |
53 | |
54 | return 0; |
55 | } |
56 | |