Permalink
Browse files

Path reparse (#36)

* Removed existing path parsing logic.
Added new logic for start, object, and search operators.
Added unit tests to support path parsing.
Removed reference to Manatee.StateMachine!

Related issues: #10, #35

* Added indexed array parsing.

* Added wildcard array parser.
Updated namespace for Slice.
Fixed indexed array parser to accept negatives and partial slices.

* Added searching indexed array parser.
Added Equals() to all the things!
Added XML comments.
Added expression array parsers.  Still need expression parsing.
Added missing search array extension methods.

* Added simple expression parsers.

* Added equality on expressions.
Added a few expression parsers.

* I've seen the light.

* Added array and hasproperty expression parsing.
Updated HasProperty to path expression.

* Added Name() to indexed expression options.
Updated ExclusiveOr expression type to function as Exponent operator.
Overrode item addition methods in JsonArray to replace null with JsonValue.Null.

* Added parsers for not and or expressions.

* Added grouped expression parsing.

* Removed the ExclusiveOr expression type mapping to exponentiation as it doesn't prioritize right with C# and is confusing.
Added more tests.
BUG FIX: #13 - Issues with tests running concurrently.

* Added a lot more individual tests.
Submoduled schema test suite directory.
Added submodule for path test suite.

* Remaining changes from previous commit.

* Passing test suite.
Need negative parser tests.

* Added filter expression parse tests that use evaluation.

* Fixed obsolete extension methods to properly call newer ones.

* Added apache documentation.
Removed remaining references to StateMachine.
  • Loading branch information...
1 parent 2202680 commit 899914be12d3523b7b728b8136eaa2b7acce4e74 @gregsdennis committed on GitHub Sep 21, 2016
Showing with 4,143 additions and 1,233 deletions.
  1. +6 −0 .gitmodules
  2. +1 −0 JSON-Schema-Test-Suite/README.md
  3. +20 −0 JSON-Schema-Test-Suite/tests/draft4/ref.json
  4. +1 −0 Json-Path-Test-Suite
  5. +1 −0 Json-Schema-Test-Suite/.gitignore
  6. +1 −1 Manatee.Json.Tests/DevTest.cs
  7. +8 −5 Manatee.Json.Tests/Manatee.Json.Tests.csproj
  8. +37 −0 Manatee.Json.Tests/Path/EvaluationTest.cs
  9. +217 −0 Manatee.Json.Tests/Path/FilterExpressionTest.cs
  10. +2 −2 Manatee.Json.Tests/Path/GoessnerExamplesTest.cs
  11. +124 −0 Manatee.Json.Tests/Path/IndexExpressionParseTest.cs
  12. +283 −0 Manatee.Json.Tests/Path/ParsingTest.cs
  13. +120 −0 Manatee.Json.Tests/Path/TestSuite/JsonPathTestSuite.cs
  14. +26 −0 Manatee.Json.Tests/Path/TestSuite/PathTest.cs
  15. +24 −0 Manatee.Json.Tests/Path/TestSuite/PathTestSet.cs
  16. +223 −0 Manatee.Json.Tests/Path/ToStringTest.cs
  17. +2 −0 Manatee.Json.Tests/Serialization/JsonDeserializerTest.cs
  18. +0 −4 Manatee.Json.Tests/packages.config
  19. +4 −2 Manatee.Json.sln.DotSettings
  20. +3 −0 Manatee.Json.sln.DotSettings.user
  21. +11 −0 Manatee.Json/Internal/GeneralExtensions.cs
  22. +21 −2 Manatee.Json/JsonArray.cs
  23. +2 −1 Manatee.Json/JsonObject.cs
  24. +36 −33 Manatee.Json/Manatee.Json.csproj
  25. +1 −1 Manatee.Json/Parsing/ArrayParser.cs
  26. +1 −1 Manatee.Json/Parsing/BoolParser.cs
  27. +1 −1 Manatee.Json/Parsing/IJsonParser.cs
  28. +2 −2 Manatee.Json/Parsing/JsonParser.cs
  29. +1 −1 Manatee.Json/Parsing/NullParser.cs
  30. +4 −2 Manatee.Json/Parsing/NumberParser.cs
  31. +1 −1 Manatee.Json/Parsing/ObjectParser.cs
  32. +1 −1 Manatee.Json/Parsing/StringParser.cs
  33. +16 −1 Manatee.Json/Path/ArrayParameters/FilterExpressionQuery.cs
  34. +17 −2 Manatee.Json/Path/ArrayParameters/IndexExpressionQuery.cs
  35. +0 −53 Manatee.Json/Path/ArrayParameters/IndexQuery.cs
  36. +22 −31 Manatee.Json/Path/ArrayParameters/SliceQuery.cs
  37. +16 −1 Manatee.Json/Path/ArrayParameters/WildCardQuery.cs
  38. +26 −2 Manatee.Json/Path/Expressions/AddExpression.cs
  39. +23 −2 Manatee.Json/Path/Expressions/AndExpression.cs
  40. +27 −3 Manatee.Json/Path/Expressions/ArrayIndexExpression.cs
  41. +20 −3 Manatee.Json/Path/Expressions/ConversionExpression.cs
  42. +23 −2 Manatee.Json/Path/Expressions/DivideExpression.cs
  43. +21 −2 Manatee.Json/Path/Expressions/ExponentExpression.cs
  44. +23 −447 Manatee.Json/Path/Expressions/Expression.cs
  45. +13 −0 Manatee.Json/Path/Expressions/ExpressionTreeBranch.cs
  46. +10 −1 Manatee.Json/Path/Expressions/ExpressionTreeNode.cs
  47. +21 −3 Manatee.Json/Path/Expressions/FieldExpression.cs
  48. +22 −2 Manatee.Json/Path/Expressions/HasPropertyExpression.cs
  49. +25 −3 Manatee.Json/Path/Expressions/IndexOfExpression.cs
  50. +21 −2 Manatee.Json/Path/Expressions/IsEqualExpression.cs
  51. +23 −2 Manatee.Json/Path/Expressions/IsGreaterThanEqualExpression.cs
  52. +24 −2 Manatee.Json/Path/Expressions/IsGreaterThanExpression.cs
  53. +23 −2 Manatee.Json/Path/Expressions/IsLessThanEqualExpression.cs
  54. +23 −2 Manatee.Json/Path/Expressions/IsLessThanExpression.cs
  55. +21 −2 Manatee.Json/Path/Expressions/IsNotEqualExpression.cs
  56. +21 −2 Manatee.Json/Path/Expressions/LengthExpression.cs
  57. +23 −2 Manatee.Json/Path/Expressions/ModuloExpression.cs
  58. +23 −2 Manatee.Json/Path/Expressions/MultiplyExpression.cs
  59. +25 −3 Manatee.Json/Path/Expressions/NameExpresssion.cs
  60. +17 −2 Manatee.Json/Path/Expressions/NegateExpression.cs
  61. +19 −2 Manatee.Json/Path/Expressions/NotExpression.cs
  62. +23 −2 Manatee.Json/Path/Expressions/OrExpression.cs
  63. +38 −0 Manatee.Json/Path/Expressions/Parsing/AddExpressionParser.cs
  64. +38 −0 Manatee.Json/Path/Expressions/Parsing/AndExpressionParser.cs
  65. +50 −0 Manatee.Json/Path/Expressions/Parsing/ConstantBooleanExpressionParser.cs
  66. +47 −0 Manatee.Json/Path/Expressions/Parsing/ConstantNumberExpressionParser.cs
  67. +47 −0 Manatee.Json/Path/Expressions/Parsing/ConstantStringExpressionParser.cs
  68. +38 −0 Manatee.Json/Path/Expressions/Parsing/DivideExpressionParser.cs
  69. +38 −0 Manatee.Json/Path/Expressions/Parsing/ExponentExpressionParser.cs
  70. +38 −0 Manatee.Json/Path/Expressions/Parsing/ExpressionEndParser.cs
  71. +39 −0 Manatee.Json/Path/Expressions/Parsing/GroupExpressionParser.cs
  72. +30 −0 Manatee.Json/Path/Expressions/Parsing/IJsonPathExpressionParser.cs
  73. +38 −0 Manatee.Json/Path/Expressions/Parsing/IsEqualExpressionParser.cs
  74. +38 −0 Manatee.Json/Path/Expressions/Parsing/IsGreaterThanEqualExpressionParser.cs
  75. +38 −0 Manatee.Json/Path/Expressions/Parsing/IsGreaterThanExpressionParser.cs
  76. +38 −0 Manatee.Json/Path/Expressions/Parsing/IsLessThanEqualExpressionParser.cs
  77. +38 −0 Manatee.Json/Path/Expressions/Parsing/IsLessThanExpressionParser.cs
  78. +38 −0 Manatee.Json/Path/Expressions/Parsing/IsNotEqualExpressionParser.cs
  79. +121 −0 Manatee.Json/Path/Expressions/Parsing/JsonPathExpressionParser.cs
  80. +38 −0 Manatee.Json/Path/Expressions/Parsing/LengthExpressionParser.cs
  81. +38 −0 Manatee.Json/Path/Expressions/Parsing/ModuloExpressionParser.cs
  82. +38 −0 Manatee.Json/Path/Expressions/Parsing/MultiplyExpressionParser.cs
  83. +38 −0 Manatee.Json/Path/Expressions/Parsing/NotExpressionParser.cs
  84. +38 −0 Manatee.Json/Path/Expressions/Parsing/OrExpressionParser.cs
  85. +128 −0 Manatee.Json/Path/Expressions/Parsing/PathExpressionParser.cs
  86. +39 −0 Manatee.Json/Path/Expressions/Parsing/SubtractExpressionParser.cs
  87. +17 −2 Manatee.Json/Path/Expressions/PathExpression.cs
  88. +24 −3 Manatee.Json/Path/Expressions/SubtractExpression.cs
  89. +9 −9 Manatee.Json/Path/Expressions/Translation/ArrayIndexExpressionTranslator.cs
  90. +11 −11 Manatee.Json/Path/Expressions/Translation/ExpressionTranslator.cs
  91. +9 −3 Manatee.Json/Path/Expressions/Translation/HasPropertyExpressionTranslator.cs
  92. +4 −4 Manatee.Json/Path/Expressions/Translation/PathExpressionTranslator.cs
  93. +16 −10 Manatee.Json/Path/Expressions/ValueComparer.cs
  94. +22 −3 Manatee.Json/Path/Expressions/ValueExpression.cs
  95. +24 −407 Manatee.Json/Path/JsonPath.cs
  96. +1 −1 Manatee.Json/Path/JsonPathArray.cs
  97. +3 −3 Manatee.Json/Path/JsonPathSyntaxException.cs
  98. +3 −34 Manatee.Json/Path/JsonPathValue.cs
  99. +61 −39 Manatee.Json/Path/JsonPathWith.cs
  100. +21 −6 Manatee.Json/Path/Operators/ArrayOperator.cs
  101. +16 −1 Manatee.Json/Path/Operators/IndexOfOperator.cs
  102. +16 −2 Manatee.Json/Path/Operators/LengthOperator.cs
  103. +19 −2 Manatee.Json/Path/Operators/NameOperator.cs
  104. +17 −1 Manatee.Json/Path/Operators/SearchOperator.cs
  105. +22 −2 Manatee.Json/Path/Operators/WildCardOperator.cs
  106. +50 −0 Manatee.Json/Path/Parsing/ExpressionFilterParser.cs
  107. +50 −0 Manatee.Json/Path/Parsing/ExpressionIndexParser.cs
  108. +31 −0 Manatee.Json/Path/Parsing/IJsonPathParser.cs
  109. +48 −0 Manatee.Json/Path/Parsing/IndexedArrayParser.cs
  110. +70 −0 Manatee.Json/Path/Parsing/JsonPathParser.cs
  111. +53 −0 Manatee.Json/Path/Parsing/ObjectParser.cs
  112. +238 −0 Manatee.Json/Path/Parsing/PathParsingExtensions.cs
  113. +49 −0 Manatee.Json/Path/Parsing/SearchIndexedArrayParser.cs
  114. +53 −0 Manatee.Json/Path/Parsing/SearchParser.cs
  115. +17 −17 Manatee.Json/Path/{Expressions/GroupExpression.cs → Parsing/StartParser.cs}
  116. +38 −0 Manatee.Json/Path/Parsing/WildcardArrayParser.cs
  117. +10 −0 Manatee.Json/Path/PathExpressionExtensions.cs
  118. +16 −1 Manatee.Json/Path/SearchParameters/ArraySearchParameter.cs
  119. +15 −1 Manatee.Json/Path/SearchParameters/LengthSearchParameter.cs
  120. +16 −1 Manatee.Json/Path/SearchParameters/NameSearchParameter.cs
  121. +15 −1 Manatee.Json/Path/SearchParameters/WildCardSearchParameter.cs
  122. +143 −0 Manatee.Json/Path/Slice.cs
  123. +11 −20 Manatee.Json/Schema/JsonSchemaPropertyDefinition.cs
  124. +0 −4 Manatee.Json/packages.config
View
@@ -0,0 +1,6 @@
+[submodule "Json-Path-Test-Suite"]
+ path = Json-Path-Test-Suite
+ url = https://github.com/gregsdennis/JSON-Path-Test-Suite.git
+[submodule "Json-Schema-Test-Suite"]
+ path = Json-Schema-Test-Suite
+ url = https://github.com/json-schema-org/JSON-Schema-Test-Suite.git
@@ -118,6 +118,7 @@ for more information.
### .NET ###
* [Newtonsoft.Json.Schema](https://github.com/JamesNK/Newtonsoft.Json.Schema)
+* [Manatee.Json](https://github.com/gregsdennis/Manatee.Json)
### PHP ###
@@ -155,5 +155,25 @@
"valid": false
}
]
+ },
+ {
+ "description": "property named $ref that is not a reference",
+ "schema": {
+ "properties": {
+ "$ref": {"type": "string"}
+ }
+ },
+ "tests": [
+ {
+ "description": "property named $ref valid",
+ "data": {"$ref": "a"},
+ "valid": true
+ },
+ {
+ "description": "property named $ref invalid",
+ "data": {"$ref": 2},
+ "valid": false
+ }
+ ]
}
]
Submodule Json-Path-Test-Suite added at c5afa4
@@ -0,0 +1 @@
+TODO
@@ -28,7 +28,7 @@
namespace Manatee.Json.Tests
{
[TestClass]
- [Ignore]
+ [Ignore]
public class DevTest
{
[TestMethod]
@@ -139,10 +139,6 @@
<AssemblyOriginatorKeyFile>Manatee.Json.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
- <Reference Include="Manatee.StateMachine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=15909d91027a225e, processorArchitecture=MSIL">
- <HintPath>..\packages\Manatee.StateMachine.1.1.2\lib\net40\Manatee.StateMachine.dll</HintPath>
- <Private>True</Private>
- </Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
@@ -174,6 +170,14 @@
<Compile Include="JsonValueEqualsTest.cs" />
<Compile Include="JsonValueOperatorTest.cs" />
<Compile Include="JsonValueParseTest.cs" />
+ <Compile Include="Path\EvaluationTest.cs" />
+ <Compile Include="Path\FilterExpressionTest.cs" />
+ <Compile Include="Path\IndexExpressionParseTest.cs" />
+ <Compile Include="Path\ParsingTest.cs" />
+ <Compile Include="Path\TestSuite\JsonPathTestSuite.cs" />
+ <Compile Include="Path\TestSuite\PathTest.cs" />
+ <Compile Include="Path\TestSuite\PathTestSet.cs" />
+ <Compile Include="Path\ToStringTest.cs" />
<Compile Include="Schema\JsonSchemaTypeDefinitionTest.cs" />
<Compile Include="Schema\JsonSchemaTypeTest.cs" />
<Compile Include="Schema\SelfValidationTest.cs" />
@@ -223,7 +227,6 @@
</ItemGroup>
<ItemGroup>
<None Include="Manatee.Json.snk" />
- <None Include="packages.config" />
<None Include="TrelloCard.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
@@ -0,0 +1,37 @@
+using Manatee.Json.Path;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace Manatee.Json.Tests.Path
+{
+ [TestClass]
+ public class EvaluationTest
+ {
+ [TestMethod]
+ 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);
+ }
+ [TestMethod]
+ 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);
+ }
+ }
+}
@@ -0,0 +1,217 @@
+using Manatee.Json.Path;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace Manatee.Json.Tests.Path
+{
+ [TestClass]
+ public class FilterExpressionTest
+ {
+ private void Run(JsonPath expected, string text)
+ {
+ var actual = JsonPath.Parse(text);
+ Assert.AreEqual(expected, actual);
+ }
+
+ private void CompareEval(JsonPath expected, string text)
+ {
+ var data = new JsonArray
+ {
+ 1,
+ new JsonObject
+ {
+ ["bool"] = false,
+ ["int"] = 20,
+ ["string"] = "value",
+ },
+ "hello",
+ true,
+ 5,
+ new JsonArray {1,2,3 }
+ };
+
+ var actual = JsonPath.Parse(text);
+
+ var expectedResult = expected.Evaluate(data);
+ var actualResult = actual.Evaluate(data);
+
+ Assert.AreEqual(expectedResult, actualResult);
+ }
+
+ [TestMethod]
+ public void PropertyEqualsValue()
+ {
+ Run(JsonPathWith.Array(jv => jv.Name("test") == 5), "$[?(@.test == 5)]");
+ }
+ [TestMethod]
+ public void PropertyNotEqualToValue()
+ {
+ Run(JsonPathWith.Array(jv => jv.Name("test") != 5), "$[?(@.test != 5)]");
+ }
+ [TestMethod]
+ public void PropertyGreaterThanValue()
+ {
+ Run(JsonPathWith.Array(jv => jv.Name("test") > 5), "$[?(@.test > 5)]");
+ }
+ [TestMethod]
+ public void PropertyGreaterThanEqualToValue()
+ {
+ Run(JsonPathWith.Array(jv => jv.Name("test") >= 5), "$[?(@.test >= 5)]");
+ }
+ [TestMethod]
+ public void PropertyLessThanValue()
+ {
+ Run(JsonPathWith.Array(jv => jv.Name("test") < 5), "$[?(@.test < 5)]");
+ }
+ [TestMethod]
+ public void PropertyLessThanEqualToValue()
+ {
+ Run(JsonPathWith.Array(jv => jv.Name("test") <= 5), "$[?(@.test <= 5)]");
+ }
+ [TestMethod]
+ public void ArrayIndexEqualsValue()
+ {
+ Run(JsonPathWith.Array(jv => jv.ArrayIndex(1) == 5), "$[?(@[1] == 5)]");
+ }
+ [TestMethod]
+ [ExpectedException(typeof(JsonPathSyntaxException))]
+ public void ArrayMultiIndex()
+ {
+ var text = "$[?(@[1,3] == 5)]";
+
+ try
+ {
+ var actual = JsonPath.Parse(text);
+ }
+ catch (JsonPathSyntaxException e)
+ {
+ Assert.IsTrue(e.Message.StartsWith("JSON Path expression indexers only support single constant values."));
+ throw;
+ }
+ }
+ [TestMethod]
+ [ExpectedException(typeof(JsonPathSyntaxException))]
+ public void ArraySliceEqualsValue()
+ {
+ var text = "$[?(@[1:3] == 5)]";
+
+ try
+ {
+ var actual = JsonPath.Parse(text);
+ }
+ catch (JsonPathSyntaxException e)
+ {
+ Assert.IsTrue(e.Message.StartsWith("JSON Path expression indexers only support single constant values."));
+ throw;
+ }
+ }
+ [TestMethod]
+ [ExpectedException(typeof(JsonPathSyntaxException))]
+ public void ArrayIndexExpressionEqualsValue()
+ {
+ var text = "$[?(@[(@.length-1))]";
+
+ try
+ {
+ var actual = JsonPath.Parse(text);
+ }
+ catch (JsonPathSyntaxException e)
+ {
+ Assert.IsTrue(e.Message.StartsWith("JSON Path expression indexers only support single constant values."));
+ throw;
+ }
+ }
+ [TestMethod]
+ [ExpectedException(typeof(JsonPathSyntaxException))]
+ public void ArrayFilterExpressionEqualsValue()
+ {
+ var text = "$[?(@[?(@.name == 5))]";
+
+ try
+ {
+ var actual = JsonPath.Parse(text);
+ }
+ catch (JsonPathSyntaxException e)
+ {
+ Assert.IsTrue(e.Message.StartsWith("JSON Path expression indexers only support single constant values."));
+ throw;
+ }
+ }
+ [TestMethod]
+ public void HasProperty()
+ {
+ Run(JsonPathWith.Array(jv => jv.HasProperty("test")), "$[?(@.test)]");
+ }
+ [TestMethod]
+ public void DoesNotHaveProperty()
+ {
+ Run(JsonPathWith.Array(jv => !jv.HasProperty("test")), "$[?(!@.test)]");
+ }
+ [TestMethod]
+ public void GroupedNot()
+ {
+ Run(JsonPathWith.Array(jv => !(jv.HasProperty("test") && jv.Name("name") == 5)), "$[?(!(@.test && @.name == 5))]");
+ }
+ [TestMethod]
+ public void And()
+ {
+ Run(JsonPathWith.Array(jv => jv.HasProperty("test") && jv.Name("name") == 5), "$[?(@.test && @.name == 5)]");
+ }
+ [TestMethod]
+ public void Or()
+ {
+ Run(JsonPathWith.Array(jv => jv.HasProperty("test") || jv.Name("name") == 5),"$[?(@.test || @.name == 5)]");
+ }
+ [TestMethod]
+ // 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)]");
+ }
+ [TestMethod]
+ // 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)]");
+ }
+ [TestMethod]
+ // 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)]");
+ }
+ [TestMethod]
+ // 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)]");
+ }
+ [TestMethod]
+ // 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)]");
+ }
+ }
+}
@@ -332,7 +332,7 @@ public void GoessnerExample6BParsed()
[TestMethod]
public void GoessnerExample6BConstructed()
{
- var path = JsonPathWith.Search("book").ArraySlice(-1, null);
+ var path = JsonPathWith.Search("book").Array(new Slice(-1, null));
var expected = new JsonArray
{
new JsonObject
@@ -426,7 +426,7 @@ public void GoessnerExample7BParsed()
[TestMethod]
public void GoessnerExample7BConstructed()
{
- var path = JsonPathWith.Search("book").ArraySlice(null, 2);
+ var path = JsonPathWith.Search("book").Array(new Slice(null, 2));
var expected = new JsonArray
{
new JsonObject
Oops, something went wrong.

0 comments on commit 899914b

Please sign in to comment.