| 1 |
// Copyright (C) 2020-2025 Free Software Foundation, Inc. |
| 2 |
// |
| 3 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 4 |
// software; you can redistribute it and/or modify it under the |
| 5 |
// terms of the GNU General Public License as published by the |
| 6 |
// Free Software Foundation; either version 3, or (at your option) |
| 7 |
// any later version. |
| 8 |
|
| 9 |
// This library is distributed in the hope that it will be useful, |
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
// GNU General Public License for more details. |
| 13 |
|
| 14 |
// You should have received a copy of the GNU General Public License along |
| 15 |
// with this library; see the file COPYING3. If not see |
| 16 |
// <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
// { dg-do run { target c++20 } } |
| 19 |
|
| 20 |
// C++20 21.3.3.2 Non-member comparison functions [string.cmp] |
| 21 |
|
| 22 |
// operator== |
| 23 |
/* |
| 24 |
template<class charT, class traits, class Allocator> |
| 25 |
constexpr bool |
| 26 |
operator==(const basic_string<charT, traits, Allocator>& lhs, |
| 27 |
const basic_string<charT, traits, Allocator>& rhs); |
| 28 |
|
| 29 |
template<class charT, class traits, class Allocator> |
| 30 |
constexpr bool |
| 31 |
operator==(const basic_string<charT, traits, Allocator>& lhs, |
| 32 |
const charT* rhs); |
| 33 |
*/ |
| 34 |
|
| 35 |
// operator<=> |
| 36 |
/* |
| 37 |
template<class charT, class traits, class Allocator> |
| 38 |
constexpr [see below] |
| 39 |
operator<=>(const basic_string<charT, traits, Allocator>& lhs, |
| 40 |
const basic_string<charT, traits, Allocator>& rhs); |
| 41 |
|
| 42 |
template<class charT, class traits, class Allocator> |
| 43 |
constexpr [see below] |
| 44 |
operator<=>(const basic_string<charT,traits,Allocator>& lhs, |
| 45 |
const charT* rhs); |
| 46 |
*/ |
| 47 |
|
| 48 |
#include <string> |
| 49 |
#include <testsuite_hooks.h> |
| 50 |
|
| 51 |
void |
| 52 |
test01() |
| 53 |
{ |
| 54 |
std::wstring str_0(L"costa rica"); |
| 55 |
std::wstring str_1(L"costa marbella"); |
| 56 |
std::wstring str_2(L"cost"); |
| 57 |
std::wstring str_3(L"costa ricans"); |
| 58 |
std::wstring str_4; |
| 59 |
|
| 60 |
str_4 = str_0; |
| 61 |
//comparisons between string objects |
| 62 |
VERIFY( !(str_0 == str_1) ); |
| 63 |
VERIFY( !(str_0 == str_2) ); |
| 64 |
VERIFY( !(str_0 == str_3) ); |
| 65 |
VERIFY( !(str_1 == str_0) ); |
| 66 |
VERIFY( !(str_2 == str_0) ); |
| 67 |
VERIFY( !(str_3 == str_0) ); |
| 68 |
VERIFY( str_4 == str_0 ); |
| 69 |
VERIFY( str_0 == str_4 ); |
| 70 |
|
| 71 |
VERIFY( str_0 != str_1 ); |
| 72 |
VERIFY( str_0 != str_2 ); |
| 73 |
VERIFY( str_0 != str_3 ); |
| 74 |
VERIFY( str_1 != str_0 ); |
| 75 |
VERIFY( str_2 != str_0 ); |
| 76 |
VERIFY( str_3 != str_0 ); |
| 77 |
VERIFY( !(str_0 != str_4) ); |
| 78 |
VERIFY( !(str_4 != str_0) ); |
| 79 |
|
| 80 |
VERIFY( str_0 > str_1 ); //true cuz r>m |
| 81 |
VERIFY( str_0 > str_2 ); |
| 82 |
VERIFY( !(str_0 > str_3) ); |
| 83 |
VERIFY( !(str_1 > str_0) ); //false cuz m<r |
| 84 |
VERIFY( !(str_2 > str_0) ); |
| 85 |
VERIFY( str_3 > str_0 ); |
| 86 |
VERIFY( !(str_0 > str_4) ); |
| 87 |
VERIFY( !(str_4 > str_0) ); |
| 88 |
|
| 89 |
VERIFY( !(str_0 < str_1) ); //false cuz r>m |
| 90 |
VERIFY( !(str_0 < str_2) ); |
| 91 |
VERIFY( str_0 < str_3 ); |
| 92 |
VERIFY( str_1 < str_0 ); //true cuz m<r |
| 93 |
VERIFY( str_2 < str_0 ); |
| 94 |
VERIFY( !(str_3 < str_0) ); |
| 95 |
VERIFY( !(str_0 < str_4) ); |
| 96 |
VERIFY( !(str_4 < str_0) ); |
| 97 |
|
| 98 |
VERIFY( str_0 >= str_1 ); //true cuz r>m |
| 99 |
VERIFY( str_0 >= str_2 ); |
| 100 |
VERIFY( !(str_0 >= str_3) ); |
| 101 |
VERIFY( !(str_1 >= str_0) );//false cuz m<r |
| 102 |
VERIFY( !(str_2 >= str_0) ); |
| 103 |
VERIFY( str_3 >= str_0 ); |
| 104 |
VERIFY( str_0 >= str_4 ); |
| 105 |
VERIFY( str_4 >= str_0 ); |
| 106 |
|
| 107 |
VERIFY( !(str_0 <= str_1) );//false cuz r>m |
| 108 |
VERIFY( !(str_0 <= str_2) ); |
| 109 |
VERIFY( str_0 <= str_3 ); |
| 110 |
VERIFY( str_1 <= str_0 );//true cuz m<r |
| 111 |
VERIFY( str_2 <= str_0 ); |
| 112 |
VERIFY( !(str_3 <= str_0) ); |
| 113 |
VERIFY( str_0 <= str_4 ); |
| 114 |
VERIFY( str_4 <= str_0 ); |
| 115 |
|
| 116 |
VERIFY( std::is_gt(str_0 <=> str_1) ); |
| 117 |
VERIFY( std::is_gt(str_0 <=> str_2) ); |
| 118 |
VERIFY( std::is_lt(str_0 <=> str_3) ); |
| 119 |
VERIFY( std::is_eq(str_0 <=> str_4) ); |
| 120 |
VERIFY( std::is_lt(str_1 <=> str_0) ); |
| 121 |
VERIFY( std::is_lt(str_2 <=> str_0) ); |
| 122 |
VERIFY( std::is_gt(str_3 <=> str_0) ); |
| 123 |
VERIFY( std::is_eq(str_4 <=> str_0) ); |
| 124 |
|
| 125 |
//comparisons between string object and string literal |
| 126 |
VERIFY( !(str_0 == L"costa marbella") ); |
| 127 |
VERIFY( !(str_0 == L"cost") ); |
| 128 |
VERIFY( !(str_0 == L"costa ricans") ); |
| 129 |
VERIFY( !(L"costa marbella" == str_0) ); |
| 130 |
VERIFY( !(L"cost" == str_0) ); |
| 131 |
VERIFY( !(L"costa ricans" == str_0) ); |
| 132 |
VERIFY( L"costa rica" == str_0 ); |
| 133 |
VERIFY( str_0 == L"costa rica" ); |
| 134 |
|
| 135 |
VERIFY( str_0 != L"costa marbella" ); |
| 136 |
VERIFY( str_0 != L"cost" ); |
| 137 |
VERIFY( str_0 != L"costa ricans" ); |
| 138 |
VERIFY( L"costa marbella" != str_0 ); |
| 139 |
VERIFY( L"cost" != str_0 ); |
| 140 |
VERIFY( L"costa ricans" != str_0 ); |
| 141 |
VERIFY( !(L"costa rica" != str_0) ); |
| 142 |
VERIFY( !(str_0 != L"costa rica") ); |
| 143 |
|
| 144 |
VERIFY( str_0 > L"costa marbella" ); //true cuz r>m |
| 145 |
VERIFY( str_0 > L"cost" ); |
| 146 |
VERIFY( !(str_0 > L"costa ricans") ); |
| 147 |
VERIFY( !(L"costa marbella" > str_0) );//false cuz m<r |
| 148 |
VERIFY( !(L"cost" > str_0) ); |
| 149 |
VERIFY( L"costa ricans" > str_0 ); |
| 150 |
VERIFY( !(L"costa rica" > str_0) ); |
| 151 |
VERIFY( !(str_0 > L"costa rica") ); |
| 152 |
|
| 153 |
VERIFY( !(str_0 < L"costa marbella") );//false cuz r>m |
| 154 |
VERIFY( !(str_0 < L"cost") ); |
| 155 |
VERIFY( str_0 < L"costa ricans" ); |
| 156 |
VERIFY( L"costa marbella" < str_0 );//true cuz m<r |
| 157 |
VERIFY( L"cost" < str_0 ); |
| 158 |
VERIFY( !(L"costa ricans" < str_0) ); |
| 159 |
VERIFY( !(L"costa rica" < str_0) ); |
| 160 |
VERIFY( !(str_0 < L"costa rica") ); |
| 161 |
|
| 162 |
VERIFY( str_0 >= L"costa marbella" );//true cuz r>m |
| 163 |
VERIFY( str_0 >= L"cost" ); |
| 164 |
VERIFY( !(str_0 >= L"costa ricans") ); |
| 165 |
VERIFY( !(L"costa marbella" >= str_0) );//false cuz m<r |
| 166 |
VERIFY( !(L"cost" >= str_0) ); |
| 167 |
VERIFY( L"costa ricans" >= str_0 ); |
| 168 |
VERIFY( L"costa rica" >= str_0 ); |
| 169 |
VERIFY( str_0 >= L"costa rica" ); |
| 170 |
|
| 171 |
VERIFY( !(str_0 <= L"costa marbella") );//false cuz r>m |
| 172 |
VERIFY( !(str_0 <= L"cost") ); |
| 173 |
VERIFY( str_0 <= L"costa ricans" ); |
| 174 |
VERIFY( L"costa marbella" <= str_0 );//true cuz m<r |
| 175 |
VERIFY( L"cost" <= str_0 ); |
| 176 |
VERIFY( !(L"costa ricans" <= str_0) ); |
| 177 |
VERIFY( L"costa rica" <= str_0 ); |
| 178 |
VERIFY( str_0 <= L"costa rica" ); |
| 179 |
|
| 180 |
VERIFY( std::is_gt(str_0 <=> L"costa marbella") ); |
| 181 |
VERIFY( std::is_gt(str_0 <=> L"cost") ); |
| 182 |
VERIFY( std::is_lt(str_0 <=> L"costa ricans") ); |
| 183 |
VERIFY( std::is_eq(str_0 <=> L"costa rica") ); |
| 184 |
VERIFY( std::is_lt(L"costa marbella" <=> str_0) ); |
| 185 |
VERIFY( std::is_lt(L"cost" <=> str_0) ); |
| 186 |
VERIFY( std::is_gt(L"costa ricans" <=> str_0) ); |
| 187 |
VERIFY( std::is_eq(L"costa rica" <=> str_0) ); |
| 188 |
} |
| 189 |
|
| 190 |
int main() |
| 191 |
{ |
| 192 |
test01(); |
| 193 |
} |