Skip to content

Commit

Permalink
use standard operators for greaterThan and lessThan
Browse files Browse the repository at this point in the history
  • Loading branch information
alirezanet committed Jul 28, 2021
1 parent d138dcb commit 677ae06
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ but for example, if you need to just filter your data without paging or sorting
| --------------------- | -------- | --------------------------------------------------------- |
| Equal | `==` | `"FieldName ==Value"` |
| NotEqual | `!=` | `"FieldName !=Value"` |
| LessThan | `<<` | `"FieldName <<Value"` |
| GreaterThan | `>>` | `"FieldName >>Value"` |
| LessThan | `<` | `"FieldName < Value"` |
| GreaterThan | `>` | `"FieldName > Value"` |
| GreaterThanOrEqual | `>=` | `"FieldName >=Value"` |
| LessThanOrEqual | `<=` | `"FieldName <=Value"` |
| Contains - Like | `=*` | `"FieldName =*Value"` |
| NotContains - NotLike | `!*` | `"FieldName !*Value"` |
| AND - && | `,` | `"FirstName ==Value, LastName ==Value2"` |
| OR - &#124;&#124; | <code>&#124;</code> | <code>"FirstName==Value&#124;LastName==Value2"</code>
| Parenthesis | `()` | <code>"(FirstName=*Jo,Age<<30)&#124;(FirstName!=Hn,Age>>30)"</code> |
| Parenthesis | `()` | <code>"(FirstName=*Jo,Age<30)&#124;(FirstName!=Hn,Age>30)"</code> |

we can easily create complex queries using Parenthesis`()` with AND (`,`) + OR (`|`) operators.

Expand Down
2 changes: 1 addition & 1 deletion src/Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void NativeLinQ()
public void Gridify()
{
Ds .ApplyFiltering("Name=*a").Consume(Consumer);
Ds .ApplyFiltering("Id>>5").Consume(Consumer);
Ds .ApplyFiltering("Id>5").Consume(Consumer);
Ds .ApplyFiltering("Name==Ali").Consume(Consumer);
}

Expand Down
14 changes: 6 additions & 8 deletions src/Core/SyntaxTree/Lexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,12 @@ public SyntaxToken NextToken()
return new SyntaxToken(SyntaxKind.NotEqual, _position += 2, "!=");
case '!' when peek == '*':
return new SyntaxToken(SyntaxKind.NotLike, _position += 2, "!*");
case '<' when peek == '<':
return new SyntaxToken(SyntaxKind.LessThan, _position += 2, "<<");
case '>' when peek == '>':
return new SyntaxToken(SyntaxKind.GreaterThan, _position += 2, ">>");
case '<' when peek == '=':
return new SyntaxToken(SyntaxKind.LessOrEqualThan, _position += 2, "<=");
case '>' when peek == '=':
return new SyntaxToken(SyntaxKind.GreaterOrEqualThan, _position += 2, ">=");
case '<':
return peek == '=' ? new SyntaxToken(SyntaxKind.LessOrEqualThan, _position += 2, "<=") :
new SyntaxToken(SyntaxKind.LessThan, _position++, "<");
case '>':
return peek == '=' ? new SyntaxToken(SyntaxKind.GreaterOrEqualThan, _position += 2, ">=") :
new SyntaxToken(SyntaxKind.GreaterThan, _position++, ">");
}

if (char.IsLetter(Current) && !_waitingForValue)
Expand Down
8 changes: 4 additions & 4 deletions test/Core.Tests/GridifyExtensionsShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ public void ApplyFiltering_CustomConvertor()
public void ApplyFiltering_MultipleCondition()
{
var actual = _fakeRepository.AsQueryable()
.ApplyFiltering("name==Jack|name==Rose|id>>7")
.ApplyFiltering("name==Jack|name==Rose|id>=7")
.ToList();
var expected = _fakeRepository.Where(q => q.Name == "Jack" || q.Name == "Rose" || q.Id > 7).ToList();
var expected = _fakeRepository.Where(q => q.Name == "Jack" || q.Name == "Rose" || q.Id >= 7).ToList();
Assert.Equal(expected.Count, actual.Count);
Assert.Equal(expected, actual);
Assert.True(actual.Any());
Expand All @@ -286,7 +286,7 @@ public void ApplyFiltering_MultipleCondition()
public void ApplyFiltering_ComplexWithParenthesis()
{
var actual = _fakeRepository.AsQueryable()
.ApplyFiltering("(name=*J|name=*S),(Id<<5)")
.ApplyFiltering("(name=*J|name=*S),(Id<5)")
.ToList();
var expected = _fakeRepository.Where(q => (q.Name.Contains("J") || q.Name.Contains("S")) && q.Id < 5).ToList();
Assert.Equal(expected.Count, actual.Count);
Expand All @@ -298,7 +298,7 @@ public void ApplyFiltering_ComplexWithParenthesis()
public void ApplyFiltering_NestedParenthesisWithSpace()
{
// we shouldn't add spaces for values
var gq = new GridifyQuery {Filter = " ( name =*J| ( name =*S , Id <<5 ) )"};
var gq = new GridifyQuery {Filter = " ( name =*J| ( name =*S , Id <5 ) )"};
var actual = _fakeRepository.AsQueryable()
.ApplyFiltering(gq)
.ToList();
Expand Down

0 comments on commit 677ae06

Please sign in to comment.