private void CheckNumberError(string expression, SpelMessage expectedMessage) { var parser = new SpelExpressionParser(); var ex = Assert.Throws <SpelParseException>(() => parser.ParseRaw(expression)); Assert.Equal(expectedMessage, ex.MessageCode); }
public void PositionalInformation() { var expr = new SpelExpressionParser().ParseRaw("true and true or false") as SpelExpression; var rootAst = expr.AST; var operatorOr = (OpOr)rootAst; var operatorAnd = (OpAnd)operatorOr.LeftOperand; var rightOrOperand = operatorOr.RightOperand; // check position for final 'false' Assert.Equal(17, rightOrOperand.StartPosition); Assert.Equal(22, rightOrOperand.EndPosition); // check position for first 'true' Assert.Equal(0, operatorAnd.LeftOperand.StartPosition); Assert.Equal(4, operatorAnd.LeftOperand.EndPosition); // check position for second 'true' Assert.Equal(9, operatorAnd.RightOperand.StartPosition); Assert.Equal(13, operatorAnd.RightOperand.EndPosition); // check position for OperatorAnd Assert.Equal(5, operatorAnd.StartPosition); Assert.Equal(8, operatorAnd.EndPosition); // check position for OperatorOr Assert.Equal(14, operatorOr.StartPosition); Assert.Equal(16, operatorOr.EndPosition); }
public void ArithmeticPlus2() { var parser = new SpelExpressionParser(); var expr = parser.ParseRaw("37+41"); Assert.Equal(78, expr.GetValue()); }
public void ArithmeticPrecedence1() { var parser = new SpelExpressionParser(); var expr = parser.ParseRaw("2*3+5"); Assert.Equal(11, expr.GetValue()); }
public void TestStringLiterals_DoubleQuotes_spr9620() { var expr = new SpelExpressionParser().ParseRaw("\"double quote: \"\".\""); Assert.Equal("double quote: \".", expr.GetValue()); expr = new SpelExpressionParser().ParseRaw("\"hello \"\" world\""); Assert.Equal("hello \" world", expr.GetValue()); }
public void StringLiterals() { var expr = new SpelExpressionParser().ParseRaw("'howdy'"); Assert.Equal("howdy", expr.GetValue()); expr = new SpelExpressionParser().ParseRaw("'hello '' world'"); Assert.Equal("hello ' world", expr.GetValue()); }
public void ArithmeticPlus1() { var parser = new SpelExpressionParser(); var expr = parser.ParseRaw("2+2") as SpelExpression; Assert.NotNull(expr); Assert.NotNull(expr.AST); Assert.Equal(4, expr.GetValue()); }
public void ArithmeticMultiply1() { var parser = new SpelExpressionParser(); var expr = parser.ParseRaw("2*3") as SpelExpression; Assert.NotNull(expr); Assert.NotNull(expr.AST); // printAst(expr.getAST(),0); Assert.Equal(6, expr.GetValue()); }
public void TheMostBasic() { var parser = new SpelExpressionParser(); var expr = parser.ParseRaw("2") as SpelExpression; Assert.NotNull(expr); Assert.NotNull(expr.AST); Assert.Equal(2, expr.GetValue()); Assert.Equal(typeof(int), expr.GetValueType()); Assert.Equal(2, expr.AST.GetValue(null)); }
public void Whitespace() { var parser = new SpelExpressionParser(); var expr = parser.ParseRaw("2 + 3"); Assert.Equal(5, expr.GetValue()); expr = parser.ParseRaw("2 + 3"); Assert.Equal(5, expr.GetValue()); expr = parser.ParseRaw("2\n+\t3"); Assert.Equal(5, expr.GetValue()); expr = parser.ParseRaw("2\r\n+\t3"); Assert.Equal(5, expr.GetValue()); }
private void CheckNumber(string expression, object value, Type type) { try { var parser = new SpelExpressionParser(); var expr = parser.ParseRaw(expression) as SpelExpression; var exprVal = expr.GetValue(); Assert.Equal(value, exprVal); Assert.Equal(type, exprVal.GetType()); } catch (Exception ex) { throw new Exception(ex.Message, ex); } }
public void GeneralExpressions() { var ex = Assert.Throws <SpelParseException>(() => { var parser = new SpelExpressionParser(); parser.ParseRaw("new String"); }); ParseExceptionRequirements(ex, SpelMessage.MISSING_CONSTRUCTOR_ARGS, 10); ex = Assert.Throws <SpelParseException>(() => { var parser = new SpelExpressionParser(); parser.ParseRaw("new String(3,"); }); ParseExceptionRequirements(ex, SpelMessage.RUN_OUT_OF_ARGUMENTS, 10); ex = Assert.Throws <SpelParseException>(() => { var parser = new SpelExpressionParser(); parser.ParseRaw("new String(3"); }); ParseExceptionRequirements(ex, SpelMessage.RUN_OUT_OF_ARGUMENTS, 10); ex = Assert.Throws <SpelParseException>(() => { var parser = new SpelExpressionParser(); parser.ParseRaw("new String("); }); ParseExceptionRequirements(ex, SpelMessage.RUN_OUT_OF_ARGUMENTS, 10); ex = Assert.Throws <SpelParseException>(() => { var parser = new SpelExpressionParser(); parser.ParseRaw("\"abc"); }); ParseExceptionRequirements(ex, SpelMessage.NON_TERMINATING_DOUBLE_QUOTED_STRING, 0); ex = Assert.Throws <SpelParseException>(() => { var parser = new SpelExpressionParser(); parser.ParseRaw("'abc"); }); ParseExceptionRequirements(ex, SpelMessage.NON_TERMINATING_QUOTED_STRING, 0); }
public void ValueType() { var parser = new SpelExpressionParser(); var ctx = new StandardEvaluationContext(); var c = parser.ParseRaw("2").GetValueType(); Assert.Equal(typeof(int), c); c = parser.ParseRaw("12").GetValueType(ctx); Assert.Equal(typeof(int), c); c = parser.ParseRaw("null").GetValueType(); Assert.Null(c); c = parser.ParseRaw("null").GetValueType(ctx); Assert.Null(c); var o = parser.ParseRaw("null").GetValue(ctx, typeof(object)); Assert.Null(o); }
public void BooleanOperators_symbolic_spr9614() { var expr = new SpelExpressionParser().ParseRaw("true"); Assert.True(expr.GetValue <bool>()); expr = new SpelExpressionParser().ParseRaw("false"); Assert.False(expr.GetValue <bool>()); expr = new SpelExpressionParser().ParseRaw("false && false"); Assert.False(expr.GetValue <bool>()); expr = new SpelExpressionParser().ParseRaw("true && (true || false)"); Assert.True(expr.GetValue <bool>()); expr = new SpelExpressionParser().ParseRaw("true && true || false"); Assert.True(expr.GetValue <bool>()); expr = new SpelExpressionParser().ParseRaw("!true"); Assert.False(expr.GetValue <bool>()); expr = new SpelExpressionParser().ParseRaw("!(false || true)"); Assert.False(expr.GetValue <bool>()); }
public void BooleanOperators() { var expr = new SpelExpressionParser().ParseRaw("true"); Assert.True(expr.GetValue <bool>()); expr = new SpelExpressionParser().ParseRaw("false"); Assert.False(expr.GetValue <bool>()); expr = new SpelExpressionParser().ParseRaw("false and false"); Assert.False(expr.GetValue <bool>()); expr = new SpelExpressionParser().ParseRaw("true and (true or false)"); Assert.True(expr.GetValue <bool>()); expr = new SpelExpressionParser().ParseRaw("true and true or false"); Assert.True(expr.GetValue <bool>()); expr = new SpelExpressionParser().ParseRaw("!true"); Assert.False(expr.GetValue <bool>()); expr = new SpelExpressionParser().ParseRaw("!(false or true)"); Assert.False(expr.GetValue <bool>()); }
public void ArithmeticPrecedence4() { var expr = new SpelExpressionParser().ParseRaw("10/2+3"); Assert.Equal(8, expr.GetValue()); }
public void ArithmeticPrecedence5() { var expr = new SpelExpressionParser().ParseRaw("(4+10)/2"); Assert.Equal(7, expr.GetValue()); }
public void ArithmeticPrecedence6() { var expr = new SpelExpressionParser().ParseRaw("(3+2)*2"); Assert.Equal(10, expr.GetValue()); }
public void StringLiterals2() { var expr = new SpelExpressionParser().ParseRaw("'howdy'.Substring(0,2)"); Assert.Equal("ho", expr.GetValue()); }