From f55a3ca00879d4b975f01f27458fe3dc47013943 Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Fri, 2 Apr 2021 11:27:16 -0400 Subject: [PATCH] Search engine bug fix and unit tests --- LibationLauncher/LibationLauncher.csproj | 2 +- LibationSearchEngine/UNTESTED/LuceneRegex.cs | 18 ++++---- .../SearchEngineTests.cs | 45 +++++++++++++++++-- 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/LibationLauncher/LibationLauncher.csproj b/LibationLauncher/LibationLauncher.csproj index c04fbbdd..2c534211 100644 --- a/LibationLauncher/LibationLauncher.csproj +++ b/LibationLauncher/LibationLauncher.csproj @@ -13,7 +13,7 @@ win-x64 - 4.2.2.1 + 4.2.3.1 diff --git a/LibationSearchEngine/UNTESTED/LuceneRegex.cs b/LibationSearchEngine/UNTESTED/LuceneRegex.cs index 326be325..cc055098 100644 --- a/LibationSearchEngine/UNTESTED/LuceneRegex.cs +++ b/LibationSearchEngine/UNTESTED/LuceneRegex.cs @@ -61,11 +61,14 @@ namespace LibationSearchEngine /// private static string boolPattern_parameterized { get; } = @" +### IMPORTANT: 'ignore whitespace' is only partially honored in character sets +### - new lines are ok +### - ANY leading whitespace is treated like actual matching spaces :( + + ### can't begin with colon. incorrect syntax + ### can't begin with open bracket: this signals the start of a tag (? boolRegexDic { get; } = new Dictionary(); diff --git a/_Tests/LibationSearchEngine.Tests/SearchEngineTests.cs b/_Tests/LibationSearchEngine.Tests/SearchEngineTests.cs index e7fae71c..685c83e9 100644 --- a/_Tests/LibationSearchEngine.Tests/SearchEngineTests.cs +++ b/_Tests/LibationSearchEngine.Tests/SearchEngineTests.cs @@ -24,15 +24,54 @@ namespace SearchEngineTests public class FormatSearchQuery { [TestMethod] - [DataRow(null, SearchEngine.ALL_QUERY)] - [DataRow("", SearchEngine.ALL_QUERY)] - [DataRow(" ", SearchEngine.ALL_QUERY)] + // null, empty, whitespace -- *:* + [DataRow(null, "*:*")] + [DataRow("", "*:*")] + [DataRow(" ", "*:*")] + + // tag surrounded by spaces + [DataRow("[foo]", "tags:foo")] + [DataRow(" [foo]", " tags:foo")] + [DataRow("[foo] ", "tags:foo ")] + [DataRow(" [foo] ", " tags:foo ")] + [DataRow("-[foo]", "-tags:foo")] + [DataRow(" -[foo]", " -tags:foo")] + [DataRow("-[foo] ", "-tags:foo ")] + [DataRow(" -[foo] ", " -tags:foo ")] + + // tag case irrelevant + [DataRow("[FoO]", "tags:FoO")] + + // bool keyword surrounded by spaces [DataRow("israted", "israted:True")] + [DataRow(" israted", " israted:True")] + [DataRow("israted ", "israted:True ")] + [DataRow(" israted ", " israted:True ")] + [DataRow("-israted", "-israted:True")] + [DataRow(" -israted", " -israted:True")] + [DataRow("-israted ", "-israted:True ")] + [DataRow(" -israted ", " -israted:True ")] + + // bool keyword. Append :True + [DataRow("israted", "israted:True")] + + // bool keyword with [:bool]. Do not add :True [DataRow("israted:True", "israted:True")] [DataRow("isRated:false", "israted:false")] + + // tag which happens to be a bool keyword >> parse as tag [DataRow("[israted]", "tags:israted")] + + // numbers with "to". TO all caps, numbers [8.2] format [DataRow("1 to 10", "00000001.00 TO 00000010.00")] [DataRow("19990101 to 20001231", "19990101.00 TO 20001231.00")] + + // field to lowercase + [DataRow("Author:Doyle", "author:Doyle")] + // bool field to lowercase + [DataRow("IsRated", "israted:True")] + [DataRow("-isRATED", "-israted:True")] + public void FormattingTest(string input, string output) => SearchEngine.FormatSearchQuery(input).Should().Be(output); }