From a55dc1dff1892f88b3c355d0727bbf90cf7f3db1 Mon Sep 17 00:00:00 2001 From: Phil Carmody Date: Sat, 28 Apr 2018 15:33:28 +0300 Subject: [PATCH] lib-fts: test-fts-tokenizer - explicit-prefix tests 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 --- src/lib-fts/test-fts-tokenizer.c | 61 ++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/lib-fts/test-fts-tokenizer.c b/src/lib-fts/test-fts-tokenizer.c index b2f9eddd0f..09bc7560d6 100644 --- a/src/lib-fts/test-fts-tokenizer.c +++ b/src/lib-fts/test-fts-tokenizer.c @@ -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; -- 2.47.3