Example #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);
        }
Example #2
0
        public void ArrayIndexExpression_IndexOfObject()
        {
            var obj = new JsonObject {
                { "key", "value" }
            };

            Run("$[?(@.indexOf({\"key\":\"value\"}) == 4)]", JsonPathWith.Array(jv => jv.IndexOf(obj) == 4));
        }
Example #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)]");
        }
Example #5
0
        public void WildcardArray()
        {
            var text     = "$[*]";
            var expected = JsonPathWith.Array();

            var actual = JsonPath.Parse(text);

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

            var actual = JsonPath.Parse(text);

            Assert.AreEqual(expected, actual);
        }
Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #10
0
        public void SingleIndexedArray()
        {
            var text     = "$[1]";
            var expected = JsonPathWith.Array(1);

            var actual = JsonPath.Parse(text);

            Assert.AreEqual(expected, actual);
        }
        // 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)]");
        }
Example #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);
        }
Example #13
0
 public void UnaryNegate_WithMultiply()
 {
     Run(JsonPathWith.Array(jv => jv.Length() * -3 > 1), "$[?(@.length * -3 > 1)]");
 }
Example #14
0
 public void UnaryNegate_WithSubtract()
 {
     Run(JsonPathWith.Array(jv => jv.Length() - -3 > 1), "$[?(@.length - -3 > 1)]");
 }
 // 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)]");
 }
 // 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)]");
 }
 // 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)]");
 }
 public void Or()
 {
     Run(JsonPathWith.Array(jv => jv.HasProperty("test") || jv.Name("name") == 5), "$[?(@.test || @.name == 5)]");
 }
 public void DoesNotHaveProperty()
 {
     Run(JsonPathWith.Array(jv => !jv.HasProperty("test")), "$[?([email protected])]");
 }
 public void ArrayIndexEqualsValue()
 {
     Run(JsonPathWith.Array(jv => jv.ArrayIndex(1) == 5), "$[?(@[1] == 5)]");
 }
 public void PropertyGreaterThanEqualToValue()
 {
     Run(JsonPathWith.Array(jv => jv.Name("test") >= 5), "$[?(@.test >= 5)]");
 }
 public void PropertyEqualsValue()
 {
     Run(JsonPathWith.Array(jv => jv.Name("test") == 5), "$[?(@.test == 5)]");
 }
 public void PropertyNotEqualToValue()
 {
     Run(JsonPathWith.Array(jv => jv.Name("test") != 5), "$[?(@.test != 5)]");
 }
Example #24
0
 public void UnaryNegate_WithDivide()
 {
     Run(JsonPathWith.Array(jv => jv.Length() / -3 > 1), "$[?(@.length / -3 > 1)]");
 }
 public void PropertyLessThanEqualToValue()
 {
     Run(JsonPathWith.Array(jv => jv.Name("test") <= 5), "$[?(@.test <= 5)]");
 }
Example #26
0
 public void UnaryNegate_WithModulo()
 {
     Run(JsonPathWith.Array(jv => jv.Length() % -3 > 1), "$[?(@.length % -3 > 1)]");
 }
 public void HasProperty()
 {
     Run(JsonPathWith.Array(jv => jv.HasProperty("test")), "$[?(@.test)]");
 }
Example #28
0
 public void Complicated_SubtractNegate()
 {
     Run(JsonPathWith.Array(jv => (jv.Length() - -3) - -5 > 1), "$[?((@.length - -3)--5 > 1)]");
 }
 public void GroupedNot()
 {
     Run(JsonPathWith.Array(jv => !(jv.HasProperty("test") && jv.Name("name") == 5)), "$[?(!(@.test && @.name == 5))]");
 }
 public void And()
 {
     Run(JsonPathWith.Array(jv => jv.HasProperty("test") && jv.Name("name") == 5), "$[?(@.test && @.name == 5)]");
 }