Skip to content

Commit

Permalink
Fix whitespace issues with filters (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
deanmarcussen authored May 18, 2021
1 parent d9a2871 commit 738a796
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/YesSql.Filters.Abstractions/Nodes/OperatorNodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public override string ToNormalizedString()
=> $"({Left.ToNormalizedString()} OR {Right.ToNormalizedString()})";

public override string ToString()
=> $"{Left.ToString()} {Value} {Right.ToString()}";
=> String.IsNullOrWhiteSpace(Value) ? $"{Left.ToString()} {Right.ToString()}" : $"{Left.ToString()} {Value} {Right.ToString()}";
}

public class AndNode : OperatorNode
Expand Down
13 changes: 13 additions & 0 deletions test/YesSql.Tests/Filters/QueryEngineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,19 @@ public void ShouldGroup(string search, string normalized)
Assert.Equal(normalized, result.ToNormalizedString());
}

[Theory]
[InlineData("title:bill steve")]
public void ShouldNotIncludeExtraWhitespace(string search)
{
var parser = new QueryEngineBuilder<Article>()
.WithNamedTerm("title", b => b.ManyCondition(ArticleManyMatch(), ArticleManyNotMatch()))
.Build();

var result = parser.Parse(search);

Assert.Equal(search, result.ToString());
}

[Fact]
public void ShouldIgnoreMultipleNamedTerms()
{
Expand Down

0 comments on commit 738a796

Please sign in to comment.