Debian Codegraph @

libstdc++-v3/testsuite/21_strings/basic_string/operations/contains/wchar_t.cc

raw
1 // { dg-do run { target c++23 } }
2
3 // Copyright (C) 2021-2025 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
19
20 // basic_string contains
21
22 #include <string>
23 #include <testsuite_hooks.h>
24
25 void
26 test01()
27 {
28 const std::wstring haystack(L"no place for needles");
29
30 VERIFY(haystack.contains(std::wstring(L"")));
31 VERIFY(haystack.contains(std::wstring(L"no")));
32 VERIFY(haystack.contains(std::wstring(L"needles")));
33 VERIFY(haystack.contains(std::wstring(L" for ")));
34 VERIFY(!haystack.contains(std::wstring(L"places")));
35
36 VERIFY(haystack.contains(std::wstring_view(L"")));
37 VERIFY(haystack.contains(std::wstring_view(L"no")));
38 VERIFY(haystack.contains(std::wstring_view(L"needles")));
39 VERIFY(haystack.contains(std::wstring_view(L" for ")));
40 VERIFY(!haystack.contains(std::wstring_view(L"places")));
41
42 VERIFY(!haystack.contains('\0'));
43 VERIFY(haystack.contains('n'));
44 VERIFY(haystack.contains('e'));
45 VERIFY(haystack.contains('s'));
46 VERIFY(!haystack.contains('x'));
47
48 VERIFY(haystack.contains(L""));
49 VERIFY(haystack.contains(L"no"));
50 VERIFY(haystack.contains(L"needles"));
51 VERIFY(haystack.contains(L" for "));
52 VERIFY(!haystack.contains(L"places"));
53
54 const std::wstring nothing;
55 VERIFY(nothing.contains(L""));
56 VERIFY(!nothing.contains('\0'));
57 }
58
59 int
60 main()
61 {
62 test01();
63 return 0;
64 }