]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/std/ranges/adaptors/split.cc
libstdc++: Implement C++20 range adaptors
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / std / ranges / adaptors / split.cc
1 // Copyright (C) 2020 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-options "-std=gnu++2a" }
19 // { dg-do run { target c++2a } }
20
21 #include <algorithm>
22 #include <ranges>
23 #include <string>
24 #include <string_view>
25 #include <testsuite_hooks.h>
26 #include <testsuite_iterators.h>
27
28 using __gnu_test::test_range;
29 using __gnu_test::forward_iterator_wrapper;
30
31 namespace ranges = std::ranges;
32 namespace views = std::ranges::views;
33
34 using namespace std::literals;
35
36 void
37 test01()
38 {
39 auto x = "the quick brown fox"sv;
40 auto p = std::string{" "};
41 auto v = x | views::split(p);
42 auto i = v.begin();
43 VERIFY( ranges::equal(*i++, "the"sv) );
44 VERIFY( ranges::equal(*i++, "quick"sv) );
45 VERIFY( ranges::equal(*i++, "brown"sv) );
46 VERIFY( ranges::equal(*i++, "fox"sv) );
47 VERIFY( i == v.end() );
48 }
49
50 void
51 test02()
52 {
53 auto x = "the quick brown fox"sv;
54 auto v = x | views::split(' ');
55 auto i = v.begin();
56 VERIFY( ranges::equal(*i++, "the"sv) );
57 VERIFY( ranges::equal(*i++, "quick"sv) );
58 VERIFY( ranges::equal(*i++, "brown"sv) );
59 VERIFY( ranges::equal(*i++, "fox"sv) );
60 VERIFY( i == v.end() );
61 }
62
63 void
64 test03()
65 {
66 char x[] = "the quick brown fox";
67 test_range<char, forward_iterator_wrapper> rx(x);
68 auto v = rx | views::split(' ');
69 auto i = v.begin();
70 VERIFY( ranges::equal(*i++, "the"sv) );
71 VERIFY( ranges::equal(*i++, "quick"sv) );
72 VERIFY( ranges::equal(*i++, "brown"sv) );
73 VERIFY( ranges::equal(*i++, "fox"sv) );
74 VERIFY( i == v.end() );
75 }
76
77 int
78 main()
79 {
80 test01();
81 test02();
82 }