public void AnyAllSyntacticParsingShouldCheckSeperatorTokenIsColon() { // Repro for: Syntactic parsing for Any/All allows an arbitrary token between range variable and expression Action parse = () => this.testSubject.ParseFilter("Things/any(a,true)"); parse.ShouldThrow <ODataException>().WithMessage(ErrorStrings.ExpressionLexer_SyntaxError("13", "Things/any(a,true)")); }
public void StarMustBeLastTokenInDottedIdentifier() { ExpressionLexer lexer = new ExpressionLexer("m.*.blah", true, false); Action read = () => lexer.ReadDottedIdentifier(true); read.ShouldThrow <ODataException>(ODataErrorStrings.ExpressionLexer_SyntaxError("2", "m.*.blah")); }
public void ParseApplyWithTrailingNotSlashShouldThrow() { var apply = "aggregate(UnitPrice with sum as TotalPrice),"; Action parse = () => this.testSubject.ParseApply(apply); parse.ShouldThrow <ODataException>().Where(e => e.Message == ErrorStrings.ExpressionLexer_SyntaxError(apply.Length, apply)); }
public void ShouldThrowWhenCurrentTokenIsNotExpressionKind() { ExpressionLexer lexer = new ExpressionLexer("null", true, false); Action validate = () => lexer.ValidateToken(ExpressionTokenKind.Question); validate.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.ExpressionLexer_SyntaxError(4, "null")); }
public void ShouldThrowWhenNotGivenIdentifierToken() { ExpressionLexer lexer = new ExpressionLexer("2.43", false, false); Action read = () => lexer.ReadDottedIdentifier(false); read.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.ExpressionLexer_SyntaxError("0", "2.43")); }
public void ShouldThrowWhenGivenStarInDontAcceptStarMode() { ExpressionLexer lexer = new ExpressionLexer("m.*", true, false); Action read = () => lexer.ReadDottedIdentifier(false); read.ShouldThrow <ODataException>(ODataErrorStrings.ExpressionLexer_SyntaxError("2", "m.*")); }
public void FunctionParameterParserShouldThrowIfSecondParameterIsPositional() { ICollection <OperationSegmentParameter> parsedParameters; Action parse = () => TryParseFunctionParameters("fakeFunc", "a=1,2", null, out parsedParameters); parse.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.ExpressionLexer_SyntaxError(5, "a=1,2")); }
public void TypedNullFunctionParameterParsingShouldThrow() { ICollection <OperationSegmentParameter> parsedParameters; Action parse = () => TryParsOperationParameters("CanMoveToAddress", "address=null'Fully.Qualified.Namespace.Address'", null, out parsedParameters).Should().BeTrue(); parse.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.ExpressionLexer_SyntaxError(12, "address=null'Fully.Qualified.Namespace.Address'")); }
public void FunctionParameterParserShouldFailIfAnExtraClosingParenthesisIsFoundInPath() { ICollection <FunctionParameterToken> splitParameters; ODataUriParserConfiguration configuration = new ODataUriParserConfiguration(HardCodedTestModel.TestModel) { ParameterAliasValueAccessor = null }; Action parse = () => FunctionParameterParser.TrySplitOperationParameters(/*"fakeFunc", */ "a=1)", configuration, out splitParameters); parse.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.ExpressionLexer_SyntaxError(4, "a=1)")); }
/// <summary> /// Tries to parse a collection of function parameters. Allows path and filter to share the core algorithm while representing parameters differently. /// </summary> /// <param name="parser">The UriQueryExpressionParser to read from.</param> /// <param name="endTokenKind">The token kind that marks the end of the parameters.</param> /// <param name="splitParameters">The parameters if they were successfully split.</param> /// <returns>Whether the parameters could be split.</returns> private static bool TrySplitOperationParameters(this UriQueryExpressionParser parser, ExpressionTokenKind endTokenKind, out ICollection <FunctionParameterToken> splitParameters) { Debug.Assert(parser != null, "parser != null"); var lexer = parser.Lexer; var parameters = new List <FunctionParameterToken>(); splitParameters = parameters; ExpressionToken currentToken = lexer.CurrentToken; if (currentToken.Kind == endTokenKind) { return(true); } if (currentToken.Kind != ExpressionTokenKind.Identifier || lexer.PeekNextToken().Kind != ExpressionTokenKind.Equal) { return(false); } while (currentToken.Kind != endTokenKind) { lexer.ValidateToken(ExpressionTokenKind.Identifier); string identifier = lexer.CurrentToken.GetIdentifier(); lexer.NextToken(); lexer.ValidateToken(ExpressionTokenKind.Equal); lexer.NextToken(); // the below UriQueryExpressionParser.ParseExpression() is able to parse common expression per ABNF: // functionExprParameter = parameterName EQ ( parameterAlias / parameterValue ) // parameterValue = arrayOrObject // / commonExpr QueryToken parameterValue = parser.ParseExpression(); parameters.Add(new FunctionParameterToken(identifier, parameterValue)); // the above parser.ParseExpression() already moves to the next token, now get CurrentToken checking a comma followed by something currentToken = lexer.CurrentToken; if (currentToken.Kind == ExpressionTokenKind.Comma) { lexer.NextToken(); currentToken = lexer.CurrentToken; if (currentToken.Kind == endTokenKind) { // Trailing comma. throw new ODataException(ODataErrorStrings.ExpressionLexer_SyntaxError(lexer.Position, lexer.ExpressionText)); } } } return(true); }
public void ExpressionLexerShouldFailAtSymbolIsLastCharacter() { Action lex = () => new ExpressionLexer("@", moveToFirstToken: true, useSemicolonDelimeter: false, parsingFunctionParameters: true); lex.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.ExpressionLexer_SyntaxError(1, "@")); }
public void ContainerQualifiedWildcardNotAllowedInExpand() { Action parseWithContainerQualfiedWildcard = () => this.ParseExpandTerm("container.qualified.*"); parseWithContainerQualfiedWildcard.ShouldThrow <ODataException>(ODataErrorStrings.ExpressionLexer_SyntaxError("10", "container.qualified.*")); }