query/test: add term splitting unit test

For checking issue #2365.
This commit is contained in:
Dirk-Jan C. Binnema 2022-11-20 09:28:05 +02:00
parent 26b3110b8f
commit d2a3a13242
1 changed files with 43 additions and 0 deletions

View File

@ -625,6 +625,47 @@ test_duplicate_refresh_rename()
test_duplicate_refresh_real(true/*rename*/);
}
static void
test_term_split()
{
g_test_bug("2365");
// Note the fancy quote in "foos bar"
const TestMap test_msgs = {{
"inbox/new/msg",
{ R"(Message-Id: <abcde@foo.bar>
From: "Foo Example" <bar@example.com>
Date: Wed, 26 Oct 2022 11:01:54 -0700
To: example@example.com
Subject: foos bar
Boo!
)"},
}};
TempDir tdir;
auto store{make_test_store(tdir.path(), test_msgs, {})};
/* true: match; false: no match */
const auto cases = std::array<std::pair<const char*, bool>, 6>{{
{"subject:foo's", true},
{"subject:foo*", true},
{"subject:/foo/", true},
{"subject:/foos/", true}, /* <-- breaks before PR #2365 */
{"subject:/foo.*bar/", true}, /* <-- breaks before PR #2365 */
{"subject:/foos bar/", false}, /* <-- no matching yet */
}};
for (auto&& test: cases) {
g_debug("query: %s", test.first);
auto qr = store.run_query(test.first);
assert_valid_result(qr);
if (test.second)
g_assert_cmpuint(qr->size(), ==, 1);
else
g_assert_true(qr->empty());
}
}
int
main(int argc, char* argv[])
@ -646,6 +687,8 @@ main(int argc, char* argv[])
test_duplicate_refresh);
g_test_add_func("/store/query/duplicate-refresh-rename",
test_duplicate_refresh_rename);
g_test_add_func("/store/query/term-split",
test_term_split);
return g_test_run();
}