Ejemplo n.º 1
0
        public void ObjectNameLengthExpression_LastItem()
        {
            var json = new JsonObject
            {
                { "name", new JsonArray {
                      1, 2, 3
                  } },
                { "name2", new JsonArray {
                      1, 2, 3
                  } },
                { "test", new JsonArray {
                      1, 2
                  } },
            };
            var path     = JsonPathWith.Array(jv => JsonPathRoot.Name("test").Length());
            var expected = new JsonArray {
                new JsonArray {
                    1, 2
                }
            };

            var actual = path.Evaluate(json);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 2
0
        public void ArrayIndexExpression_IndexOfObject()
        {
            var obj = new JsonObject {
                { "key", "value" }
            };

            Run("$[?(@.indexOf({\"key\":\"value\"}) == 4)]", JsonPathWith.Array(jv => jv.IndexOf(obj) == 4));
        }
Ejemplo n.º 3
0
        public void ArrayIndexExpression_IndexOfArray()
        {
            var arr = new JsonArray {
                1, 2, 3
            };

            Run("$[?(@.indexOf([1,2,3]) == 4)]", JsonPathWith.Array(jv => jv.IndexOf(arr) == 4));
        }
        // This won't work the same.  Parsing generates a ValueExpression, but the only way to
        // construct the path is to pass the field, which generates a FieldExpression. The parsed
        // path would be different in structure but should still represent the same thing.
        // We have to test by evaluation.
        public void IndexOfArray()
        {
            var arr = new JsonArray {
                1, 2, 3
            };

            CompareEval(JsonPathWith.Array(jv => jv.IndexOf(arr) == 6), "$[?(@.indexOf([1,2,3]) == 6)]");
        }
Ejemplo n.º 5
0
        public void WildcardArray()
        {
            var text     = "$[*]";
            var expected = JsonPathWith.Array();

            var actual = JsonPath.Parse(text);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 6
0
        public void MultiIndexedArray()
        {
            var text     = "$[1,3]";
            var expected = JsonPathWith.Array(1, 3);

            var actual = JsonPath.Parse(text);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 7
0
        public void MultiSlicedArray()
        {
            var text     = "$[1:5,7:11:2]";
            var expected = JsonPathWith.Array(new Slice(1, 5), new Slice(7, 11, 2));

            var actual = JsonPath.Parse(text);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 8
0
        public void SlicedIndexedArray()
        {
            var text     = "$[1:5,7]";
            var expected = JsonPathWith.Array(new Slice(1, 5), 7);

            var actual = JsonPath.Parse(text);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 9
0
        public void SteppedSlicedArray()
        {
            var text     = "$[1:5:2]";
            var expected = JsonPathWith.Array(new Slice(1, 5, 2));

            var actual = JsonPath.Parse(text);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 10
0
        public void SingleIndexedArray()
        {
            var text     = "$[1]";
            var expected = JsonPathWith.Array(1);

            var actual = JsonPath.Parse(text);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 11
0
        // This won't work the same.  Parsing generates a ValueExpression, but the only way to
        // construct the path is to pass the field, which generates a FieldExpression. The parsed
        // path would be different in structure but should still represent the same thing.
        // We have to test by evaluation.
        public void IndexOfObject()
        {
            var obj = new JsonObject
            {
                ["bool"]   = false,
                ["int"]    = 20,
                ["string"] = "value",
            };

            CompareEval(JsonPathWith.Array(jv => jv.IndexOf(obj) == 1), "$[?(@.indexOf({\"key\":\"value\"}) == 1)]");
        }
Ejemplo n.º 12
0
        public void ArrayLengthExpression_LastItem()
        {
            var json = new JsonArray {
                1, 2, 3
            };
            var path     = JsonPathWith.Array(jv => jv.Length() - 1);
            var expected = new JsonArray {
                3
            };

            var actual = path.Evaluate(json);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 13
0
 public void UnaryNegate_WithMultiply()
 {
     Run(JsonPathWith.Array(jv => jv.Length() * -3 > 1), "$[?(@.length * -3 > 1)]");
 }
Ejemplo n.º 14
0
 public void UnaryNegate_WithSubtract()
 {
     Run(JsonPathWith.Array(jv => jv.Length() - -3 > 1), "$[?(@.length - -3 > 1)]");
 }
Ejemplo n.º 15
0
 // This won't work the same.  Parsing generates an IndexOfExpression with a distinct parameter,
 // but when constructing the path, the parameter goes through several castings generating a
 // parameter expression. The parsed path would be different in structure but should still
 // represent the same thing.  We have to test by evaluation.
 public void IndexOfString()
 {
     CompareEval(JsonPathWith.Array(jv => jv.IndexOf("string") == 2), "$[?(@.indexOf(\"hello\") == 2)]");
 }
Ejemplo n.º 16
0
 // This won't work the same.  Parsing generates an IndexOfExpression with a distinct parameter,
 // but when constructing the path, the parameter goes through several castings generating a
 // parameter expression. The parsed path would be different in structure but should still
 // represent the same thing.  We have to test by evaluation.
 public void IndexOfBoolean()
 {
     CompareEval(JsonPathWith.Array(jv => jv.IndexOf(true) == 3), "$[?(@.indexOf(true) == 3)]");
 }
Ejemplo n.º 17
0
 // This won't work the same.  Parsing generates an IndexOfExpression with a distinct parameter,
 // but when constructing the path, the parameter goes through several castings generating a
 // parameter expression. The parsed path would be different in structure but should still
 // represent the same thing.  We have to test by evaluation.
 public void IndexOfNumber()
 {
     CompareEval(JsonPathWith.Array(jv => jv.IndexOf(5) == 4), "$[?(@.indexOf(5) == 4)]");
 }
Ejemplo n.º 18
0
 public void Or()
 {
     Run(JsonPathWith.Array(jv => jv.HasProperty("test") || jv.Name("name") == 5), "$[?(@.test || @.name == 5)]");
 }
Ejemplo n.º 19
0
 public void DoesNotHaveProperty()
 {
     Run(JsonPathWith.Array(jv => !jv.HasProperty("test")), "$[?([email protected])]");
 }
Ejemplo n.º 20
0
 public void ArrayIndexEqualsValue()
 {
     Run(JsonPathWith.Array(jv => jv.ArrayIndex(1) == 5), "$[?(@[1] == 5)]");
 }
Ejemplo n.º 21
0
 public void PropertyGreaterThanEqualToValue()
 {
     Run(JsonPathWith.Array(jv => jv.Name("test") >= 5), "$[?(@.test >= 5)]");
 }
Ejemplo n.º 22
0
 public void PropertyEqualsValue()
 {
     Run(JsonPathWith.Array(jv => jv.Name("test") == 5), "$[?(@.test == 5)]");
 }
Ejemplo n.º 23
0
 public void PropertyNotEqualToValue()
 {
     Run(JsonPathWith.Array(jv => jv.Name("test") != 5), "$[?(@.test != 5)]");
 }
Ejemplo n.º 24
0
 public void UnaryNegate_WithDivide()
 {
     Run(JsonPathWith.Array(jv => jv.Length() / -3 > 1), "$[?(@.length / -3 > 1)]");
 }
Ejemplo n.º 25
0
 public void PropertyLessThanEqualToValue()
 {
     Run(JsonPathWith.Array(jv => jv.Name("test") <= 5), "$[?(@.test <= 5)]");
 }
Ejemplo n.º 26
0
 public void UnaryNegate_WithModulo()
 {
     Run(JsonPathWith.Array(jv => jv.Length() % -3 > 1), "$[?(@.length % -3 > 1)]");
 }
Ejemplo n.º 27
0
 public void HasProperty()
 {
     Run(JsonPathWith.Array(jv => jv.HasProperty("test")), "$[?(@.test)]");
 }
Ejemplo n.º 28
0
 public void Complicated_SubtractNegate()
 {
     Run(JsonPathWith.Array(jv => (jv.Length() - -3) - -5 > 1), "$[?((@.length - -3)--5 > 1)]");
 }
Ejemplo n.º 29
0
 public void GroupedNot()
 {
     Run(JsonPathWith.Array(jv => !(jv.HasProperty("test") && jv.Name("name") == 5)), "$[?(!(@.test && @.name == 5))]");
 }
Ejemplo n.º 30
0
 public void And()
 {
     Run(JsonPathWith.Array(jv => jv.HasProperty("test") && jv.Name("name") == 5), "$[?(@.test && @.name == 5)]");
 }