summaryrefslogtreecommitdiffstats
path: root/src/base/string_util.tests.cc
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/base/string_util.tests.cc43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/base/string_util.tests.cc b/src/base/string_util.tests.cc
index 98cf5c8..c27f2a2 100644
--- a/src/base/string_util.tests.cc
+++ b/src/base/string_util.tests.cc
@@ -87,4 +87,47 @@ TEST_CASE("strnatcmp")
CHECK(strnatcmp(strlen(n1), n1, strlen(n2), n2) < 0);
}
+ {
+ constexpr const char* n1 = "servers";
+ constexpr const char* n2 = "servers.alpha";
+
+ CHECK(strnatcasecmp(strlen(n1), n1, strlen(n2), n2) < 0);
+ }
+ {
+ static constexpr const char* TOKENS = "[](){}";
+ const std::string n1 = "[servers]";
+ const std::string n2 = "[servers.alpha]";
+
+ auto lhs = string_fragment::from_str(n1).trim(TOKENS);
+ auto rhs = string_fragment::from_str(n2).trim(TOKENS);
+ CHECK(strnatcasecmp(lhs.length(), lhs.data(), rhs.length(), rhs.data())
+ < 0);
+ }
+
+ {
+ const std::string a = "10.112.81.15";
+ const std::string b = "192.168.202.254";
+
+ int ipcmp = 0;
+ auto rc = ipv4cmp(a.length(), a.c_str(), b.length(), b.c_str(), &ipcmp);
+ CHECK(rc == 1);
+ CHECK(ipcmp == -1);
+ }
+}
+
+TEST_CASE("last_word_str")
+{
+ {
+ std::string s = "foobar baz";
+
+ auto rc = last_word_str(&s[0], s.length(), 6);
+ CHECK(s.length() == rc);
+ }
+ {
+ std::string s = "com.example.foo";
+
+ auto rc = last_word_str(&s[0], s.length(), 6);
+ s.resize(rc);
+ CHECK(s == "foo");
+ }
}