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 // UNSUPPORTED: c++03, c++11, c++14, c++17
9
10 // <string>
11
12 // template<> struct char_traits<char8_t>
13
14 // static constexpr int compare(const char_type* s1, const char_type* s2, size_t n);
15
16 #include <string>
17 #include <cassert>
18
19 #include "test_macros.h"
20
21 #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
test_constexpr()22 constexpr bool test_constexpr()
23 {
24 return std::char_traits<char8_t>::compare(u8"123", u8"223", 3) < 0
25 && std::char_traits<char8_t>::compare(u8"223", u8"123", 3) > 0
26 && std::char_traits<char8_t>::compare(u8"123", u8"123", 3) == 0;
27 }
28
29
main(int,char **)30 int main(int, char**)
31 {
32 assert(std::char_traits<char8_t>::compare(u8"", u8"", 0) == 0);
33 assert(std::char_traits<char8_t>::compare(NULL, NULL, 0) == 0);
34
35 assert(std::char_traits<char8_t>::compare(u8"1", u8"1", 1) == 0);
36 assert(std::char_traits<char8_t>::compare(u8"1", u8"2", 1) < 0);
37 assert(std::char_traits<char8_t>::compare(u8"2", u8"1", 1) > 0);
38
39 assert(std::char_traits<char8_t>::compare(u8"12", u8"12", 2) == 0);
40 assert(std::char_traits<char8_t>::compare(u8"12", u8"13", 2) < 0);
41 assert(std::char_traits<char8_t>::compare(u8"12", u8"22", 2) < 0);
42 assert(std::char_traits<char8_t>::compare(u8"13", u8"12", 2) > 0);
43 assert(std::char_traits<char8_t>::compare(u8"22", u8"12", 2) > 0);
44
45 assert(std::char_traits<char8_t>::compare(u8"123", u8"123", 3) == 0);
46 assert(std::char_traits<char8_t>::compare(u8"123", u8"223", 3) < 0);
47 assert(std::char_traits<char8_t>::compare(u8"123", u8"133", 3) < 0);
48 assert(std::char_traits<char8_t>::compare(u8"123", u8"124", 3) < 0);
49 assert(std::char_traits<char8_t>::compare(u8"223", u8"123", 3) > 0);
50 assert(std::char_traits<char8_t>::compare(u8"133", u8"123", 3) > 0);
51 assert(std::char_traits<char8_t>::compare(u8"124", u8"123", 3) > 0);
52
53 static_assert(test_constexpr(), "" );
54 return 0;
55 }
56 #else
main(int,char **)57 int main(int, char**) {
58 return 0;
59 }
60 #endif
61