1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // int compare(const charT *s) const; // constexpr since C++20
16 #include "test_macros.h"
17 #include "min_allocator.h"
19 TEST_CONSTEXPR_CXX20
int sign(int x
) {
28 TEST_CONSTEXPR_CXX20
void test(const S
& s
, const typename
S::value_type
* str
, int x
) {
29 LIBCPP_ASSERT_NOEXCEPT(s
.compare(str
));
30 assert(sign(s
.compare(str
)) == sign(x
));
34 TEST_CONSTEXPR_CXX20
void test_string() {
36 test(S(""), "abcde", -5);
37 test(S(""), "abcdefghij", -10);
38 test(S(""), "abcdefghijklmnopqrst", -20);
39 test(S("abcde"), "", 5);
40 test(S("abcde"), "abcde", 0);
41 test(S("abcde"), "abcdefghij", -5);
42 test(S("abcde"), "abcdefghijklmnopqrst", -15);
43 test(S("abcdefghij"), "", 10);
44 test(S("abcdefghij"), "abcde", 5);
45 test(S("abcdefghij"), "abcdefghij", 0);
46 test(S("abcdefghij"), "abcdefghijklmnopqrst", -10);
47 test(S("abcdefghijklmnopqrst"), "", 20);
48 test(S("abcdefghijklmnopqrst"), "abcde", 15);
49 test(S("abcdefghijklmnopqrst"), "abcdefghij", 10);
50 test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", 0);
53 TEST_CONSTEXPR_CXX20
bool test() {
54 test_string
<std::string
>();
55 #if TEST_STD_VER >= 11
56 test_string
<std::basic_string
<char, std::char_traits
<char>, min_allocator
<char> > >();
62 int main(int, char**) {
65 static_assert(test());