]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-fts: test-fts-tokenizer - explicit-prefix tests
authorPhil Carmody <phil@dovecot.fi>
Sat, 28 Apr 2018 12:33:28 +0000 (15:33 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 10 Oct 2018 04:47:26 +0000 (04:47 +0000)
Note that the special handling of '*' only kicks in when in
"search" and "explicitprefix" mode (as passed in through the
settings), and currently, only for the simple mode, not tr29.

Signed-off-by: Phil Carmody <phil@dovecot.fi>
src/lib-fts/test-fts-tokenizer.c

index b2f9eddd0fbcf1b78e8f2a5d1c6fbd7cac1ea966..09bc7560d65efb2911a535d8baa9424bdbad57f3 100644 (file)
@@ -502,6 +502,66 @@ static void test_fts_tokenizer_random(void)
        test_end();
 }
 
+
+static void
+test_fts_tokenizer_explicit_prefix(void)
+{
+       const char *input = "* ** "
+               "*pre *both* post* "
+               "mid*dle *mid*dle* "
+               "**twopre **twoboth** twopost**";
+       const char *const expected_star[] = { "pre", "both*", "post*",
+                                             "mid*", "dle", "mid*", "dle*",
+                                             "twopre", "twoboth*", "twopost*",
+                                             NULL, NULL };
+       const char *const expected_nostar[] = { "pre", "both", "post",
+                                               "mid", "dle", "mid", "dle",
+                                               "twopre", "twoboth", "twopost",
+                                               NULL, NULL };
+
+       const char *settings[9] = { "algorithm", "tr29", "wb5a", "yes" };
+       const char **setptr;
+
+       const char *algos[] = { ALGORITHM_SIMPLE_NAME,
+                               ALGORITHM_TR29_NAME,
+                               ALGORITHM_TR29_NAME "+wb5a" };
+       const char *searches[] = { "indexing", "searching" };
+       const char *prefixes[] = { "fixed", "prefix" };
+
+       for (int algo = 2; algo >= 0; algo--) { /* We overwrite the settings over time */
+               setptr = &settings[algo*2]; /* 4, 2, or 0 settings strings preserved */
+
+               for (int search = 0; search < 2; search++) {
+                       const char **setptr2 = setptr;
+                       if (search > 0) { *setptr2++ = "search"; *setptr2++ = "yes"; }
+
+                       for (int explicitprefix = 0; explicitprefix < 2; explicitprefix++) {
+                               const char **setptr3 = setptr2;
+                               if (explicitprefix > 0) { *setptr3++ = "explicitprefix"; *setptr3++ = "y"; }
+
+                               *setptr3++ = NULL;
+
+                               test_begin(t_strdup_printf("prefix search %s:%s:%s",
+                                                          algos[algo],
+                                                          searches[search],
+                                                          prefixes[explicitprefix]));
+                               struct fts_tokenizer *tok;
+                               const char *error;
+
+                               fts_tokenizer_create(fts_tokenizer_generic, NULL, settings,
+                                                    &tok, &error);
+                               test_tokenizer_inputs(
+                                       tok, &input, 1,
+                                       (search!=0) && (explicitprefix!=0) && (algo==0)
+                                       ? expected_star : expected_nostar);
+
+                               fts_tokenizer_unref(&tok);
+                               test_end();
+                       }
+               }
+       }
+}
+
 int main(void)
 {
        static void (*const test_functions[])(void) = {
@@ -516,6 +576,7 @@ int main(void)
                test_fts_tokenizer_address_search,
                test_fts_tokenizer_delete_trailing_partial_char,
                test_fts_tokenizer_random,
+               test_fts_tokenizer_explicit_prefix,
                NULL
        };
        int ret;