-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#76 Fixed default operator not being applied to right hand side of gr…
…oup node in GenerateQueryVisitor (#77) Co-authored-by: Richard Cockerill <5318261+richardcockerill@users.noreply.github.com>
- Loading branch information
1 parent
56e348b
commit 3df3d55
Showing
2 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
tests/Foundatio.Parsers.LuceneQueries.Tests/GenerateQueryVisitorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using Foundatio.Parsers.LuceneQueries.Visitors; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using System.Threading.Tasks; | ||
using Foundatio.Parsers.LuceneQueries.Nodes; | ||
using Foundatio.Xunit; | ||
using Pegasus.Common.Tracing; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Foundatio.Parsers.LuceneQueries.Tests; | ||
|
||
public class GenerateQueryVisitorTests : TestWithLoggingBase { | ||
public GenerateQueryVisitorTests(ITestOutputHelper output) : base(output) { | ||
Log.MinimumLevel = LogLevel.Trace; | ||
} | ||
|
||
[Theory] | ||
[InlineData("value1 value2", GroupOperator.Default, "value1 value2")] | ||
[InlineData("value1 value2", GroupOperator.And, "value1 AND value2")] | ||
[InlineData("value1 value2", GroupOperator.Or, "value1 OR value2")] | ||
[InlineData("value1 value2 value3", GroupOperator.Default, "value1 value2 value3")] | ||
[InlineData("value1 value2 value3", GroupOperator.And, "value1 AND value2 AND value3")] | ||
[InlineData("value1 value2 value3", GroupOperator.Or, "value1 OR value2 OR value3")] | ||
[InlineData("value1 value2 value3 value4", GroupOperator.And, "value1 AND value2 AND value3 AND value4")] | ||
[InlineData("(value1 value2) OR (value3 value4)", GroupOperator.And, "(value1 AND value2) OR (value3 AND value4)")] | ||
public Task DefaultOperatorApplied(string query, GroupOperator groupOperator, string expected) { | ||
return GenerateQuery(query, groupOperator, expected); | ||
} | ||
|
||
private async Task GenerateQuery(string query, GroupOperator defaultOperator, string expected) { | ||
#if ENABLE_TRACING | ||
var tracer = new LoggingTracer(_logger, reportPerformance: true); | ||
#else | ||
var tracer = NullTracer.Instance; | ||
#endif | ||
var parser = new LuceneQueryParser { | ||
Tracer = tracer | ||
}; | ||
|
||
IQueryNode parsedQuery = await parser.ParseAsync(query); | ||
|
||
var context = new QueryVisitorContext { DefaultOperator = defaultOperator }; | ||
string result = GenerateQueryVisitor.Run(parsedQuery, context); | ||
string nodes = await DebugQueryVisitor.RunAsync(parsedQuery); | ||
_logger.LogInformation(nodes); | ||
Assert.Equal(expected, result); | ||
} | ||
} |