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