-
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.
- Loading branch information
1 parent
5c32662
commit f066e48
Showing
7 changed files
with
64 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace PanoramicData.NCalcExtensions.Test; | ||
|
||
public class JArrayTests | ||
{ | ||
[Fact] | ||
public void JArray_CreatesJArray() | ||
{ | ||
var expression = new ExtendedExpression("jArray(jObject('a', 1, 'b', null), jObject('a', 2, 'b', 'woo'), null)"); | ||
var result = expression.Evaluate() as JArray; | ||
result.Should().BeOfType<JArray>(); | ||
result.Should().NotBeNull(); | ||
result.Should().HaveCount(3); | ||
result![0]["a"].Should().BeOfType<JValue>(); | ||
result![0]["a"].Should().BeEquivalentTo(JToken.FromObject(1)); | ||
result![0]["b"].Should().BeOfType<JValue>(); | ||
result![0]["b"].Should().BeEquivalentTo(JValue.CreateNull()); | ||
result![1]["a"].Should().BeOfType<JValue>(); | ||
result![1]["a"].Should().BeEquivalentTo(JToken.FromObject(2)); | ||
result![1]["b"].Should().BeOfType<JValue>(); | ||
result![1]["b"].Should().BeEquivalentTo(JToken.FromObject("woo")); | ||
result![2].Should().BeEquivalentTo(JValue.CreateNull()); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace PanoramicData.NCalcExtensions.Extensions; | ||
|
||
internal static class NewJArray | ||
{ | ||
internal static void Evaluate(FunctionArgs functionArgs) | ||
{ | ||
var parameterIndex = 0; | ||
|
||
// Create an empty JObject | ||
var jArray = new JArray(); | ||
while (parameterIndex < functionArgs.Parameters.Length) | ||
{ | ||
var item = functionArgs.Parameters[parameterIndex++].Evaluate(); | ||
jArray.Add(item is null ? JValue.CreateNull() : JObject.FromObject(item)); | ||
} | ||
|
||
functionArgs.Result = jArray; | ||
} | ||
} | ||
|
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