40 #include <gtest/gtest.h> 51 TEST(StrTest, EatLeadWhite)
53 std::string
val =
" hello there ";
58 TEST(StrTest, EatLeadWhiteNoLeadingWhitespace)
60 std::string
val =
"hello there ";
67 std::string
val =
" hello there ";
72 TEST(StrTest, EatEndWhiteNoTrailingWhitespace)
74 std::string
val =
" hello there";
81 std::string
val =
" hello there ";
86 TEST(StrTest, EatWhiteNoWhitespace)
88 std::string
val =
"hello there";
99 std::string
val =
"gOoDbYe FOO@barr!";
114 std::string
val =
"abcdefg abcdefg";
124 TEST(StrTest, SplitFirstNoChar)
126 std::string
val =
"abcdefg abcdefg";
136 TEST(StrTest, SplitFirstOnFirstChar)
138 std::string
val =
"abcdefg abcdefg";
150 std::string
val =
"abcdefg abcdefg";
162 std::string
val =
"abcdefg abcdefg";
172 TEST(StrTest, SplitLastOnLastChar)
174 std::string
val =
"abcdefg abcdefg";
195 std::string
val =
" Hello, this is a sentence. ";
203 EXPECT_EQ(
" Hello, this is a sentence. ", val);
212 TEST(StrTest, TokenizeOnSpaceIgnFalse)
218 std::string
val =
" Hello, this is a sentence. ";
222 EXPECT_EQ(
" Hello, this is a sentence. ", val);
237 TEST(StrTest, TokenizedTokenDoesNotExist)
239 std::string
val =
"abcdefg";
256 std::string input =
"-128";
261 TEST(StrTest, ToNumber8BitIntStringOutOfRange)
264 std::string input =
"-129";
268 TEST(StrTest, ToNumber8BitIntInvalidString)
271 std::string input =
"onetwoeight";
275 TEST(StrTest, ToNumberUnsigned8BitInt)
278 std::string input =
"255";
283 TEST(StrTest, ToNumberUnsigned8BitIntNegative)
286 std::string input =
"-1";
290 TEST(StrTest, ToNumber64BitInt)
293 int64_t input_number = 0xFFFFFFFFFFFFFFFF;
299 TEST(StrTest, ToNumber64BitIntInvalidString)
302 std::string input =
" ";
309 std::string input =
"0.1";
310 float expected_output = 0.1;
315 TEST(StrTest, ToNumberFloatIntegerString)
318 std::string input =
"10";
319 float expected_output = 10.0;
324 TEST(StrTest, ToNumberFloatNegative)
327 std::string input =
"-0.1";
328 float expected_output = -0.1;
336 std::string input =
"0.0001";
337 double expected_output = 0.0001;
342 TEST(StrTest, ToNumberDoubleIntegerString)
345 std::string input =
"12345";
346 double expected_output = 12345.0;
351 TEST(StrTest, ToNumberDoubleNegative)
354 std::string input =
"-1.2345";
355 double expected_output = -1.2345;
378 TEST(StrTest, ToBoolInvalidInput)
388 TEST(StrTest, QuoteStringNoSpace)
393 TEST(StrTest, QuoteStringWithSpace)
398 TEST(StrTest, QuoteQuotedString)
406 TEST(StrTest, QuoteStringWithTab)
421 TEST(StrTest, StartswithDoubleStringDoesStartWith)
423 std::string
s =
"Hello, how are you?";
424 std::string prefix =
"Hello";
428 TEST(StrTest, StartswithDoubleStringDoesNotStartWith)
430 std::string
s =
"Hello, how are you?";
431 std::string prefix =
"ello";
435 TEST(StrTest, StartswithDoubleCharArrayDoesStartWith)
437 const char*
s =
"abcdefg";
438 const char* prefix =
"ab";
442 TEST(StrTest, StartswithDoubleCharArrayDoesNotStartWith)
444 const char*
s =
" abcdefg";
445 const char* prefix =
"a";
449 TEST(StrTest, StartswithStringCharArrayDoesStartWith)
451 std::string
s =
"foobarr";
452 const char* prefix =
"f";
456 TEST(StrTest, StartswithStringCharArrayDoesNotStartWith)
458 std::string
s =
"foobarr";
459 const char* prefix =
"barr";
bool to_bool(const std::string &value, bool &retval)
Turn a string representation of a boolean into a boolean value.
static void output(const char *filename)
void eat_end_white(std::string &s)
bool split_last(const string &s, string &lhs, string &rhs, char c)
#define EXPECT_TRUE(expr)
A macro which verifies that expr evaluates to true.
TEST(StrTest, EatLeadWhite)
bool to_number(const std::string &value, VecPredRegContainer< NumBits, Packed > &p)
Helper functions used for serialization/de-serialization.
#define EXPECT_FALSE(expr)
A macro which verifies that expr evaluates to false.
bool startswith(const char *s, const char *prefix)
Return true if 's' starts with the prefix string 'prefix'.
std::string quote(const std::string &s)
void eat_white(std::string &s)
bool split_first(const string &s, string &lhs, string &rhs, char c)
std::string to_lower(const std::string &s)
void tokenize(vector< string > &v, const string &s, char token, bool ignore)
void eat_lead_white(std::string &s)
#define EXPECT_EQ(lhs, rhs)
A macro which verifies that lhs and rhs are equal to each other.
const std::string to_string(sc_enc enc)