Skip to content

Commit

Permalink
fix: filtering with parenthesis and case-insensitive operator #171
Browse files Browse the repository at this point in the history
  • Loading branch information
alirezanet committed Oct 31, 2024
1 parent e8fc334 commit e1feb5d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/Gridify/Syntax/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ private ValueExpressionSyntax ParseValueExpression()
{
// field=
if (Current.Kind != SyntaxKind.ValueToken)
return new ValueExpressionSyntax(new SyntaxToken(), false, true);
{
if (Current.Kind != SyntaxKind.CaseInsensitive) return new ValueExpressionSyntax(new SyntaxToken(), false, true);
NextToken(); // field=/i
return new ValueExpressionSyntax(new SyntaxToken(), true, true);
}


var valueToken = Match(SyntaxKind.ValueToken);
var isCaseInsensitive = TryMatch(SyntaxKind.CaseInsensitive, out _);
Expand Down
15 changes: 13 additions & 2 deletions test/Gridify.Tests/IssueTests/Issue171Tests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Xunit;

Expand All @@ -7,7 +7,18 @@ namespace Gridify.Tests.IssueTests;
public class Issue171Tests
{

private readonly List<TestClass> _fakeRepository = [..GridifyExtensionsShould.GetSampleData(), new TestClass(4444,"/i",null)];
private readonly List<TestClass> _fakeRepository = [.. GridifyExtensionsShould.GetSampleData(), new TestClass(4444, "/i", null)];

[Fact]
public void ApplyFiltering_CaseInsensitiveEmptyFieldsWithParenthesis_ShouldFilter()
{
var actual = _fakeRepository.AsQueryable().ApplyFiltering("(tag=/i)").ToList();
var expected = _fakeRepository.Where(q => string.IsNullOrEmpty(q.Tag)).ToList();

Assert.Equal(expected.Count, actual.Count);
Assert.Equal(expected, actual);
Assert.True(actual.Any());
}

[Fact]
public void ApplyFiltering_CaseInsensitiveEmptyFields_ShouldFilter()
Expand Down

0 comments on commit e1feb5d

Please sign in to comment.