public void JmesPathProjection_Slice() { // expression foo[0:2].a JmesPathExpression expression = new JmesPathSubExpression( new JmesPathIndexExpression( new JmesPathIdentifier("foo"), new JmesPathSliceProjection(0, 2, null) ), new JmesPathIdentifier("a") ); Assert(expression, "{\"foo\": [{\"a\": 1}, {\"a\": 2}, {\"a\": 3}, {\"a\": 4}]}", "[1,2]"); // expression foo[0:2][0:1] expression = new JmesPathIndexExpression( new JmesPathIndexExpression( new JmesPathIdentifier("foo"), new JmesPathSliceProjection(0, 2, null) ), new JmesPathSliceProjection(0, 1, null) ); Assert(expression, "{\"foo\": [[1, 2, 3], [4, 5, 6]]}", "[[1],[4]]"); }
public void JmesPathEqualOperator_Evaluate() { JmesPathExpression expression = new JmesPathFilterProjection( new JmesPathEqualOperator( new JmesPathIdentifier("bar"), new JmesPathLiteral(10) ) ); Assert(expression, "[{\"bar\": 1}, {\"bar\": 10}]", "[{\"bar\":10}]"); expression = new JmesPathIndexExpression( new JmesPathIdentifier("foo"), expression ); Assert(expression, "{\"foo\": [{\"bar\": 1}, {\"bar\": 10}]}", "[{\"bar\":10}]"); expression = new JmesPathIndexExpression( new JmesPathIdentifier("foo"), new JmesPathFilterProjection( new JmesPathEqualOperator( new JmesPathIdentifier("a"), new JmesPathIdentifier("b") ) ) ); Assert(expression, "{\"foo\": [{\"a\": 1, \"b\": 2}, {\"a\": 2, \"b\": 2}]}", "[{\"a\":2,\"b\":2}]"); }
public void JmesPathSliceExpression_Compliance() { var expression = new JmesPathIndexExpression( new JmesPathIdentifier("foo"), new JmesPathSliceProjection(null, 10, null) ); Assert(expression, "{\"foo\": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],\"bar\": {\"baz\": 1}}", "[0,1,2,3,4,5,6,7,8,9]"); }
private void Assert(string identifier, int specifier, string input, string expected) { JmesPathExpression index = new JmesPathIndexExpression( new JmesPathIdentifier(identifier), new JmesPathIndex(specifier) ); Assert(index, input, expected); }
public void OnIndexExpression() { Prolog(); System.Diagnostics.Debug.Assert(expressions_.Count >= 2); var right = expressions_.Pop(); var left = expressions_.Pop(); var expression = new JmesPathIndexExpression(left, right); expressions_.Push(expression); }
public void JmesPathProjection_Compliance() { var expression = new JmesPathIndexExpression( new JmesPathSubExpression( new JmesPathSubExpression( new JmesPathIdentifier("foo"), new JmesPathHashWildcardProjection() ), new JmesPathIdentifier("bar")), new JmesPathIndex(0) ); Assert(expression, "{ \"foo\": {\"a\": {\"bar\": [0, 2]}, \"b\": {\"bar\": [1, 3]}}}", "[0,1]"); }
public void JmesPathProjection_Wildcard_List() { JmesPathExpression identifier = new JmesPathIdentifier("foo"); JmesPathProjection wildcard = new JmesPathListWildcardProjection(); JmesPathExpression expression = new JmesPathSubExpression(wildcard, identifier); Assert(expression, "[{\"foo\": 1}, {\"foo\": 2}, {\"foo\": 3}]", "[1,2,3]"); Assert(expression, "[{\"foo\": 1}, {\"foo\": 2}, {\"bar\": 3}]", "[1,2]"); identifier = new JmesPathIndex(0); wildcard = new JmesPathListWildcardProjection(); expression = new JmesPathIndexExpression(wildcard, identifier); Assert(expression, "[\"foo\", \"bar\"]", "[]"); }
public void JmesPathProjection_Others() { var expression = new JmesPathIndexExpression( new JmesPathIndexExpression( new JmesPathSubExpression(new JmesPathIndexExpression( new JmesPathIndexExpression( new JmesPathIdentifier("toto"), new JmesPathFlattenProjection()), new JmesPathFlattenProjection()), new JmesPathIdentifier("first")), new JmesPathFlattenProjection()), new JmesPathFlattenProjection() ); Assert(expression, "{ \"toto\": [{\"first\": 0}, {\"first\": 1}, {\"first\": 2}, {\"first\": 3}] }", "[0,1,2,3]"); Assert(expression, "{ \"toto\": [[{\"first\": [[0, 1], 2, [3, 4]]}, {\"first\": 5}], [{\"first\": 6}], [[{\"first\": 7}]]] }", "[0,1,2,3,4,5,6,7]"); }
public void JmesPathIndexExpression_Compliance() { var expression = new JmesPathIndexExpression( new JmesPathIndexExpression( new JmesPathIndexExpression( new JmesPathIndexExpression( new JmesPathSubExpression( new JmesPathIdentifier("foo"), new JmesPathIdentifier("bar")), new JmesPathIndex(0)), new JmesPathIndex(0)), new JmesPathIndex(0)), new JmesPathIndex(0)) ; Assert(expression, "{\"foo\": { \"bar\": [[\"one\", \"two\"], [\"three\", \"four\"]] }}", "null"); }