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
9 // <string>
10
11 // we get this comparison "for free" because the string implicitly converts to the string_view
12
13 #include <string>
14 #include <cassert>
15
16 #include "test_macros.h"
17 #include "min_allocator.h"
18
19 template <class S, class SV>
test(SV lhs,const S & rhs,bool x)20 TEST_CONSTEXPR_CXX20 void test(SV lhs, const S& rhs, bool x) {
21 assert((lhs == rhs) == x);
22 }
23
24 template <class CharT, template <class> class Alloc>
test_string()25 TEST_CONSTEXPR_CXX20 void test_string() {
26 using S = std::basic_string<CharT, std::char_traits<CharT>, Alloc<CharT> >;
27 using SV = std::basic_string_view<CharT, std::char_traits<CharT> >;
28
29 test(SV(""), S(""), true);
30 test(SV(""), S("abcde"), false);
31 test(SV(""), S("abcdefghij"), false);
32 test(SV(""), S("abcdefghijklmnopqrst"), false);
33 test(SV("abcde"), S(""), false);
34 test(SV("abcde"), S("abcde"), true);
35 test(SV("abcde"), S("abcdefghij"), false);
36 test(SV("abcde"), S("abcdefghijklmnopqrst"), false);
37 test(SV("abcdefghij"), S(""), false);
38 test(SV("abcdefghij"), S("abcde"), false);
39 test(SV("abcdefghij"), S("abcdefghij"), true);
40 test(SV("abcdefghij"), S("abcdefghijklmnopqrst"), false);
41 test(SV("abcdefghijklmnopqrst"), S(""), false);
42 test(SV("abcdefghijklmnopqrst"), S("abcde"), false);
43 test(SV("abcdefghijklmnopqrst"), S("abcdefghij"), false);
44 test(SV("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), true);
45 }
46
test()47 TEST_CONSTEXPR_CXX20 bool test() {
48 test_string<char, std::allocator>();
49 #if TEST_STD_VER >= 11
50 test_string<char, min_allocator>();
51 #endif
52 return true;
53 }
54
main(int,char **)55 int main(int, char**) {
56 test();
57 #if TEST_STD_VER > 17
58 static_assert(test());
59 #endif
60
61 return 0;
62 }
63