38 #include <gtest/gtest.h>
49 TEST(StrTest, EatLeadWhite)
51 std::string
val =
" hello there ";
53 EXPECT_EQ(
"hello there ",
val);
56 TEST(StrTest, EatLeadWhiteNoLeadingWhitespace)
58 std::string
val =
"hello there ";
60 EXPECT_EQ(
"hello there ",
val);
65 std::string
val =
" hello there ";
67 EXPECT_EQ(
" hello there",
val);
70 TEST(StrTest, EatEndWhiteNoTrailingWhitespace)
72 std::string
val =
" hello there";
74 EXPECT_EQ(
" hello there",
val);
79 std::string
val =
" hello there ";
81 EXPECT_EQ(
"hello there",
val);
84 TEST(StrTest, EatWhiteNoWhitespace)
86 std::string
val =
"hello there";
88 EXPECT_EQ(
"hello there",
val);
97 std::string
val =
"gOoDbYe FOO@barr!";
112 std::string
val =
"abcdefg abcdefg";
117 EXPECT_EQ(
"abcdefg abcdefg",
val);
118 EXPECT_EQ(
"abcde", lhs);
119 EXPECT_EQ(
"g abcdefg", rhs);
122 TEST(StrTest, SplitFirstNoChar)
124 std::string
val =
"abcdefg abcdefg";
129 EXPECT_EQ(
"abcdefg abcdefg",
val);
130 EXPECT_EQ(
"abcdefg abcdefg", lhs);
134 TEST(StrTest, SplitFirstOnFirstChar)
136 std::string
val =
"abcdefg abcdefg";
141 EXPECT_EQ(
"abcdefg abcdefg",
val);
143 EXPECT_EQ(
"bcdefg abcdefg", rhs);
148 std::string
val =
"abcdefg abcdefg";
153 EXPECT_EQ(
"abcdefg abcdefg",
val);
154 EXPECT_EQ(
"abcdefg abcde", lhs);
160 std::string
val =
"abcdefg abcdefg";
165 EXPECT_EQ(
"abcdefg abcdefg",
val);
166 EXPECT_EQ(
"abcdefg abcdefg", lhs);
170 TEST(StrTest, SplitLastOnLastChar)
172 std::string
val =
"abcdefg abcdefg";
177 EXPECT_EQ(
"abcdefg abcdefg",
val);
178 EXPECT_EQ(
"abcdefg abcdef", lhs);
193 std::string
val =
" Hello, this is a sentence. ";
201 EXPECT_EQ(
" Hello, this is a sentence. ",
val);
202 EXPECT_EQ(5, tokens.size());
203 EXPECT_EQ(
"Hello,", tokens[0]);
204 EXPECT_EQ(
"this", tokens[1]);
205 EXPECT_EQ(
"is", tokens[2]);
206 EXPECT_EQ(
"a", tokens[3]);
207 EXPECT_EQ(
"sentence.", tokens[4]);
210 TEST(StrTest, TokenizeOnSpaceIgnFalse)
216 std::string
val =
" Hello, this is a sentence. ";
220 EXPECT_EQ(
" Hello, this is a sentence. ",
val);
221 EXPECT_EQ(11, tokens.size());
222 EXPECT_EQ(
"", tokens[0]);
223 EXPECT_EQ(
"Hello,", tokens[1]);
224 EXPECT_EQ(
"", tokens[2]);
225 EXPECT_EQ(
"this", tokens[3]);
226 EXPECT_EQ(
"", tokens[4]);
227 EXPECT_EQ(
"is", tokens[5]);
228 EXPECT_EQ(
"", tokens[6]);
229 EXPECT_EQ(
"a", tokens[7]);
230 EXPECT_EQ(
"", tokens[8]);
231 EXPECT_EQ(
"sentence.", tokens[9]);
232 EXPECT_EQ(
"", tokens[10]);
235 TEST(StrTest, TokenizedTokenDoesNotExist)
237 std::string
val =
"abcdefg";
241 EXPECT_EQ(
"abcdefg",
val);
242 EXPECT_EQ(1, tokens.size());
243 EXPECT_EQ(
"abcdefg", tokens[0]);
254 std::string input =
"-128";
259 TEST(StrTest, ToNumber8BitIntStringOutOfRange)
262 std::string input =
"-129";
266 TEST(StrTest, ToNumber8BitIntInvalidString)
269 std::string input =
"onetwoeight";
273 TEST(StrTest, ToNumberUnsigned8BitInt)
276 std::string input =
"255";
281 TEST(StrTest, ToNumberUnsigned8BitIntNegative)
284 std::string input =
"-1";
289 TEST(StrTest, ToNumberUnsigned8BitIntRoundDown)
292 std::string input_1 =
"2.99";
296 std::string input_2 =
"3.99";
305 TEST(StrTest, ToNumber8BitUnsignedLimit)
308 std::string input =
"255.99";
317 TEST(StrTest, ToNumber8BitUnsignedOutOfRange)
320 std::string input =
"256.99";
325 TEST(StrTest, ToNumberUnsignedScientific)
328 std::string input =
"8.234e+08";
333 TEST(StrTest, ToNumberIntScientificNegative)
336 std::string input =
"-8.234e+08";
340 TEST(StrTest, ToNumber64BitInt)
343 int64_t input_number = 0xFFFFFFFFFFFFFFFF;
346 EXPECT_EQ(input_number,
output);
349 TEST(StrTest, ToNumber64BitIntInvalidString)
352 std::string input =
" ";
363 std::string input =
"2";
369 TEST(StrTest, DISABLED_ToNumberEnumInvalid)
376 std::string input =
"3";
383 std::string input =
"0.1";
384 float expected_output = 0.1;
386 EXPECT_EQ(expected_output,
output);
389 TEST(StrTest, ToNumberFloatIntegerString)
392 std::string input =
"10";
393 float expected_output = 10.0;
395 EXPECT_EQ(expected_output,
output);
398 TEST(StrTest, ToNumberFloatNegative)
401 std::string input =
"-0.1";
402 float expected_output = -0.1;
404 EXPECT_EQ(expected_output,
output);
410 std::string input =
"0.0001";
411 double expected_output = 0.0001;
413 EXPECT_EQ(expected_output,
output);
416 TEST(StrTest, ToNumberDoubleIntegerString)
419 std::string input =
"12345";
420 double expected_output = 12345.0;
422 EXPECT_EQ(expected_output,
output);
425 TEST(StrTest, ToNumberDoubleNegative)
428 std::string input =
"-1.2345";
429 double expected_output = -1.2345;
431 EXPECT_EQ(expected_output,
output);
435 TEST(StrTest, ToNumberScientific)
438 std::string input =
"8.234e+08";
439 double expected_output = 823400000;
441 EXPECT_EQ(expected_output,
output);
462 TEST(StrTest, ToBoolInvalidInput)
472 TEST(StrTest, QuoteStringNoSpace)
474 EXPECT_EQ(
"hello",
quote(
"hello"));
477 TEST(StrTest, QuoteStringWithSpace)
479 EXPECT_EQ(
"\"hello world\"",
quote(
"hello world"));
482 TEST(StrTest, QuoteQuotedString)
487 EXPECT_EQ(
"\"\"hello world\"\"",
quote(
"\"hello world\""));
490 TEST(StrTest, QuoteStringWithTab)
496 EXPECT_EQ(
"hello\tworld",
quote(
"hello\tworld"));
505 TEST(StrTest, StartswithDoubleStringDoesStartWith)
507 std::string
s =
"Hello, how are you?";
508 std::string prefix =
"Hello";
512 TEST(StrTest, StartswithDoubleStringDoesNotStartWith)
514 std::string
s =
"Hello, how are you?";
515 std::string prefix =
"ello";
519 TEST(StrTest, StartswithDoubleCharArrayDoesStartWith)
521 const char*
s =
"abcdefg";
522 const char* prefix =
"ab";
526 TEST(StrTest, StartswithDoubleCharArrayDoesNotStartWith)
528 const char*
s =
" abcdefg";
529 const char* prefix =
"a";
533 TEST(StrTest, StartswithStringCharArrayDoesStartWith)
535 std::string
s =
"foobarr";
536 const char* prefix =
"f";
540 TEST(StrTest, StartswithStringCharArrayDoesNotStartWith)
542 std::string
s =
"foobarr";
543 const char* prefix =
"barr";