-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Function #transform: handles multiple transforms #267
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1a84d6c
Merge pull request #28 from WorkMaze/master
Courela e0b76ac
Replace operation using ISelectableToken; make static every bulk oper…
Courela c8cc44c
Update test nuget packages: nunit, NUnit3TestAdapter and Microsoft.NE…
Courela 6c794fb
TargetFramework; change UnitTestForExternalAssemblyBug project to use…
Courela 2a81b11
Fix build of UnitTestForExternalAssemblyBug project
Courela 9c79c8c
Multiple transformations in array
Courela bf7d09f
Multiple transforms inside loop
Courela c5558db
Create MultipleTransformations unit test class; Readme unit test for …
Courela 6a0bfcb
Update README.md
Courela 56c78d6
Revert "Replace operation using ISelectableToken; make static every b…
Courela f706630
Merge branch 'WorkMaze:master' into master
Courela 0fe38b3
Merge branch 'master' into feature/multiple_transforms
Courela bc15ccc
Typo in README.md
Courela File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,74 @@ | ||
using NUnit.Framework; | ||
|
||
namespace JUST.UnitTests | ||
{ | ||
[TestFixture] | ||
public class MultipleTransformations | ||
{ | ||
[Test] | ||
public void MultipleTransformsScalarResult() | ||
{ | ||
const string input = "{\"d\": [ \"one\", \"two\", \"three\" ], \"values\": [ \"z\", \"c\", \"n\" ]}"; | ||
const string transformer = | ||
"{ \"result\": " + | ||
"{ \"#transform($)\": [ " + | ||
"{ \"condition\": { \"#loop($.values)\": { \"test\": \"#ifcondition(#stringcontains(#valueof($.d[0]),#currentvalue()),True,yes,no)\" } } }, " + | ||
"{ \"intermediate_transform\": \"#valueof($.condition)\" }," + | ||
"\"#exists($.intermediate_transform[?(@.test=='yes')])\" ] } }"; | ||
|
||
var result = new JsonTransformer().Transform(transformer, input); | ||
|
||
Assert.AreEqual("{\"result\":true}", result); | ||
} | ||
|
||
[Test] | ||
public void MultipleTransformsObjectResult() | ||
{ | ||
const string input = "{\"d\": [ \"one\", \"two\", \"three\" ], \"values\": [ \"z\", \"c\", \"n\" ]}"; | ||
const string transformer = | ||
"{ \"object\": " + | ||
"{ \"#transform($)\": [ " + | ||
"{ \"condition\": { \"#loop($.values)\": { \"test\": \"#ifcondition(#stringcontains(#valueof($.d[0]),#currentvalue()),True,yes,no)\" } } }, " + | ||
"{ \"intermediate_transform\": \"#valueof($.condition)\" }," + | ||
"{ \"result\": \"#exists($.intermediate_transform[?(@.test=='yes')])\" } ] } }"; | ||
|
||
var result = new JsonTransformer().Transform(transformer, input); | ||
|
||
Assert.AreEqual("{\"object\":{\"result\":true}}", result); | ||
} | ||
|
||
[Test] | ||
public void MultipleTransformsOverSelectedToken() | ||
{ | ||
const string input = "{ \"select\": {\"d\": [ \"one\", \"two\", \"three\" ], \"values\": [ \"z\", \"c\", \"n\" ]} }"; | ||
const string transformer = | ||
"{ \"select_token\": " + | ||
"{ \"#transform($.select)\": [ " + | ||
"{ \"condition\": { \"#loop($.values)\": { \"test\": \"#ifcondition(#stringcontains(#valueof($.d[0]),#currentvalue()),True,yes,no)\" } } }, " + | ||
"{ \"intermediate_transform\": \"#valueof($.condition)\" }," + | ||
"{ \"result\": \"#exists($.intermediate_transform[?(@.test=='yes')])\" } ] } }"; | ||
|
||
var result = new JsonTransformer().Transform(transformer, input); | ||
|
||
Assert.AreEqual("{\"select_token\":{\"result\":true}}", result); | ||
} | ||
|
||
[Test] | ||
public void MultipleTransformsWithinLoop() | ||
{ | ||
const string input = "{ \"select\": [{ \"d\": [ \"one\", \"two\", \"three\" ], \"values\": [ \"z\", \"c\", \"n\" ] }, { \"d\": [ \"four\", \"five\", \"six\" ], \"values\": [ \"z\", \"c\", \"n\" ] }] }"; | ||
const string transformer = | ||
"{ \"loop\": {" + | ||
" \"#loop($.select,selectLoop)\": { " + | ||
"\"#transform($)\": [ " + | ||
"{ \"condition\": { \"#loop($.values)\": { \"test\": \"#ifcondition(#stringcontains(#currentvalueatpath($.d[0],selectLoop),#currentvalue()),True,yes,no)\" } } }, " + | ||
"{ \"intermediate_transform\": \"#valueof($.condition)\" }," + | ||
"{ \"result\": \"#exists($.intermediate_transform[?(@.test=='yes')])\" } ] " + | ||
" } } }"; | ||
|
||
var result = new JsonTransformer().Transform(transformer, input); | ||
|
||
Assert.AreEqual("{\"loop\":[{\"result\":true},{\"result\":false}]}", result); | ||
} | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider using raw string literals (e.g. "triple quotes") to make these JSONs more readable.
See: https://devblogs.microsoft.com/dotnet/csharp-11-preview-updates/
(Of course, you'll need to bump the language version to 11.)