summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPhil Jones <philj56@gmail.com>2023-04-17 23:43:05 +0100
committerPhil Jones <philj56@gmail.com>2023-04-17 23:43:05 +0100
commit574eff0df1aff9bdc6d32939a03312cc08803de3 (patch)
tree5aeca72f70314bee3bf95db99f10d89f0a7b4032 /test
parent71a4801d20d8904cfcfa5e92c96d53ee06a2c69f (diff)
Add --matching-algorithm option.
This replaces the --fuzzy-match algorithm. Available choices are normal, prefix and fuzzy. Levenshtein distance was investigated, but it seems pretty rubbish for tofi's use case, where you normally want a good match when you've only typed a small portion of the target string.
Diffstat (limited to 'test')
-rw-r--r--test/config.c6
-rw-r--r--test/utf8.c36
2 files changed, 19 insertions, 23 deletions
diff --git a/test/config.c b/test/config.c
index 79f90e5..c15d66d 100644
--- a/test/config.c
+++ b/test/config.c
@@ -45,6 +45,12 @@ int main(int argc, char *argv[])
is_valid("text-cursor-style", "underscore", "Text cursor underscore");
isnt_valid("text-cursor-style", "blocky", "Invalid text cursor style");
+ /* Matching algorithms */
+ is_valid("matching-algorithm", "normal", "Normal matching");
+ is_valid("matching-algorithm", "fuzzy", "Fuzzy matching");
+ is_valid("matching-algorithm", "prefix", "Prefix matching");
+ isnt_valid("matching-algorithm", "regex", "Regex matching");
+
/* Bools */
is_valid("horizontal", "tRuE", "Boolean true");
is_valid("horizontal", "fAlSe", "Boolean false");
diff --git a/test/utf8.c b/test/utf8.c
index f18eca0..5d75cb6 100644
--- a/test/utf8.c
+++ b/test/utf8.c
@@ -3,43 +3,33 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "fuzzy_match.h"
+#include "matching.h"
#include "tap.h"
-void is_simple_match(const char *pattern, const char *str, const char *message)
+void is_single_match(enum matching_algorithm algorithm, const char *pattern, const char *str, const char *message)
{
- int32_t res = fuzzy_match_simple_words(pattern, str);
+ int32_t res = match_words(algorithm, pattern, str);
tap_isnt(res, INT32_MIN, message);
}
-void isnt_simple_match(const char *pattern, const char *str, const char *message)
+void isnt_single_match(enum matching_algorithm algorithm, const char *pattern, const char *str, const char *message)
{
- int32_t res = fuzzy_match_simple_words(pattern, str);
- tap_is(res, INT32_MIN, message);
-}
-
-void is_fuzzy_match(const char *pattern, const char *str, const char *message)
-{
- int32_t res = fuzzy_match_words(pattern, str);
- tap_isnt(res, INT32_MIN, message);
-}
-
-void isnt_fuzzy_match(const char *pattern, const char *str, const char *message)
-{
- int32_t res = fuzzy_match_words(pattern, str);
+ int32_t res = match_words(algorithm, pattern, str);
tap_is(res, INT32_MIN, message);
}
void is_match(const char *pattern, const char *str, const char *message)
{
- is_simple_match(pattern, str, message);
- is_fuzzy_match(pattern, str, message);
+ is_single_match(MATCHING_ALGORITHM_NORMAL, pattern, str, message);
+ is_single_match(MATCHING_ALGORITHM_PREFIX, pattern, str, message);
+ is_single_match(MATCHING_ALGORITHM_FUZZY, pattern, str, message);
}
void isnt_match(const char *pattern, const char *str, const char *message)
{
- isnt_simple_match(pattern, str, message);
- isnt_fuzzy_match(pattern, str, message);
+ isnt_single_match(MATCHING_ALGORITHM_NORMAL, pattern, str, message);
+ isnt_single_match(MATCHING_ALGORITHM_PREFIX, pattern, str, message);
+ isnt_single_match(MATCHING_ALGORITHM_FUZZY, pattern, str, message);
}
int main(int argc, char *argv[])
@@ -56,9 +46,9 @@ int main(int argc, char *argv[])
/* Combining diacritics. */
isnt_match("o", "ọ", "Single character with composed diacritic");
- isnt_simple_match("ạ", "aọ", "Decomposed diacritics, character mismatch");
+ isnt_single_match(MATCHING_ALGORITHM_NORMAL, "ạ", "aọ", "Decomposed diacritics, character mismatch");
tap_todo("Needs composed character comparison");
- isnt_fuzzy_match("ạ", "aọ", "Decomposed diacritics, character mismatch");
+ isnt_single_match(MATCHING_ALGORITHM_FUZZY, "ạ", "aọ", "Decomposed diacritics, character mismatch");
tap_plan();