1*11be35a1SLionel Sambuc // Copyright 2012 Google Inc.
2*11be35a1SLionel Sambuc // All rights reserved.
3*11be35a1SLionel Sambuc //
4*11be35a1SLionel Sambuc // Redistribution and use in source and binary forms, with or without
5*11be35a1SLionel Sambuc // modification, are permitted provided that the following conditions are
6*11be35a1SLionel Sambuc // met:
7*11be35a1SLionel Sambuc //
8*11be35a1SLionel Sambuc // * Redistributions of source code must retain the above copyright
9*11be35a1SLionel Sambuc // notice, this list of conditions and the following disclaimer.
10*11be35a1SLionel Sambuc // * Redistributions in binary form must reproduce the above copyright
11*11be35a1SLionel Sambuc // notice, this list of conditions and the following disclaimer in the
12*11be35a1SLionel Sambuc // documentation and/or other materials provided with the distribution.
13*11be35a1SLionel Sambuc // * Neither the name of Google Inc. nor the names of its contributors
14*11be35a1SLionel Sambuc // may be used to endorse or promote products derived from this software
15*11be35a1SLionel Sambuc // without specific prior written permission.
16*11be35a1SLionel Sambuc //
17*11be35a1SLionel Sambuc // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18*11be35a1SLionel Sambuc // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19*11be35a1SLionel Sambuc // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20*11be35a1SLionel Sambuc // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21*11be35a1SLionel Sambuc // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22*11be35a1SLionel Sambuc // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23*11be35a1SLionel Sambuc // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24*11be35a1SLionel Sambuc // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25*11be35a1SLionel Sambuc // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26*11be35a1SLionel Sambuc // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27*11be35a1SLionel Sambuc // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*11be35a1SLionel Sambuc
29*11be35a1SLionel Sambuc #include "utils/text/operations.ipp"
30*11be35a1SLionel Sambuc
31*11be35a1SLionel Sambuc #include <iostream>
32*11be35a1SLionel Sambuc #include <set>
33*11be35a1SLionel Sambuc #include <string>
34*11be35a1SLionel Sambuc #include <vector>
35*11be35a1SLionel Sambuc
36*11be35a1SLionel Sambuc #include <atf-c++.hpp>
37*11be35a1SLionel Sambuc
38*11be35a1SLionel Sambuc #include "utils/text/exceptions.hpp"
39*11be35a1SLionel Sambuc
40*11be35a1SLionel Sambuc namespace text = utils::text;
41*11be35a1SLionel Sambuc
42*11be35a1SLionel Sambuc
43*11be35a1SLionel Sambuc namespace {
44*11be35a1SLionel Sambuc
45*11be35a1SLionel Sambuc
46*11be35a1SLionel Sambuc /// Tests text::refill() on an input string with a range of widths.
47*11be35a1SLionel Sambuc ///
48*11be35a1SLionel Sambuc /// \param expected The expected refilled paragraph.
49*11be35a1SLionel Sambuc /// \param input The input paragraph to be refilled.
50*11be35a1SLionel Sambuc /// \param first_width The first width to validate.
51*11be35a1SLionel Sambuc /// \param last_width The last width to validate (inclusive).
52*11be35a1SLionel Sambuc static void
refill_test(const char * expected,const char * input,const std::size_t first_width,const std::size_t last_width)53*11be35a1SLionel Sambuc refill_test(const char* expected, const char* input,
54*11be35a1SLionel Sambuc const std::size_t first_width, const std::size_t last_width)
55*11be35a1SLionel Sambuc {
56*11be35a1SLionel Sambuc for (std::size_t width = first_width; width <= last_width; ++width) {
57*11be35a1SLionel Sambuc const std::vector< std::string > lines = text::split(expected, '\n');
58*11be35a1SLionel Sambuc std::cout << "Breaking at width " << width << '\n';
59*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(expected, text::refill_as_string(input, width));
60*11be35a1SLionel Sambuc ATF_REQUIRE(lines == text::refill(input, width));
61*11be35a1SLionel Sambuc }
62*11be35a1SLionel Sambuc }
63*11be35a1SLionel Sambuc
64*11be35a1SLionel Sambuc
65*11be35a1SLionel Sambuc } // anonymous namespace
66*11be35a1SLionel Sambuc
67*11be35a1SLionel Sambuc
68*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(quote__empty);
ATF_TEST_CASE_BODY(quote__empty)69*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(quote__empty)
70*11be35a1SLionel Sambuc {
71*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("''", text::quote("", '\''));
72*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("##", text::quote("", '#'));
73*11be35a1SLionel Sambuc }
74*11be35a1SLionel Sambuc
75*11be35a1SLionel Sambuc
76*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(quote__no_escaping);
ATF_TEST_CASE_BODY(quote__no_escaping)77*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(quote__no_escaping)
78*11be35a1SLionel Sambuc {
79*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("'Some text\"'", text::quote("Some text\"", '\''));
80*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("#Another'string#", text::quote("Another'string", '#'));
81*11be35a1SLionel Sambuc }
82*11be35a1SLionel Sambuc
83*11be35a1SLionel Sambuc
84*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(quote__some_escaping);
ATF_TEST_CASE_BODY(quote__some_escaping)85*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(quote__some_escaping)
86*11be35a1SLionel Sambuc {
87*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("'Some\\'text'", text::quote("Some'text", '\''));
88*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("#Some\\#text#", text::quote("Some#text", '#'));
89*11be35a1SLionel Sambuc
90*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("'More than one\\' quote\\''",
91*11be35a1SLionel Sambuc text::quote("More than one' quote'", '\''));
92*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("'Multiple quotes \\'\\'\\' together'",
93*11be35a1SLionel Sambuc text::quote("Multiple quotes ''' together", '\''));
94*11be35a1SLionel Sambuc
95*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("'\\'escape at the beginning'",
96*11be35a1SLionel Sambuc text::quote("'escape at the beginning", '\''));
97*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("'escape at the end\\''",
98*11be35a1SLionel Sambuc text::quote("escape at the end'", '\''));
99*11be35a1SLionel Sambuc }
100*11be35a1SLionel Sambuc
101*11be35a1SLionel Sambuc
102*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(refill__empty);
ATF_TEST_CASE_BODY(refill__empty)103*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(refill__empty)
104*11be35a1SLionel Sambuc {
105*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(1, text::refill("", 0).size());
106*11be35a1SLionel Sambuc ATF_REQUIRE(text::refill("", 0)[0].empty());
107*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("", text::refill_as_string("", 0));
108*11be35a1SLionel Sambuc
109*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(1, text::refill("", 10).size());
110*11be35a1SLionel Sambuc ATF_REQUIRE(text::refill("", 10)[0].empty());
111*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("", text::refill_as_string("", 10));
112*11be35a1SLionel Sambuc }
113*11be35a1SLionel Sambuc
114*11be35a1SLionel Sambuc
115*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(refill__no_changes);
ATF_TEST_CASE_BODY(refill__no_changes)116*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(refill__no_changes)
117*11be35a1SLionel Sambuc {
118*11be35a1SLionel Sambuc std::vector< std::string > exp_lines;
119*11be35a1SLionel Sambuc exp_lines.push_back("foo bar\nbaz");
120*11be35a1SLionel Sambuc
121*11be35a1SLionel Sambuc ATF_REQUIRE(exp_lines == text::refill("foo bar\nbaz", 12));
122*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("foo bar\nbaz", text::refill_as_string("foo bar\nbaz", 12));
123*11be35a1SLionel Sambuc
124*11be35a1SLionel Sambuc ATF_REQUIRE(exp_lines == text::refill("foo bar\nbaz", 18));
125*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("foo bar\nbaz", text::refill_as_string("foo bar\nbaz", 80));
126*11be35a1SLionel Sambuc }
127*11be35a1SLionel Sambuc
128*11be35a1SLionel Sambuc
129*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(refill__break_one);
ATF_TEST_CASE_BODY(refill__break_one)130*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(refill__break_one)
131*11be35a1SLionel Sambuc {
132*11be35a1SLionel Sambuc refill_test("only break the\nfirst line", "only break the first line",
133*11be35a1SLionel Sambuc 14, 19);
134*11be35a1SLionel Sambuc }
135*11be35a1SLionel Sambuc
136*11be35a1SLionel Sambuc
137*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(refill__break_one__not_first_word);
ATF_TEST_CASE_BODY(refill__break_one__not_first_word)138*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(refill__break_one__not_first_word)
139*11be35a1SLionel Sambuc {
140*11be35a1SLionel Sambuc refill_test("first-long-word\nother\nwords", "first-long-word other words",
141*11be35a1SLionel Sambuc 6, 10);
142*11be35a1SLionel Sambuc refill_test("first-long-word\nother words", "first-long-word other words",
143*11be35a1SLionel Sambuc 11, 20);
144*11be35a1SLionel Sambuc refill_test("first-long-word other\nwords", "first-long-word other words",
145*11be35a1SLionel Sambuc 21, 26);
146*11be35a1SLionel Sambuc refill_test("first-long-word other words", "first-long-word other words",
147*11be35a1SLionel Sambuc 27, 28);
148*11be35a1SLionel Sambuc }
149*11be35a1SLionel Sambuc
150*11be35a1SLionel Sambuc
151*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(refill__break_many);
ATF_TEST_CASE_BODY(refill__break_many)152*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(refill__break_many)
153*11be35a1SLionel Sambuc {
154*11be35a1SLionel Sambuc refill_test("this is a long\nparagraph to be\nsplit into\npieces",
155*11be35a1SLionel Sambuc "this is a long paragraph to be split into pieces",
156*11be35a1SLionel Sambuc 15, 15);
157*11be35a1SLionel Sambuc }
158*11be35a1SLionel Sambuc
159*11be35a1SLionel Sambuc
160*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(refill__cannot_break);
ATF_TEST_CASE_BODY(refill__cannot_break)161*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(refill__cannot_break)
162*11be35a1SLionel Sambuc {
163*11be35a1SLionel Sambuc refill_test("this-is-a-long-string", "this-is-a-long-string", 5, 5);
164*11be35a1SLionel Sambuc
165*11be35a1SLionel Sambuc refill_test("this is\na-string-with-long-words",
166*11be35a1SLionel Sambuc "this is a-string-with-long-words", 10, 10);
167*11be35a1SLionel Sambuc }
168*11be35a1SLionel Sambuc
169*11be35a1SLionel Sambuc
170*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(refill__preserve_whitespace);
ATF_TEST_CASE_BODY(refill__preserve_whitespace)171*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(refill__preserve_whitespace)
172*11be35a1SLionel Sambuc {
173*11be35a1SLionel Sambuc refill_test("foo bar baz ", "foo bar baz ", 80, 80);
174*11be35a1SLionel Sambuc refill_test("foo \n bar", "foo bar", 5, 5);
175*11be35a1SLionel Sambuc
176*11be35a1SLionel Sambuc std::vector< std::string > exp_lines;
177*11be35a1SLionel Sambuc exp_lines.push_back("foo \n");
178*11be35a1SLionel Sambuc exp_lines.push_back(" bar");
179*11be35a1SLionel Sambuc ATF_REQUIRE(exp_lines == text::refill("foo \n bar", 5));
180*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("foo \n\n bar", text::refill_as_string("foo \n bar", 5));
181*11be35a1SLionel Sambuc }
182*11be35a1SLionel Sambuc
183*11be35a1SLionel Sambuc
184*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(join__empty);
ATF_TEST_CASE_BODY(join__empty)185*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(join__empty)
186*11be35a1SLionel Sambuc {
187*11be35a1SLionel Sambuc std::vector< std::string > lines;
188*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("", text::join(lines, " "));
189*11be35a1SLionel Sambuc }
190*11be35a1SLionel Sambuc
191*11be35a1SLionel Sambuc
192*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(join__one);
ATF_TEST_CASE_BODY(join__one)193*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(join__one)
194*11be35a1SLionel Sambuc {
195*11be35a1SLionel Sambuc std::vector< std::string > lines;
196*11be35a1SLionel Sambuc lines.push_back("first line");
197*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("first line", text::join(lines, "*"));
198*11be35a1SLionel Sambuc }
199*11be35a1SLionel Sambuc
200*11be35a1SLionel Sambuc
201*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(join__several);
ATF_TEST_CASE_BODY(join__several)202*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(join__several)
203*11be35a1SLionel Sambuc {
204*11be35a1SLionel Sambuc std::vector< std::string > lines;
205*11be35a1SLionel Sambuc lines.push_back("first abc");
206*11be35a1SLionel Sambuc lines.push_back("second");
207*11be35a1SLionel Sambuc lines.push_back("and last line");
208*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("first abc second and last line", text::join(lines, " "));
209*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("first abc***second***and last line",
210*11be35a1SLionel Sambuc text::join(lines, "***"));
211*11be35a1SLionel Sambuc }
212*11be35a1SLionel Sambuc
213*11be35a1SLionel Sambuc
214*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(join__unordered);
ATF_TEST_CASE_BODY(join__unordered)215*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(join__unordered)
216*11be35a1SLionel Sambuc {
217*11be35a1SLionel Sambuc std::set< std::string > lines;
218*11be35a1SLionel Sambuc lines.insert("first");
219*11be35a1SLionel Sambuc lines.insert("second");
220*11be35a1SLionel Sambuc const std::string joined = text::join(lines, " ");
221*11be35a1SLionel Sambuc ATF_REQUIRE(joined == "first second" || joined == "second first");
222*11be35a1SLionel Sambuc }
223*11be35a1SLionel Sambuc
224*11be35a1SLionel Sambuc
225*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(split__empty);
ATF_TEST_CASE_BODY(split__empty)226*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(split__empty)
227*11be35a1SLionel Sambuc {
228*11be35a1SLionel Sambuc std::vector< std::string > words = text::split("", ' ');
229*11be35a1SLionel Sambuc std::vector< std::string > exp_words;
230*11be35a1SLionel Sambuc ATF_REQUIRE(exp_words == words);
231*11be35a1SLionel Sambuc }
232*11be35a1SLionel Sambuc
233*11be35a1SLionel Sambuc
234*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(split__one);
ATF_TEST_CASE_BODY(split__one)235*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(split__one)
236*11be35a1SLionel Sambuc {
237*11be35a1SLionel Sambuc std::vector< std::string > words = text::split("foo", ' ');
238*11be35a1SLionel Sambuc std::vector< std::string > exp_words;
239*11be35a1SLionel Sambuc exp_words.push_back("foo");
240*11be35a1SLionel Sambuc ATF_REQUIRE(exp_words == words);
241*11be35a1SLionel Sambuc }
242*11be35a1SLionel Sambuc
243*11be35a1SLionel Sambuc
244*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(split__several__simple);
ATF_TEST_CASE_BODY(split__several__simple)245*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(split__several__simple)
246*11be35a1SLionel Sambuc {
247*11be35a1SLionel Sambuc std::vector< std::string > words = text::split("foo bar baz", ' ');
248*11be35a1SLionel Sambuc std::vector< std::string > exp_words;
249*11be35a1SLionel Sambuc exp_words.push_back("foo");
250*11be35a1SLionel Sambuc exp_words.push_back("bar");
251*11be35a1SLionel Sambuc exp_words.push_back("baz");
252*11be35a1SLionel Sambuc ATF_REQUIRE(exp_words == words);
253*11be35a1SLionel Sambuc }
254*11be35a1SLionel Sambuc
255*11be35a1SLionel Sambuc
256*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(split__several__delimiters);
ATF_TEST_CASE_BODY(split__several__delimiters)257*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(split__several__delimiters)
258*11be35a1SLionel Sambuc {
259*11be35a1SLionel Sambuc std::vector< std::string > words = text::split("XfooXXbarXXXbazXX", 'X');
260*11be35a1SLionel Sambuc std::vector< std::string > exp_words;
261*11be35a1SLionel Sambuc exp_words.push_back("");
262*11be35a1SLionel Sambuc exp_words.push_back("foo");
263*11be35a1SLionel Sambuc exp_words.push_back("");
264*11be35a1SLionel Sambuc exp_words.push_back("bar");
265*11be35a1SLionel Sambuc exp_words.push_back("");
266*11be35a1SLionel Sambuc exp_words.push_back("");
267*11be35a1SLionel Sambuc exp_words.push_back("baz");
268*11be35a1SLionel Sambuc exp_words.push_back("");
269*11be35a1SLionel Sambuc exp_words.push_back("");
270*11be35a1SLionel Sambuc ATF_REQUIRE(exp_words == words);
271*11be35a1SLionel Sambuc }
272*11be35a1SLionel Sambuc
273*11be35a1SLionel Sambuc
274*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(to_type__ok__bool);
ATF_TEST_CASE_BODY(to_type__ok__bool)275*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(to_type__ok__bool)
276*11be35a1SLionel Sambuc {
277*11be35a1SLionel Sambuc ATF_REQUIRE( text::to_type< bool >("true"));
278*11be35a1SLionel Sambuc ATF_REQUIRE(!text::to_type< bool >("false"));
279*11be35a1SLionel Sambuc }
280*11be35a1SLionel Sambuc
281*11be35a1SLionel Sambuc
282*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(to_type__ok__numerical);
ATF_TEST_CASE_BODY(to_type__ok__numerical)283*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(to_type__ok__numerical)
284*11be35a1SLionel Sambuc {
285*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(12, text::to_type< int >("12"));
286*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(18745, text::to_type< int >("18745"));
287*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(-12345, text::to_type< int >("-12345"));
288*11be35a1SLionel Sambuc
289*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(12.0, text::to_type< double >("12"));
290*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(12.5, text::to_type< double >("12.5"));
291*11be35a1SLionel Sambuc }
292*11be35a1SLionel Sambuc
293*11be35a1SLionel Sambuc
294*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(to_type__ok__string);
ATF_TEST_CASE_BODY(to_type__ok__string)295*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(to_type__ok__string)
296*11be35a1SLionel Sambuc {
297*11be35a1SLionel Sambuc // While this seems redundant, having this particular specialization that
298*11be35a1SLionel Sambuc // does nothing allows callers to delegate work to to_type without worrying
299*11be35a1SLionel Sambuc // about the particular type being converted.
300*11be35a1SLionel Sambuc ATF_REQUIRE_EQ("", text::to_type< std::string >(""));
301*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(" abcd ", text::to_type< std::string >(" abcd "));
302*11be35a1SLionel Sambuc }
303*11be35a1SLionel Sambuc
304*11be35a1SLionel Sambuc
305*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(to_type__empty);
ATF_TEST_CASE_BODY(to_type__empty)306*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(to_type__empty)
307*11be35a1SLionel Sambuc {
308*11be35a1SLionel Sambuc ATF_REQUIRE_THROW(text::value_error, text::to_type< int >(""));
309*11be35a1SLionel Sambuc }
310*11be35a1SLionel Sambuc
311*11be35a1SLionel Sambuc
312*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(to_type__invalid__bool);
ATF_TEST_CASE_BODY(to_type__invalid__bool)313*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(to_type__invalid__bool)
314*11be35a1SLionel Sambuc {
315*11be35a1SLionel Sambuc ATF_REQUIRE_THROW(text::value_error, text::to_type< bool >(""));
316*11be35a1SLionel Sambuc ATF_REQUIRE_THROW(text::value_error, text::to_type< bool >("true "));
317*11be35a1SLionel Sambuc ATF_REQUIRE_THROW(text::value_error, text::to_type< bool >("foo"));
318*11be35a1SLionel Sambuc }
319*11be35a1SLionel Sambuc
320*11be35a1SLionel Sambuc
321*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(to_type__invalid__numerical);
ATF_TEST_CASE_BODY(to_type__invalid__numerical)322*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(to_type__invalid__numerical)
323*11be35a1SLionel Sambuc {
324*11be35a1SLionel Sambuc ATF_REQUIRE_THROW(text::value_error, text::to_type< int >(" 3"));
325*11be35a1SLionel Sambuc ATF_REQUIRE_THROW(text::value_error, text::to_type< int >("3 "));
326*11be35a1SLionel Sambuc ATF_REQUIRE_THROW(text::value_error, text::to_type< int >("3a"));
327*11be35a1SLionel Sambuc ATF_REQUIRE_THROW(text::value_error, text::to_type< int >("a3"));
328*11be35a1SLionel Sambuc }
329*11be35a1SLionel Sambuc
330*11be35a1SLionel Sambuc
ATF_INIT_TEST_CASES(tcs)331*11be35a1SLionel Sambuc ATF_INIT_TEST_CASES(tcs)
332*11be35a1SLionel Sambuc {
333*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, quote__empty);
334*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, quote__no_escaping);
335*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, quote__some_escaping);
336*11be35a1SLionel Sambuc
337*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, refill__empty);
338*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, refill__no_changes);
339*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, refill__break_one);
340*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, refill__break_one__not_first_word);
341*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, refill__break_many);
342*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, refill__cannot_break);
343*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, refill__preserve_whitespace);
344*11be35a1SLionel Sambuc
345*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, join__empty);
346*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, join__one);
347*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, join__several);
348*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, join__unordered);
349*11be35a1SLionel Sambuc
350*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, split__empty);
351*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, split__one);
352*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, split__several__simple);
353*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, split__several__delimiters);
354*11be35a1SLionel Sambuc
355*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, to_type__ok__bool);
356*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, to_type__ok__numerical);
357*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, to_type__ok__string);
358*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, to_type__empty);
359*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, to_type__invalid__bool);
360*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, to_type__invalid__numerical);
361*11be35a1SLionel Sambuc }
362