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