]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
extract-word: increase test-extract-word coverage for unicode inputs
authorChandra Pratap <chandrapratap3519@gmail.com>
Fri, 8 Mar 2024 14:37:29 +0000 (20:07 +0530)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 8 Mar 2024 21:29:08 +0000 (21:29 +0000)
In the current testing scheme in test-extract-word, we only
have two test cases covering unicode strings. Improve upon
this by adding more cases for the same.

Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
src/test/test-extract-word.c

index 32c01b99fd4e142edf12e78a489496823c2355de..0f10fe7e6f5aa37f71df699233009278927da964 100644 (file)
@@ -533,6 +533,20 @@ TEST(extract_first_word) {
         assert_se(streq(t, "a:a"));
         assert_se(streq(p, ":b"));
         free(t);
+
+        p = original = "zaΕΌΓ³Ε‚ciΔ‡ πŸ‘ŠπŸ”ͺπŸ’ κ°€λ„ˆλ„루";
+        assert_se(extract_first_word(&p, &t, NULL, 0) > 0);
+        assert_se(streq(t, "zaΕΌΓ³Ε‚ciΔ‡"));
+        free(t);
+        assert_se(p == original + 13);
+
+        assert_se(extract_first_word(&p, &t, NULL, 0) > 0);
+        assert_se(streq(t, "πŸ‘ŠπŸ”ͺπŸ’"));
+        free(t);
+        assert_se(extract_first_word(&p, &t, NULL, 0) > 0);
+        assert_se(streq(t, "κ°€λ„ˆλ„λ£¨"));
+        free(t);
+        assert_se(isempty(p));
 }
 
 TEST(extract_first_word_and_warn) {
@@ -758,6 +772,16 @@ TEST(extract_many_words) {
         assert_se(isempty(p));
         assert_se(streq_ptr(a, "foobar"));
         free(a);
+
+        p = original = "gΔ™Ε›lΔ…:πŸ‘ŠπŸ”ͺπŸ’ κ°€λ„ˆλ„루";
+        assert_se(extract_many_words(&p, ":" WHITESPACE, 0, &a, &b, &c) == 3);
+        assert_se(isempty(p));
+        assert_se(streq(a, "gΔ™Ε›lΔ…"));
+        assert_se(streq(b, "πŸ‘ŠπŸ”ͺπŸ’"));
+        assert_se(streq(c, "κ°€λ„ˆλ„λ£¨"));
+        free(a);
+        free(b);
+        free(c);
 }
 
 DEFINE_TEST_MAIN(LOG_INFO);