1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef TEST_STD_THREAD_THREAD_THREADS_THREAD_THREAD_CLASS_THREAD_THREAD_ID_FORMAT_FUNCTIONS_TESTS_H
10 #define TEST_STD_THREAD_THREAD_THREADS_THREAD_THREAD_CLASS_THREAD_THREAD_ID_FORMAT_FUNCTIONS_TESTS_H
14 #include "format.functions.common.h"
15 #include "test_macros.h"
17 template <class CharT
, class TestFunction
, class ExceptionTest
>
18 void format_tests(TestFunction check
, ExceptionTest check_exception
) {
19 // Note the output of std::thread::id is unspecified. The output text is the
20 // same as the stream operator. Since that format is already released this
21 // test follows the practice on existing systems.
22 std::thread::id input
{};
24 /***** Test the type specific part *****/
25 #if !defined(__APPLE__) && !defined(__FreeBSD__)
26 check(SV("0"), SV("{}"), input
);
27 check(SV("0^42"), SV("{}^42"), input
);
28 check(SV("0^42"), SV("{:}^42"), input
);
30 // *** align-fill & width ***
31 check(SV(" 0"), SV("{:5}"), input
);
32 check(SV("0****"), SV("{:*<5}"), input
);
33 check(SV("__0__"), SV("{:_^5}"), input
);
34 check(SV("::::0"), SV("{::>5}"), input
); // This is not a range, so : is allowed as fill character.
36 check(SV(" 0"), SV("{:{}}"), input
, 5);
37 check(SV("0****"), SV("{:*<{}}"), input
, 5);
38 check(SV("__0__"), SV("{:_^{}}"), input
, 5);
39 check(SV("####0"), SV("{:#>{}}"), input
, 5);
40 #else // !defined(__APPLE__) && !defined(__FreeBSD__)
41 check(SV("0x0"), SV("{}"), input
);
42 check(SV("0x0^42"), SV("{}^42"), input
);
43 check(SV("0x0^42"), SV("{:}^42"), input
);
45 // *** align-fill & width ***
46 check(SV(" 0x0"), SV("{:7}"), input
);
47 check(SV("0x0****"), SV("{:*<7}"), input
);
48 check(SV("__0x0__"), SV("{:_^7}"), input
);
49 check(SV("::::0x0"), SV("{::>7}"), input
); // This is not a range, so : is allowed as fill character.
51 check(SV(" 0x0"), SV("{:{}}"), input
, 7);
52 check(SV("0x0****"), SV("{:*<{}}"), input
, 7);
53 check(SV("__0x0__"), SV("{:_^{}}"), input
, 7);
54 check(SV("####0x0"), SV("{:#>{}}"), input
, 7);
55 #endif // !defined(__APPLE__) && !defined(__FreeBSD__)
57 /***** Test the type generic part *****/
58 check_exception("The format string contains an invalid escape sequence", SV("{:}<}"), input
);
59 check_exception("The fill option contains an invalid value", SV("{:{<}"), input
);
62 check_exception("The replacement field misses a terminating '}'", SV("{:-}"), input
);
63 check_exception("The replacement field misses a terminating '}'", SV("{:+}"), input
);
64 check_exception("The replacement field misses a terminating '}'", SV("{: }"), input
);
66 // *** alternate form ***
67 check_exception("The replacement field misses a terminating '}'", SV("{:#}"), input
);
69 // *** zero-padding ***
70 check_exception("The width option should not have a leading zero", SV("{:0}"), input
);
73 check_exception("The replacement field misses a terminating '}'", SV("{:.}"), input
);
75 // *** locale-specific form ***
76 check_exception("The replacement field misses a terminating '}'", SV("{:L}"), input
);
79 for (std::basic_string_view
<CharT
> fmt
: fmt_invalid_types
<CharT
>(""))
80 check_exception("The replacement field misses a terminating '}'", fmt
, input
);
83 #endif // TEST_STD_THREAD_THREAD_THREADS_THREAD_THREAD_CLASS_THREAD_THREAD_ID_FORMAT_FUNCTIONS_TESTS_H