aboutsummaryrefslogtreecommitdiff
path: root/libs/kstd/kstd/string.test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/kstd/kstd/string.test.cpp')
-rw-r--r--libs/kstd/kstd/string.test.cpp305
1 files changed, 305 insertions, 0 deletions
diff --git a/libs/kstd/kstd/string.test.cpp b/libs/kstd/kstd/string.test.cpp
index 74be1f0b..3fbf6c0c 100644
--- a/libs/kstd/kstd/string.test.cpp
+++ b/libs/kstd/kstd/string.test.cpp
@@ -2533,6 +2533,311 @@ SCENARIO("String conversion and comparison", "[string]")
REQUIRE_FALSE(view != str);
}
}
+
+ GIVEN("The string 'abc'")
+ {
+ auto s1 = kstd::string{"abc"};
+
+ WHEN("comparing with the string 'def'")
+ {
+ auto result = s1.compare(kstd::string{"def"});
+
+ THEN("the result is negative")
+ {
+ REQUIRE(result < 0);
+ }
+ }
+
+ WHEN("comparing with the string 'abb'")
+ {
+ auto result = s1.compare(kstd::string{"abb"});
+
+ THEN("the result is positive")
+ {
+ REQUIRE(result > 0);
+ }
+ }
+
+ WHEN("comparing with the string 'abc'")
+ {
+ auto result = s1.compare(kstd::string{"abc"});
+
+ THEN("the result is zero")
+ {
+ REQUIRE(result == 0);
+ }
+ }
+
+ WHEN("comparing substring [1,2] with the string 'def'")
+ {
+ auto result = s1.compare(1, 2, kstd::string{"def"});
+
+ THEN("the result is negative")
+ {
+ REQUIRE(result < 0);
+ }
+ }
+
+ WHEN("comparing substring [1,2] with the string 'abb'")
+ {
+ auto result = s1.compare(1, 2, kstd::string{"abb"});
+
+ THEN("the result is positive")
+ {
+ REQUIRE(result > 0);
+ }
+ }
+
+ WHEN("comparing substring [1,2] with the string 'cc'")
+ {
+ auto result = s1.compare(1, 2, kstd::string{"bc"});
+
+ THEN("the result is zero")
+ {
+ REQUIRE(result == 0);
+ }
+ }
+
+ WHEN("comparing substring [1,npos] with the string 'ef'")
+ {
+ auto result = s1.compare(1, kstd::string::npos, kstd::string{"ef"});
+
+ THEN("the result is negative")
+ {
+ REQUIRE(result < 0);
+ }
+ }
+
+ WHEN("comparing substring [1,npos] with the string 'bb'")
+ {
+ auto result = s1.compare(1, kstd::string::npos, kstd::string{"bb"});
+
+ THEN("the result is positive")
+ {
+ REQUIRE(result > 0);
+ }
+ }
+
+ WHEN("comparing substring [1,npos] with the string 'bc'")
+ {
+ auto result = s1.compare(1, kstd::string::npos, kstd::string{"bc"});
+
+ THEN("the result is zero")
+ {
+ REQUIRE(result == 0);
+ }
+ }
+
+ WHEN("comparing substring [1,2] with the substring [1,2] of 'def'")
+ {
+ auto result = s1.compare(1, 2, kstd::string{"def"}, 1, 2);
+
+ THEN("the result is negative")
+ {
+ REQUIRE(result < 0);
+ }
+ }
+
+ WHEN("comparing substring [1,2] with the substring [1,2] of 'abb'")
+ {
+ auto result = s1.compare(1, 2, kstd::string{"abb"}, 1, 2);
+
+ THEN("the result is positive")
+ {
+ REQUIRE(result > 0);
+ }
+ }
+
+ WHEN("comparing substring [1,2] with the substring [1,2] of 'abc'")
+ {
+ auto result = s1.compare(1, 2, kstd::string{"abc"}, 1, 2);
+
+ THEN("the result is zero")
+ {
+ REQUIRE(result == 0);
+ }
+ }
+
+ WHEN("comparing substring [1,npos] with the substring [1,2] of 'def'")
+ {
+ auto result = s1.compare(1, kstd::string::npos, kstd::string{"def"}, 1, 2);
+
+ THEN("the result is negative")
+ {
+ REQUIRE(result < 0);
+ }
+ }
+
+ WHEN("comparing substring [1,npos] with the substring [1,2] of 'abb'")
+ {
+ auto result = s1.compare(1, kstd::string::npos, kstd::string{"abb"}, 1, 2);
+
+ THEN("the result is positive")
+ {
+ REQUIRE(result > 0);
+ }
+ }
+
+ WHEN("comparing substring [1,npos] with the substring [1,2] of 'abc'")
+ {
+ auto result = s1.compare(1, kstd::string::npos, kstd::string{"abc"}, 1, 2);
+
+ THEN("the result is zero")
+ {
+ REQUIRE(result == 0);
+ }
+ }
+
+ WHEN("comparing substring [1,2] with the substring [1,npos] of 'def'")
+ {
+ auto result = s1.compare(1, 2, kstd::string{"def"}, 1, kstd::string::npos);
+
+ THEN("the result is negative")
+ {
+ REQUIRE(result < 0);
+ }
+ }
+
+ WHEN("comparing substring [1,2] with the substring [1,npos] of 'abb'")
+ {
+ auto result = s1.compare(1, 2, kstd::string{"abb"}, 1, kstd::string::npos);
+
+ THEN("the result is positive")
+ {
+ REQUIRE(result > 0);
+ }
+ }
+
+ WHEN("comparing substring [1,2] with the substring [1,npos] of 'abc'")
+ {
+ auto result = s1.compare(1, 2, kstd::string{"abc"}, 1, kstd::string::npos);
+
+ THEN("the result is zero")
+ {
+ REQUIRE(result == 0);
+ }
+ }
+
+ WHEN("comparing substring [1,npos] with the substring [1,npos] of 'def'")
+ {
+ auto result = s1.compare(1, kstd::string::npos, kstd::string{"def"}, 1, kstd::string::npos);
+
+ THEN("the result is negative")
+ {
+ REQUIRE(result < 0);
+ }
+ }
+
+ WHEN("comparing substring [1,npos] with the substring [1,npos] of 'abb'")
+ {
+ auto result = s1.compare(1, kstd::string::npos, kstd::string{"abb"}, 1, kstd::string::npos);
+
+ THEN("the result is positive")
+ {
+ REQUIRE(result > 0);
+ }
+ }
+
+ WHEN("comparing substring [1,npos] with the substring [1,npos] of 'abc'")
+ {
+ auto result = s1.compare(1, kstd::string::npos, kstd::string{"abc"}, 1, kstd::string::npos);
+
+ THEN("the result is zero")
+ {
+ REQUIRE(result == 0);
+ }
+ }
+
+ WHEN("comparing with the C-style string 'def'")
+ {
+ auto result = s1.compare("def");
+
+ THEN("the result is negative")
+ {
+ REQUIRE(result < 0);
+ }
+ }
+
+ WHEN("comparing with the C-style string 'abb'")
+ {
+ auto result = s1.compare("abb");
+
+ THEN("the result is positive")
+ {
+ REQUIRE(result > 0);
+ }
+ }
+
+ WHEN("comparing with the C-style string 'abc'")
+ {
+ auto result = s1.compare("abc");
+
+ THEN("the result is zero")
+ {
+ REQUIRE(result == 0);
+ }
+ }
+
+ WHEN("comparing substring [1,2] with the C-style string 'def'")
+ {
+ auto result = s1.compare(1, 2, "def");
+
+ THEN("the result is negative")
+ {
+ REQUIRE(result < 0);
+ }
+ }
+
+ WHEN("comparing substring [1,2] with the C-style string 'abb'")
+ {
+ auto result = s1.compare(1, 2, "abb");
+
+ THEN("the result is positive")
+ {
+ REQUIRE(result > 0);
+ }
+ }
+
+ WHEN("comparing substring [1,2] with the C-style string 'bc'")
+ {
+ auto result = s1.compare(1, 2, "bc");
+
+ THEN("the result is zero")
+ {
+ REQUIRE(result == 0);
+ }
+ }
+
+ WHEN("comparing substring [1,npos] with the C-style string 'def'")
+ {
+ auto result = s1.compare(1, 2, "ef");
+
+ THEN("the result is negative")
+ {
+ REQUIRE(result < 0);
+ }
+ }
+
+ WHEN("comparing substring [1,npos] with the C-style string 'abb'")
+ {
+ auto result = s1.compare(1, 2, "abb");
+
+ THEN("the result is positive")
+ {
+ REQUIRE(result > 0);
+ }
+ }
+
+ WHEN("comparing substring [1,npos] with the C-style string 'bc'")
+ {
+ auto result = s1.compare(1, 2, "bc");
+
+ THEN("the result is zero")
+ {
+ REQUIRE(result == 0);
+ }
+ }
+ }
}
SCENARIO("String iteration", "[string]")