-
Notifications
You must be signed in to change notification settings - Fork 38
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
Showing
2 changed files
with
44 additions
and
1 deletion.
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
42 changes: 42 additions & 0 deletions
42
jackson-jq/src/test/java/net/thisptr/jackson/jq/internal/NullLHSFunctionTest.java
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,42 @@ | ||
package net.thisptr.jackson.jq.internal; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import javax.management.ObjectName; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.IntNode; | ||
import com.fasterxml.jackson.databind.node.NullNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
|
||
import net.thisptr.jackson.jq.BuiltinFunctionLoader; | ||
import net.thisptr.jackson.jq.JsonQuery; | ||
import net.thisptr.jackson.jq.Scope; | ||
import net.thisptr.jackson.jq.Versions; | ||
import net.thisptr.jackson.jq.exception.JsonQueryException; | ||
import net.thisptr.jackson.jq.internal.javacc.ExpressionParser; | ||
|
||
public class NullLHSFunctionTest { | ||
@Test | ||
public void test() throws IOException { | ||
final ObjectMapper mapper = new ObjectMapper(); | ||
final Scope scope = Scope.newEmptyScope(); | ||
BuiltinFunctionLoader.getInstance().loadFunctions(Versions.JQ_1_5, scope); | ||
ObjectNode input = mapper.createObjectNode().set("input", mapper.createArrayNode().add(1)); | ||
assertEquals(Arrays.asList(input.deepCopy().set("output", mapper.createArrayNode().add(2))), eval(scope, ".output+=[.input[0]+1]", input)); | ||
} | ||
|
||
public static List<JsonNode> eval(final Scope scope, final String q, final JsonNode in) throws JsonQueryException { | ||
final List<JsonNode> out = new ArrayList<>(); | ||
JsonQuery.compile(q, Versions.JQ_1_5).apply(scope, in, out::add); | ||
return out; | ||
} | ||
} |