-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v2.4.0 - added support for delegate function bindings, see #15
- Loading branch information
1 parent
84f8008
commit 042266d
Showing
8 changed files
with
4,050 additions
and
3,749 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7,652 changes: 3,932 additions & 3,720 deletions
7,652
src/Jsonata.Net.Native.TestSuite/TestReport/Jsonata.Net.Native.TestSuite.xml
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using Jsonata.Net.Native; | ||
using Jsonata.Net.Native.Json; | ||
using NUnit.Framework; | ||
|
||
namespace Jsonata.Net.Native.Tests | ||
{ | ||
public sealed class FuncBindingTests | ||
{ | ||
[Test] | ||
public void ViaMethodInfo() | ||
{ | ||
EvaluationEnvironment env = new EvaluationEnvironment(); | ||
env.BindFunction(typeof(FuncBindingTests).GetMethod(nameof(Mult3))!); | ||
JsonataQuery query = new JsonataQuery("( $Mult3(1, 2, 3); )"); | ||
JToken result = query.Eval(JValue.CreateNull(), env); | ||
Assert.AreEqual(JTokenType.Integer, result.Type); | ||
Assert.AreEqual(6, (int)result); | ||
} | ||
|
||
[Test] | ||
public void ViaFuncStatic() | ||
{ | ||
EvaluationEnvironment env = new EvaluationEnvironment(); | ||
Func<int, int, int, int> func = Mult3; | ||
env.BindFunction(nameof(Mult3), func); | ||
JsonataQuery query = new JsonataQuery("( $Mult3(1, 2, 3); )"); | ||
JToken result = query.Eval(JValue.CreateNull(), env); | ||
Assert.AreEqual(JTokenType.Integer, result.Type); | ||
Assert.AreEqual(6, (int)result); | ||
} | ||
|
||
[Test] | ||
public void ViaInplaceStatic() | ||
{ | ||
EvaluationEnvironment env = new EvaluationEnvironment(); | ||
env.BindFunction(nameof(Mult3), Mult3); | ||
JsonataQuery query = new JsonataQuery("( $Mult3(1, 2, 3); )"); | ||
JToken result = query.Eval(JValue.CreateNull(), env); | ||
Assert.AreEqual(JTokenType.Integer, result.Type); | ||
Assert.AreEqual(6, (int)result); | ||
} | ||
|
||
[Test] | ||
public void ViaFuncLambda() | ||
{ | ||
EvaluationEnvironment env = new EvaluationEnvironment(); | ||
Func<int, int, int, int> func = (int a, int b, int c) => a * b * c; | ||
env.BindFunction(nameof(Mult3), func); | ||
JsonataQuery query = new JsonataQuery("( $Mult3(1, 2, 3); )"); | ||
JToken result = query.Eval(JValue.CreateNull(), env); | ||
Assert.AreEqual(JTokenType.Integer, result.Type); | ||
Assert.AreEqual(6, (int)result); | ||
} | ||
|
||
[Test] | ||
public void ViaInplaceLambda() | ||
{ | ||
EvaluationEnvironment env = new EvaluationEnvironment(); | ||
env.BindFunction(nameof(Mult3), (int a, int b, int c) => a * b * c); | ||
JsonataQuery query = new JsonataQuery("( $Mult3(1, 2, 3); )"); | ||
JToken result = query.Eval(JValue.CreateNull(), env); | ||
Assert.AreEqual(JTokenType.Integer, result.Type); | ||
Assert.AreEqual(6, (int)result); | ||
} | ||
|
||
public static int Mult3(int a, int b, int c) | ||
{ | ||
return a * b * c; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters