Skip to content

Commit e8a3d8e

Browse files
alex-daviesAlex Davies
and
Alex Davies
authored
26 Use logical and/or operations (#27)
and/or operations now use logical rather than bitwise logic Co-authored-by: Alex Davies <[email protected]>
1 parent 229e016 commit e8a3d8e

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/StringToExpression/Languages/ODataFilterLanguage.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,12 @@ protected virtual IEnumerable<GrammerDefinition> LogicalOperatorDefinitions()
297297
name:"AND",
298298
regex: @"\b(and)\b",
299299
orderOfPrecedence:17,
300-
expressionBuilder: (left,right) => Expression.And(left, right)),
300+
expressionBuilder: (left,right) => Expression.AndAlso(left, right)),
301301
new BinaryOperatorDefinition(
302302
name:"OR",
303303
regex: @"\b(or)\b",
304304
orderOfPrecedence:18,
305-
expressionBuilder: (left,right) => Expression.Or(left, right)),
305+
expressionBuilder: (left,right) => Expression.OrElse(left, right)),
306306

307307
new UnaryOperatorDefinition(
308308
name:"NOT",

tests/StringToExpression.Test/Languages/ODataFilter/ODataTests.cs

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using StringToExpression.LanguageDefinitions;
1+
using StringToExpression.Exceptions;
2+
using StringToExpression.LanguageDefinitions;
3+
using StringToExpression.Test.Fixtures;
24
using System;
35
using System.Collections.Generic;
46
using System.Linq;
@@ -70,5 +72,17 @@ public void When_functions_should_evaluate(string query, bool expectedMatch)
7072
Assert.Equal(expectedMatch, compiled(null));
7173

7274
}
75+
76+
[Theory]
77+
[InlineData("(6 and 5) eq 4")]
78+
[InlineData("(6 or 5) eq 7")]
79+
[InlineData("'leet' eq 1337")]
80+
public void When_invalid_operations_should_throw(string query)
81+
{
82+
Assert.Throws<OperationInvalidException>(() =>
83+
{
84+
new ODataFilterLanguage().Parse<LinqToQuerystringTestDataFixture.ConcreteClass>(query);
85+
});
86+
}
7387
}
7488
}

0 commit comments

Comments
 (0)