21 TEST_CASE(
"ModernStringUtils_strToLower",
"[utilities]")
23 std::string test_string(
"IamAMixedCaseTest_String");
24 std::string lcase_string =
lowerCase(test_string);
25 CHECK(lcase_string ==
"iamamixedcasetest_string");
26 std::string i_am_not_just_ascii{
"\xab" 30 i_am_not_just_ascii =
lowerCase(i_am_not_just_ascii);
31 CHECK(i_am_not_just_ascii ==
41 auto no_tokens =
split(nothing,
" ");
42 CHECK(no_tokens.empty());
43 no_tokens =
split(nothing,
"");
44 CHECK(no_tokens.empty());
46 std::string white_space{
" "};
47 auto tokens =
split(white_space,
".");
48 CHECK(tokens.size() == 1);
49 CHECK(tokens[0] ==
" ");
51 tokens =
split(white_space,
" ");
52 CHECK(tokens.empty());
54 std::string test_line{
"hi there 101, random line"};
55 tokens =
split(test_line,
" ");
56 CHECK(tokens[0].size() == 2);
57 CHECK(tokens[4].size() == 4);
58 CHECK(tokens[3] ==
"random");
60 tokens =
split(test_line,
"");
61 CHECK(tokens.size() == 1);
63 tokens =
split(test_line,
";");
64 CHECK(tokens.size() == 1);
66 std::string test_lines{R
"( 71 auto tokens_lines =
split(test_lines,
"\n");
72 CHECK(tokens_lines[0] ==
"this is a multi");
73 CHECK(tokens_lines[1] ==
"line");
74 CHECK(tokens_lines[2] ==
"token test");
76 std::string test_multidel{
"this \t is a multidelimiter \n \n token test"};
77 auto tokens_multidel =
split(test_multidel,
"\t \n");
78 CHECK(tokens_multidel[0] ==
"this");
79 CHECK(tokens_multidel[1] ==
"is");
80 CHECK(tokens_multidel[4] ==
"token");
83 TEST_CASE(
"ModernStringUtils_string2Real",
"[utilities]")
85 std::string_view svalue{
"101.52326626"};
86 double value = string2Real<double>(svalue);
87 CHECK(value == Approx(101.52326626));
90 TEST_CASE(
"ModernStringUtils_string2Int",
"[utilities]")
92 std::string_view svalue{
"1003"};
93 auto value = string2Int<int>(svalue);
95 long too_large_for_int = std::numeric_limits<int>::max();
96 too_large_for_int += 2;
97 std::ostringstream
input;
98 input << too_large_for_int;
100 #if _GLIBCXX_RELEASE > 10 101 CHECK_THROWS_AS(string2Int<int>(
input.str()), std::range_error);
102 CHECK_THROWS_AS(string2Int<int>(
"bad"), std::runtime_error);
104 long big_enough = string2Int<decltype(big_enough)>(
input.str());
105 CHECK(big_enough == too_large_for_int);
114 auto stripped_nothing =
strip(nothing);
115 CHECK(stripped_nothing.empty());
117 std::string white_space{
" "};
118 auto stripped_white_space =
strip(white_space);
119 CHECK(stripped_white_space.empty());
121 std::string test_lines{R
"( 127 std::string_view stripped_lines = strip(test_lines); 129 std::string_view ref_stripped{"r1 1 0 0\n r2 0 1 0\n r3 0 0 1"};
130 CHECK(ref_stripped == stripped_lines);
132 std::string_view another{
"r1 1 0 0\n r2 0 1 0\n r3 0 0 1\n \0"};
133 std::string_view another_stripped =
strip(another);
134 CHECK(another_stripped ==
"r1 1 0 0\n r2 0 1 0\n r3 0 0 1");
136 std::string_view unneeded{
"this needs no stripping"};
137 std::string_view unneeded_stripped =
strip(unneeded);
138 CHECK(unneeded_stripped == unneeded);
helper functions for EinsplineSetBuilder
TEST_CASE("complex_helper", "[type_traits]")
std::string_view strip(const string_view s)
std::string strip(const std::string &s)
std::vector< std::string > split(const std::string &s)
std::string lowerCase(const std::string_view s)
++17
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
std::vector< std::string_view > split(const string_view s, const string_view delimiters)
testing::ValidSpinDensityInput input