Skip to content

Commit

Permalink
Update LambdaParserTests.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
hzy-6 authored Jan 27, 2024
1 parent 4702aee commit f88157d
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/NReco.LambdaParser.Tests/LambdaParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,34 @@ public void EvalCachePerf() {
Console.WriteLine("10000 iterations: {0}", sw.Elapsed);
}

[Fact]
public void MultiParameterFunc()
{
var lambdaParser = new LambdaParser(new OptionsParamsInvokeMethod());

var context = getContext();
context["f"] = new Funcs();
context["sum"] = new Func<object, decimal>((p) =>
{
if (p is ICollection collection)
{
return collection.Cast<object>().Select(w =>
{
decimal.TryParse(w?.ToString(), out var value);
return value;
})?.Sum() ?? 0;
}

decimal.TryParse(p?.ToString(), out var value1);
return value1;
});

var value1 = ; //

Assert.Equal(13M,
lambdaParser.Eval("sum(1,2,3) + sum(1) + f.sum(1,2,3)", context));
}


public class TestBaseClass
{
Expand Down Expand Up @@ -295,5 +323,24 @@ public string Format(string format,params object[] args)

}


public class Funcs
{
public decimal sum(params object[] p)
{
if (p is ICollection collection)
{
return collection.Cast<object?>().Select(w =>
{
decimal.TryParse(w?.ToString(), out var value);
return value;
})?.Sum() ?? 0;
}

return 0;
}
}


}
}

0 comments on commit f88157d

Please sign in to comment.