summaryrefslogtreecommitdiff
path: root/tests/unit/core
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2023-01-30 20:41:36 +0100
committerSébastien Helleu <flashcode@flashtux.org>2023-01-30 21:43:58 +0100
commit38ffac78f3bd635adf069e3c30fc62edc5e90f40 (patch)
tree3cbdc26b8912f50130caf21678f6cc4fd180313e /tests/unit/core
parent269b8fc66e45edb02a58bbee5d4c510873e53951 (diff)
downloadweechat-38ffac78f3bd635adf069e3c30fc62edc5e90f40.zip
core: add function string_levenshtein (issue #1877)
Diffstat (limited to 'tests/unit/core')
-rw-r--r--tests/unit/core/test-core-string.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp
index 7c14345d9..671a1327c 100644
--- a/tests/unit/core/test-core-string.cpp
+++ b/tests/unit/core/test-core-string.cpp
@@ -2542,6 +2542,60 @@ TEST(CoreString, InputForBuffer)
/*
* Tests functions:
+ * string_levenshtein
+ */
+
+TEST(CoreString, Levenshtein)
+{
+ LONGS_EQUAL(0, string_levenshtein (NULL, NULL, 1));
+ LONGS_EQUAL(0, string_levenshtein ("", "", 1));
+ LONGS_EQUAL(3, string_levenshtein (NULL, "abc", 1));
+ LONGS_EQUAL(3, string_levenshtein ("abc", NULL, 1));
+ LONGS_EQUAL(3, string_levenshtein ("", "abc", 1));
+ LONGS_EQUAL(3, string_levenshtein ("abc", "", 1));
+
+ LONGS_EQUAL(0, string_levenshtein ("abc", "abc", 1));
+ LONGS_EQUAL(1, string_levenshtein ("abc", "ab", 1));
+ LONGS_EQUAL(1, string_levenshtein ("ab", "abc", 1));
+ LONGS_EQUAL(2, string_levenshtein ("abc", "a", 1));
+ LONGS_EQUAL(2, string_levenshtein ("a", "abc", 1));
+ LONGS_EQUAL(3, string_levenshtein ("abc", "", 1));
+ LONGS_EQUAL(3, string_levenshtein ("", "abc", 1));
+
+ LONGS_EQUAL(3, string_levenshtein ("abc", "ABC", 1));
+ LONGS_EQUAL(3, string_levenshtein ("abc", "AB", 1));
+ LONGS_EQUAL(3, string_levenshtein ("ab", "ABC", 1));
+ LONGS_EQUAL(3, string_levenshtein ("abc", "A", 1));
+ LONGS_EQUAL(3, string_levenshtein ("a", "ABC", 1));
+ LONGS_EQUAL(3, string_levenshtein ("abc", "", 1));
+ LONGS_EQUAL(3, string_levenshtein ("", "ABC", 1));
+
+ LONGS_EQUAL(0, string_levenshtein ("abc", "ABC", 0));
+ LONGS_EQUAL(1, string_levenshtein ("abc", "AB", 0));
+ LONGS_EQUAL(1, string_levenshtein ("ab", "ABC", 0));
+ LONGS_EQUAL(2, string_levenshtein ("abc", "A", 0));
+ LONGS_EQUAL(2, string_levenshtein ("a", "ABC", 0));
+ LONGS_EQUAL(3, string_levenshtein ("abc", "", 0));
+ LONGS_EQUAL(3, string_levenshtein ("", "ABC", 0));
+
+ LONGS_EQUAL(2, string_levenshtein ("response", "respond", 1));
+ LONGS_EQUAL(4, string_levenshtein ("response", "resist", 1));
+
+ LONGS_EQUAL(2, string_levenshtein ("response", "responsive", 1));
+
+ /* with UTF-8 chars */
+ LONGS_EQUAL(1, string_levenshtein ("é", "É", 1));
+ LONGS_EQUAL(0, string_levenshtein ("é", "É", 0));
+ LONGS_EQUAL(1, string_levenshtein ("é", "à", 1));
+ LONGS_EQUAL(1, string_levenshtein ("é", "à", 0));
+ LONGS_EQUAL(1, string_levenshtein ("té", "to", 1));
+ LONGS_EQUAL(1, string_levenshtein ("noël", "noel", 1));
+ LONGS_EQUAL(2, string_levenshtein ("bôô", "boo", 1));
+ LONGS_EQUAL(2, string_levenshtein ("界世", "こん", 1));
+}
+
+/*
+ * Tests functions:
* string_get_priority_and_name
*/