| 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 |
#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 |
| 10 |
|
| 11 |
#include <thread> |
| 12 |
|
| 13 |
#include "format.functions.common.h" |
| 14 |
#include "test_macros.h" |
| 15 |
|
| 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{}; |
| 22 |
|
| 23 |
/***** Test the type specific part *****/ |
| 24 |
#if !defined(__APPLE__) && !defined(__FreeBSD__) |
| 25 |
check(SV("0"), SV("{}"), input); |
| 26 |
check(SV("0^42"), SV("{}^42"), input); |
| 27 |
check(SV("0^42"), SV("{:}^42"), input); |
| 28 |
|
| 29 |
// *** align-fill & width *** |
| 30 |
check(SV(" 0"), SV("{:5}"), input); |
| 31 |
check(SV("0****"), SV("{:*<5}"), input); |
| 32 |
check(SV("__0__"), SV("{:_^5}"), input); |
| 33 |
check(SV("::::0"), SV("{::>5}"), input); // This is not a range, so : is allowed as fill character. |
| 34 |
|
| 35 |
check(SV(" 0"), SV("{:{}}"), input, 5); |
| 36 |
check(SV("0****"), SV("{:*<{}}"), input, 5); |
| 37 |
check(SV("__0__"), SV("{:_^{}}"), input, 5); |
| 38 |
check(SV("####0"), SV("{:#>{}}"), input, 5); |
| 39 |
#else // !defined(__APPLE__) && !defined(__FreeBSD__) |
| 40 |
check(SV("0x0"), SV("{}"), input); |
| 41 |
check(SV("0x0^42"), SV("{}^42"), input); |
| 42 |
check(SV("0x0^42"), SV("{:}^42"), input); |
| 43 |
|
| 44 |
// *** align-fill & width *** |
| 45 |
check(SV(" 0x0"), SV("{:7}"), input); |
| 46 |
check(SV("0x0****"), SV("{:*<7}"), input); |
| 47 |
check(SV("__0x0__"), SV("{:_^7}"), input); |
| 48 |
check(SV("::::0x0"), SV("{::>7}"), input); // This is not a range, so : is allowed as fill character. |
| 49 |
|
| 50 |
check(SV(" 0x0"), SV("{:{}}"), input, 7); |
| 51 |
check(SV("0x0****"), SV("{:*<{}}"), input, 7); |
| 52 |
check(SV("__0x0__"), SV("{:_^{}}"), input, 7); |
| 53 |
check(SV("####0x0"), SV("{:#>{}}"), input, 7); |
| 54 |
#endif // !defined(__APPLE__) && !defined(__FreeBSD__) |
| 55 |
|
| 56 |
/***** Test the type generic part *****/ |
| 57 |
check_exception("The format string contains an invalid escape sequence", SV("{:}<}"), input); |
| 58 |
check_exception("The fill option contains an invalid value", SV("{:{<}"), input); |
| 59 |
|
| 60 |
// *** sign *** |
| 61 |
check_exception("The replacement field misses a terminating '}'", 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 |
|
| 65 |
// *** alternate form *** |
| 66 |
check_exception("The replacement field misses a terminating '}'", SV("{:#}"), input); |
| 67 |
|
| 68 |
// *** zero-padding *** |
| 69 |
check_exception("The width option should not have a leading zero", SV("{:0}"), input); |
| 70 |
|
| 71 |
// *** precision *** |
| 72 |
check_exception("The replacement field misses a terminating '}'", SV("{:.}"), input); |
| 73 |
|
| 74 |
// *** locale-specific form *** |
| 75 |
check_exception("The replacement field misses a terminating '}'", SV("{:L}"), input); |
| 76 |
|
| 77 |
// *** type *** |
| 78 |
for (std::basic_string_view<CharT> fmt : fmt_invalid_types<CharT>("")) |
| 79 |
check_exception("The replacement field misses a terminating '}'", fmt, input); |
| 80 |
} |
| 81 |
|
| 82 |
#endif // TEST_STD_THREAD_THREAD_THREADS_THREAD_THREAD_CLASS_THREAD_THREAD_ID_FORMAT_FUNCTIONS_TESTS_H |