private void Parse_Worker(string expression, bool expectedRecursiveDescent, JsonPathElement expectedElement) { var expected = expectedRecursiveDescent ? new JsonPathRecursiveDescentElement(expectedElement) : expectedElement; var actual = JsonPathExpressionStringParser.Parse(expression); actual.Should().BeEquivalentTo(expected); }
public void Append_Elements(string path, string expected, params string[] elementsToAppend) { var pathExpr = new JsonPathExpression(path); var expectedExpr = new JsonPathExpression(expected); var elements = elementsToAppend .Select(x => JsonPathExpressionStringParser.Parse(x).First()) .ToArray(); var actual = pathExpr.Append(elements); actual.Should().BeEquivalentTo(expectedExpr); }
public void Parse_Indexes_Parses() { string expression = "$[0][1]..[2].[3][*]"; var expected = new List <JsonPathElement> { new JsonPathRootElement(), new JsonPathArrayIndexElement(0), new JsonPathArrayIndexElement(1), new JsonPathRecursiveDescentElement(new JsonPathArrayIndexElement(2)), new JsonPathArrayIndexElement(3), new JsonPathAnyArrayIndexElement() }; var actual = JsonPathExpressionStringParser.Parse(expression); actual.Should().BeEquivalentTo(expected); }
public void Parse_Properties_Parses() { string expression = "$.first.second..third['fourth'].['fifth'].$.*"; var expected = new List <JsonPathElement> { new JsonPathRootElement(), new JsonPathPropertyElement("first"), new JsonPathPropertyElement("second"), new JsonPathRecursiveDescentElement(new JsonPathPropertyElement("third")), new JsonPathPropertyElement("fourth"), new JsonPathPropertyElement("fifth"), new JsonPathPropertyElement("$"), new JsonPathAnyPropertyElement() }; var actual = JsonPathExpressionStringParser.Parse(expression); actual.Should().BeEquivalentTo(expected); }
public void Parse_Throws(string expression) { Action action = () => JsonPathExpressionStringParser.Parse(expression); action.Should().Throw <JsonPathExpressionParsingException>(); }
/// <summary> /// Create <see cref="RelativeJsonPathExpression"/> instance from string presentation /// </summary> /// <param name="jsonPath">JsonPath expression string</param> /// <exception cref="ArgumentNullException"><paramref name="jsonPath"/> is null or empty</exception> /// <exception cref="JsonPathExpressionParsingException">Unable to parse <paramref name="jsonPath"/></exception> public RelativeJsonPathExpression(string jsonPath) : this(JsonPathExpressionStringParser.Parse(jsonPath)) { }
/// <summary> /// Create <see cref="AbsoluteJsonPathExpression"/> instance from string presentation /// </summary> /// <param name="jsonPath">JsonPath expression string</param> /// <exception cref="ArgumentNullException"><paramref name="jsonPath"/> is null or empty</exception> /// <exception cref="JsonPathExpressionParsingException">Unable to parse <paramref name="jsonPath"/></exception> public AbsoluteJsonPathExpression(string jsonPath) : this(JsonPathExpressionStringParser.Parse(jsonPath)) { }