Toolbox snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
Tokeniser.ut.cpp
Go to the documentation of this file.
1// The Reactive C++ Toolbox.
2// Copyright (C) 2013-2019 Swirly Cloud Limited
3// Copyright (C) 2021 Reactive Markets Limited
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17#include "Tokeniser.hpp"
18
19#include <boost/test/unit_test.hpp>
20
21using namespace toolbox;
22using namespace std::literals::string_view_literals;
23
25
27{
29
30 BOOST_CHECK(toks.empty());
31 BOOST_CHECK(!toks.has_delim());
32
33 toks = Tokeniser{""sv, ","sv};
34 BOOST_CHECK(toks.empty());
35 BOOST_CHECK(!toks.has_delim());
36}
37
39{
40 Tokeniser toks{","sv, ","sv};
41
42 BOOST_CHECK(!toks.empty());
43 BOOST_CHECK(toks.has_delim());
44 BOOST_CHECK(toks.top().empty());
45
46 toks.pop();
47 BOOST_CHECK(toks.empty());
48 BOOST_CHECK(!toks.has_delim());
49 BOOST_CHECK(toks.top().empty());
50}
51
53{
54 Tokeniser toks{"foo"sv, ","sv};
55
56 BOOST_CHECK(!toks.empty());
57 BOOST_CHECK(!toks.has_delim());
58 BOOST_CHECK_EQUAL(toks.top(), "foo");
59
60 toks.pop();
61 BOOST_CHECK(toks.empty());
62 BOOST_CHECK(!toks.has_delim());
63 BOOST_CHECK(toks.top().empty());
64}
65
67{
68 Tokeniser toks{"foo,bar,baz"sv, ","sv};
69
70 BOOST_CHECK(!toks.empty());
71 BOOST_CHECK(toks.has_delim());
72 BOOST_CHECK_EQUAL(toks.top(), "foo");
73
74 toks.pop();
75 BOOST_CHECK(!toks.empty());
76 BOOST_CHECK(toks.has_delim());
77 BOOST_CHECK_EQUAL(toks.top(), "bar");
78
79 toks.pop();
80 BOOST_CHECK(!toks.empty());
81 BOOST_CHECK(!toks.has_delim());
82 BOOST_CHECK_EQUAL(toks.top(), "baz");
83
84 toks.pop();
85 BOOST_CHECK(toks.empty());
86 BOOST_CHECK(!toks.has_delim());
87 BOOST_CHECK(toks.top().empty());
88}
89
91{
92 Tokeniser toks{"foo,bar;baz"sv, ",;"sv};
93
94 BOOST_CHECK(!toks.empty());
95 BOOST_CHECK(toks.has_delim());
96 BOOST_CHECK_EQUAL(toks.top(), "foo");
97
98 toks.pop();
99 BOOST_CHECK(!toks.empty());
100 BOOST_CHECK(toks.has_delim());
101 BOOST_CHECK_EQUAL(toks.top(), "bar");
102
103 toks.pop();
104 BOOST_CHECK(!toks.empty());
105 BOOST_CHECK(!toks.has_delim());
106 BOOST_CHECK_EQUAL(toks.top(), "baz");
107
108 toks.pop();
109 BOOST_CHECK(toks.empty());
110 BOOST_CHECK(!toks.has_delim());
111 BOOST_CHECK(toks.top().empty());
112}
113
115{
116 Tokeniser toks{",foo"sv, ","sv};
117
118 BOOST_CHECK(!toks.empty());
119 BOOST_CHECK(toks.has_delim());
120 BOOST_CHECK(toks.top().empty());
121
122 toks.pop();
123 BOOST_CHECK(!toks.empty());
124 BOOST_CHECK(!toks.has_delim());
125 BOOST_CHECK_EQUAL(toks.top(), "foo");
126
127 toks.pop();
128 BOOST_CHECK(toks.empty());
129 BOOST_CHECK(!toks.has_delim());
130 BOOST_CHECK(toks.top().empty());
131}
132
134{
135 Tokeniser toks{"foo,"sv, ","sv};
136
137 BOOST_CHECK(!toks.empty());
138 BOOST_CHECK(toks.has_delim());
139 BOOST_CHECK_EQUAL(toks.top(), "foo");
140
141 toks.pop();
142 BOOST_CHECK(toks.empty());
143 BOOST_CHECK(!toks.has_delim());
144 BOOST_CHECK(toks.top().empty());
145}
146
148{
149 Tokeniser lines{"foo\nbar\nbaz..."sv, "\n"sv};
150
151 BOOST_CHECK(!lines.empty());
152 BOOST_CHECK(lines.has_delim());
153 BOOST_CHECK_EQUAL(lines.top(), "foo");
154
155 lines.pop();
156 BOOST_CHECK(!lines.empty());
157 BOOST_CHECK(lines.has_delim());
158 BOOST_CHECK_EQUAL(lines.top(), "bar");
159
160 lines.pop();
161 BOOST_CHECK(!lines.empty());
162 BOOST_CHECK(!lines.has_delim());
163 BOOST_CHECK_EQUAL(lines.top(), "baz...");
164 BOOST_CHECK_EQUAL(lines.consumed(), 8);
165
166 lines.pop();
167 BOOST_CHECK(lines.empty());
168 BOOST_CHECK(!lines.has_delim());
169 BOOST_CHECK(lines.top().empty());
170}
171
BOOST_CHECK_EQUAL(v.size(), 10U)
BOOST_AUTO_TEST_CASE(TokeniserEmptyCase)
std::string_view sv
Definition Tokeniser.hpp:26
constexpr auto bind() noexcept
Definition Slot.hpp:92
BOOST_CHECK(isnan(stod(""sv, numeric_limits< double >::quiet_NaN())))