Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nikoraes committed Jul 11, 2024
1 parent 89511e5 commit d91f66a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions JexlNet.ExtendedGrammar/ExtendedGrammar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ public ExtendedGrammar()
AddFunction("$number", ToNumber);
AddTransform("number", ToNumber);
AddTransform("toNumber", ToNumber);
AddFunction("parseFloat", ToNumber);
AddFunction("$parseFloat", ToNumber);
AddTransform("float", ToNumber);
AddTransform("toFloat", ToNumber);
// AbsoluteValue
AddFunction("abs", AbsoluteValue);
AddFunction("$abs", AbsoluteValue);
Expand Down Expand Up @@ -151,6 +155,7 @@ public ExtendedGrammar()
AddTransform("parseInteger", ParseInteger);
AddTransform("parseInt", ParseInteger);
AddTransform("toInt", ParseInteger);
AddTransform("integer", ParseInteger);
// Sum
AddFunction("sum", Sum);
AddFunction("$sum", Sum);
Expand Down
4 changes: 3 additions & 1 deletion JexlNet.Test/ExtendedGrammar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public void ConvertBase64(string expression, string expected)
[InlineData("3|power(2)", 9)]
[InlineData("3|power", 9)]
[InlineData("9|sqrt", 3)]
[InlineData("random() < 1 ? 1 : 0", 1)]
public void Number(string expression, decimal expected)
{
var jexl = new Jexl(new ExtendedGrammar());
Expand Down Expand Up @@ -233,7 +234,8 @@ public void Boolean(string expression, bool? expected)
[InlineData("['tek', 'baz', 'bar', 'foo']|reverse")]
[InlineData("['tek', 'baz', 'bar', 'foo', 'foo']|reverse|distinct")]
[InlineData("{'foo':0, bar:1, 'baz':2, tek:3}|keys")] // doesn't work in TS
[InlineData("{foo:0, bar:1, baz:2, tek:3}|keys")] // doesn't work in TS
// [InlineData("{['foo']:0, bar:1, ['baz']:2, tek:3}|keys")] // doesn't work
[InlineData("{foo:0, bar:1, baz:2, tek:3}|keys")]
[InlineData("{a:'foo', b:'bar', c:'baz', d:'tek'}|values")]
[InlineData("[{name:'foo'}, {name:'bar'}, {name:'baz'}, {name:'tek'}]|mapField('name')")]
[InlineData("[{name:'tek',age:32}, {name:'bar',age:34}, {name:'baz',age:33}, {name:'foo',age:35}]|sort('age',true)|mapField('name')")]
Expand Down

0 comments on commit d91f66a

Please sign in to comment.