brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.9 KiB · 74a2cea Raw
85 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef TEST_STD_INPUT_OUTPUT_IOSTREAM_FORMAT_PRINT_FUN_PRINT_TESTS_H10#define TEST_STD_INPUT_OUTPUT_IOSTREAM_FORMAT_PRINT_FUN_PRINT_TESTS_H11 12template <class TestFunction, class ExceptionTest>13void print_tests(TestFunction check, ExceptionTest check_exception) {14  // *** Test escaping  ***15 16  check("{", "{{");17  check("{:^}", "{{:^}}");18  check("{: ^}", "{{:{}^}}", ' ');19  check("{:{}^}", "{{:{{}}^}}");20  check("{:{ }^}", "{{:{{{}}}^}}", ' ');21 22  // *** Test argument ID ***23  check("hello false true", "hello {0:} {1:}", false, true);24  check("hello true false", "hello {1:} {0:}", false, true);25 26  // *** Test many arguments ***27  check(28      "1234567890\t1234567890",29      "{}{}{}{}{}{}{}{}{}{}\t{}{}{}{}{}{}{}{}{}{}",30      1,31      2,32      3,33      4,34      5,35      6,36      7,37      8,38      9,39      0,40      1,41      2,42      3,43      4,44      5,45      6,46      7,47      8,48      9,49      0);50 51  // *** Test embedded NUL character ***52  using namespace std::literals;53  check("hello\0world"sv, "hello{}{}", '\0', "world");54  check("hello\0world"sv, "hello\0{}"sv, "world");55  check("hello\0world"sv, "hello{}", "\0world"sv);56 57  // *** Test Unicode ***58  // 2-byte code points59  check("\u00a1"sv, "{}"sv, "\u00a1");  // INVERTED EXCLAMATION MARK60  check("\u07ff"sv, "{:}"sv, "\u07ff"); // NKO TAMAN SIGN61 62  // 3-byte code points63  check("\u0800"sv, "{}"sv, "\u0800"); // SAMARITAN LETTER ALAF64  check("\ufffd"sv, "{}"sv, "\ufffd"); // REPLACEMENT CHARACTER65 66  // 4-byte code points67  check("\U00010000"sv, "{}"sv, "\U00010000"); // LINEAR B SYLLABLE B008 A68  check("\U0010FFFF"sv, "{}"sv, "\U0010FFFF"); // Undefined Character69 70  // *** Test invalid format strings ***71  check_exception("The format string terminates at a '{'", "{");72  check_exception("The replacement field misses a terminating '}'", "{:", 42);73 74  check_exception("The format string contains an invalid escape sequence", "}");75  check_exception("The format string contains an invalid escape sequence", "{:}-}", 42);76 77  check_exception("The format string contains an invalid escape sequence", "} ");78  check_exception("The argument index starts with an invalid character", "{-", 42);79  check_exception("The argument index value is too large for the number of arguments supplied", "hello {}");80  check_exception("The argument index value is too large for the number of arguments supplied", "hello {0}");81  check_exception("The argument index value is too large for the number of arguments supplied", "hello {1}", 42);82}83 84#endif // TEST_STD_INPUT_OUTPUT_IOSTREAM_FORMAT_PRINT_FUN_PRINT_TESTS_H85