Removing functionality. Removed expression list support, cannot say (foo();bar()) any more
This commit is contained in:
@@ -180,19 +180,11 @@ public class EvaluationTests extends ExpressionTestCase {
|
||||
evaluate("#{1:'January', 2:'February', 3:'March'}.get(2)", "February", String.class);
|
||||
}
|
||||
|
||||
public void testInlineMapCreation06() {
|
||||
evaluate("(#pos=3;#{1:'January', 2:'February', 3:'March'}[#pos])", "March", String.class);
|
||||
}
|
||||
|
||||
// set construction
|
||||
public void testSetConstruction01() {
|
||||
evaluate("new HashSet().addAll({'a','b','c'})", "true", Boolean.class);
|
||||
}
|
||||
|
||||
public void testSets01() {
|
||||
evaluate("(#var=new HashSet();#var.addAll({'a','b','c'});#var[1])", "c", String.class);
|
||||
}
|
||||
|
||||
// constructors
|
||||
public void testConstructorInvocation01() {
|
||||
evaluate("new String('hello')", "hello", String.class);
|
||||
@@ -323,19 +315,6 @@ public class EvaluationTests extends ExpressionTestCase {
|
||||
evaluate("#var1='value1'", "value1", String.class);
|
||||
}
|
||||
|
||||
public void testAssignmentToVariables02() {
|
||||
evaluate("(#var1='value1';#var1)", "value1", String.class, true);
|
||||
}
|
||||
|
||||
// Property setting
|
||||
public void testAssignmentToProperty01() {
|
||||
evaluate("placeOfBirth.city='SmilJan'", "SmilJan", String.class);
|
||||
evaluate(
|
||||
"(#oldPOB = placeOfBirth.city;placeOfBirth.city='FairOak';'From ' + #oldPOB + ' to ' + placeOfBirth.city)",
|
||||
"From SmilJan to FairOak", String.class);
|
||||
evaluate("placeOfBirth.city='SmilJan'", "SmilJan", String.class);
|
||||
}
|
||||
|
||||
// Ternary operator
|
||||
public void testTernaryOperator01() {
|
||||
evaluate("{1}.#isEven(#this[0]) == 'y'?'it is even':'it is odd'", "it is odd", String.class);
|
||||
@@ -389,10 +368,6 @@ public class EvaluationTests extends ExpressionTestCase {
|
||||
evaluate("@(apple).color.getRGB() == T(java.awt.Color).green.getRGB()", "true", Boolean.class);
|
||||
}
|
||||
|
||||
public void testReferences06b() {
|
||||
evaluate("(#t='Color';@(apple).color.getRGB() == T(java.awt.Color).green.getRGB())", "true", Boolean.class);
|
||||
}
|
||||
|
||||
public void testReferences07() {
|
||||
evaluate("@(apple).color.getRGB().equals(T(java.awt.Color).green.getRGB())", "true", Boolean.class);
|
||||
}
|
||||
@@ -424,49 +399,46 @@ public class EvaluationTests extends ExpressionTestCase {
|
||||
evaluate("{|| true }", "{|| true }", Lambda.class);
|
||||
}
|
||||
|
||||
public void testLambdaNoArgsReferenced() {
|
||||
evaluate("(#fn={|| false };#fn)", "{|| false }", Lambda.class, true);
|
||||
}
|
||||
|
||||
public void testLambda01() {
|
||||
evaluate("{|x,y| $x > $y ? $x : $y }", "{|x,y| ($x > $y) ? $x : $y }",
|
||||
org.springframework.expression.spel.ast.Lambda.class);
|
||||
}
|
||||
|
||||
public void testLambda02() {
|
||||
evaluate("(#max={|x,y| $x > $y ? $x : $y };true)", "true", Boolean.class);
|
||||
}
|
||||
|
||||
public void testLambdaMax() {
|
||||
evaluate("(#max = {|x,y| $x > $y ? $x : $y }; #max(5,25))", "25", Integer.class);
|
||||
}
|
||||
|
||||
public void testLambdaFactorial01() {
|
||||
evaluate("(#fact = {|n| $n <= 1 ? 1 : $n * #fact($n-1) }; #fact(5))", "120", Integer.class);
|
||||
}
|
||||
|
||||
public void testLambdaFactorial02() {
|
||||
evaluate("(#fact = {|n| $n <= 1 ? 1 : #fact($n-1) * $n }; #fact(5))", "120", Integer.class);
|
||||
}
|
||||
|
||||
public void testLambdaAlphabet01() {
|
||||
evaluate("(#alpha = {|l,s| $l>'z'?$s:#alpha($l+1,$s+$l)};#alphabet={||#alpha('a','')}; #alphabet())",
|
||||
"abcdefghijklmnopqrstuvwxyz", String.class);
|
||||
}
|
||||
|
||||
public void testLambdaAlphabet02() {
|
||||
evaluate("(#alphabet = {|l,s| $l>'z'?$s:#alphabet($l+1,$s+$l)};#alphabet('a',''))",
|
||||
"abcdefghijklmnopqrstuvwxyz", String.class);
|
||||
}
|
||||
|
||||
public void testLambdaDelegation01() {
|
||||
evaluate("(#sqrt={|n| T(Math).sqrt($n)};#delegate={|f,n| $f($n)};#delegate(#sqrt,4))", "2.0", Double.class);
|
||||
}
|
||||
|
||||
public void testVariableReferences() {
|
||||
evaluate("(#answer=42;#answer)", "42", Integer.class, true);
|
||||
evaluate("($answer=42;$answer)", "42", Integer.class, true);
|
||||
}
|
||||
//
|
||||
// public void testLambda02() {
|
||||
// evaluate("(#max={|x,y| $x > $y ? $x : $y };true)", "true", Boolean.class);
|
||||
// }
|
||||
//
|
||||
// public void testLambdaMax() {
|
||||
// evaluate("(#max = {|x,y| $x > $y ? $x : $y }; #max(5,25))", "25", Integer.class);
|
||||
// }
|
||||
//
|
||||
// public void testLambdaFactorial01() {
|
||||
// evaluate("(#fact = {|n| $n <= 1 ? 1 : $n * #fact($n-1) }; #fact(5))", "120", Integer.class);
|
||||
// }
|
||||
//
|
||||
// public void testLambdaFactorial02() {
|
||||
// evaluate("(#fact = {|n| $n <= 1 ? 1 : #fact($n-1) * $n }; #fact(5))", "120", Integer.class);
|
||||
// }
|
||||
//
|
||||
// public void testLambdaAlphabet01() {
|
||||
// evaluate("(#alpha = {|l,s| $l>'z'?$s:#alpha($l+1,$s+$l)};#alphabet={||#alpha('a','')}; #alphabet())",
|
||||
// "abcdefghijklmnopqrstuvwxyz", String.class);
|
||||
// }
|
||||
//
|
||||
// public void testLambdaAlphabet02() {
|
||||
// evaluate("(#alphabet = {|l,s| $l>'z'?$s:#alphabet($l+1,$s+$l)};#alphabet('a',''))",
|
||||
// "abcdefghijklmnopqrstuvwxyz", String.class);
|
||||
// }
|
||||
//
|
||||
// public void testLambdaDelegation01() {
|
||||
// evaluate("(#sqrt={|n| T(Math).sqrt($n)};#delegate={|f,n| $f($n)};#delegate(#sqrt,4))", "2.0", Double.class);
|
||||
// }
|
||||
//
|
||||
// public void testVariableReferences() {
|
||||
// evaluate("(#answer=42;#answer)", "42", Integer.class, true);
|
||||
// evaluate("($answer=42;$answer)", "42", Integer.class, true);
|
||||
// }
|
||||
|
||||
// type references
|
||||
public void testTypeReferences01() {
|
||||
|
||||
@@ -90,27 +90,27 @@ public class LiteralTests extends ExpressionTestCase {
|
||||
}
|
||||
|
||||
public void testLiteralReal01_CreatingDoubles() {
|
||||
evaluate("1.25",1.25d,Double.class);
|
||||
evaluate("2.99",2.99d,Double.class);
|
||||
evaluate("-3.141",-3.141d,Double.class);
|
||||
evaluate("1.25d",1.25d,Double.class);
|
||||
evaluate("2.99d",2.99d,Double.class);
|
||||
evaluate("-3.141d",-3.141d,Double.class);
|
||||
evaluate("1.25D",1.25d,Double.class);
|
||||
evaluate("2.99D",2.99d,Double.class);
|
||||
evaluate("-3.141D",-3.141d,Double.class);
|
||||
evaluate("1.25", 1.25d, Double.class);
|
||||
evaluate("2.99", 2.99d, Double.class);
|
||||
evaluate("-3.141", -3.141d, Double.class);
|
||||
evaluate("1.25d", 1.25d, Double.class);
|
||||
evaluate("2.99d", 2.99d, Double.class);
|
||||
evaluate("-3.141d", -3.141d, Double.class);
|
||||
evaluate("1.25D", 1.25d, Double.class);
|
||||
evaluate("2.99D", 2.99d, Double.class);
|
||||
evaluate("-3.141D", -3.141d, Double.class);
|
||||
}
|
||||
|
||||
public void testLiteralReal02_CreatingFloats() {
|
||||
// For now, everything becomes a double...
|
||||
evaluate("1.25f",1.25d,Double.class);
|
||||
evaluate("2.99f",2.99d,Double.class);
|
||||
evaluate("-3.141f",-3.141d,Double.class);
|
||||
evaluate("1.25F",1.25d,Double.class);
|
||||
evaluate("2.99F",2.99d,Double.class);
|
||||
evaluate("-3.141F",-3.141d,Double.class);
|
||||
evaluate("1.25f", 1.25d, Double.class);
|
||||
evaluate("2.99f", 2.99d, Double.class);
|
||||
evaluate("-3.141f", -3.141d, Double.class);
|
||||
evaluate("1.25F", 1.25d, Double.class);
|
||||
evaluate("2.99F", 2.99d, Double.class);
|
||||
evaluate("-3.141F", -3.141d, Double.class);
|
||||
}
|
||||
|
||||
|
||||
public void testLiteralReal03_UsingExponents() {
|
||||
evaluate("6.0221415E+23", "6.0221415E23", Double.class);
|
||||
evaluate("6.0221415e+23", "6.0221415E23", Double.class);
|
||||
@@ -121,10 +121,10 @@ public class LiteralTests extends ExpressionTestCase {
|
||||
}
|
||||
|
||||
public void testLiteralReal04_BadExpressions() {
|
||||
parseAndCheckError("6.1e23e22",SpelMessages.PARSE_PROBLEM,6,"mismatched input 'e22' expecting EOF");
|
||||
parseAndCheckError("6.1f23e22",SpelMessages.PARSE_PROBLEM,4,"mismatched input '23e22' expecting EOF");
|
||||
parseAndCheckError("6.1e23e22", SpelMessages.PARSE_PROBLEM, 6, "mismatched input 'e22' expecting EOF");
|
||||
parseAndCheckError("6.1f23e22", SpelMessages.PARSE_PROBLEM, 4, "mismatched input '23e22' expecting EOF");
|
||||
}
|
||||
|
||||
|
||||
public void testLiteralNull01() {
|
||||
evaluate("null", null, null);
|
||||
}
|
||||
@@ -156,10 +156,10 @@ public class LiteralTests extends ExpressionTestCase {
|
||||
// int year convertable from number to string
|
||||
parseAndCheckError("date(2008,'yyyy').getTime()>0", SpelMessages.PARSE_PROBLEM);
|
||||
}
|
||||
|
||||
|
||||
public void testConversions() {
|
||||
// getting the expression type to be what we want - either:
|
||||
evaluate("(#foo=37;#foo.byteValue())",(byte)37,Byte.class); // calling byteValue() on Integer.class
|
||||
evaluateAndAskForReturnType("(#foo=37;#foo)",(byte)37,Byte.class); // relying on registered type converters
|
||||
evaluate("new Integer(37).byteValue()", (byte) 37, Byte.class); // calling byteValue() on Integer.class
|
||||
evaluateAndAskForReturnType("new Integer(37)", (byte) 37, Byte.class); // relying on registered type converters
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,12 +35,6 @@ public class ParserErrorMessagesTests extends ExpressionTestCase {
|
||||
parseAndCheckError("0xB0BG", SpelMessages.PARSE_PROBLEM, 5, "mismatched input 'G' expecting EOF");
|
||||
}
|
||||
|
||||
public void testBrokenExpression03() {
|
||||
// too many closing brackets
|
||||
parseAndCheckError("((3;4;)+(5;6;)))", SpelMessages.PARSE_PROBLEM, 15, "mismatched input ')' expecting EOF");
|
||||
evaluate("((3;4;)+(5;6;))", 10 /* 4+6 */, Integer.class);
|
||||
}
|
||||
|
||||
public void testBrokenExpression04() {
|
||||
// missing right operand
|
||||
parseAndCheckError("true or ", SpelMessages.PARSE_PROBLEM, -1, "no viable alternative at input '<EOF>'"); // POOR
|
||||
@@ -51,21 +45,10 @@ public class ParserErrorMessagesTests extends ExpressionTestCase {
|
||||
parseAndCheckError("1 + ", SpelMessages.PARSE_PROBLEM, -1, "no viable alternative at input '<EOF>'"); // POOR
|
||||
}
|
||||
|
||||
public void testBrokenExpression06() {
|
||||
// expression list missing surrounding parentheses
|
||||
parseAndCheckError("1;2;3", SpelMessages.PARSE_PROBLEM, 1, "mismatched input ';' expecting EOF"); // POOR
|
||||
evaluate("(1;2;3)", 3, Integer.class);
|
||||
}
|
||||
|
||||
public void testBrokenExpression07() {
|
||||
// T() can only take an identifier (possibly qualified), not a literal
|
||||
// message ought to say identifier rather than ID
|
||||
parseAndCheckError("null is T('a')", SpelMessages.PARSE_PROBLEM, 10, "mismatched input ''a'' expecting ID"); // POOR
|
||||
}
|
||||
|
||||
public void testExpressionLists02a() {
|
||||
// either missing semi or rogue 5. RPAREN should at least be ')', and why doesn't it give the other possibles?
|
||||
parseAndCheckError("( (3;4)5)", SpelMessages.PARSE_PROBLEM, 7, "mismatched input '5' expecting RPAREN"); // POOR
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.expression.ParseException;
|
||||
/**
|
||||
* Parse some expressions and check we get the AST we expect. Rather than inspecting each node in the AST, we ask it to
|
||||
* write itself to a string form and check that is as expected.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class ParsingTests extends TestCase {
|
||||
@@ -360,14 +360,15 @@ public class ParsingTests extends TestCase {
|
||||
parseCheck("{|x,y| $x > $y ? $x : $y }", "{|x,y| ($x > $y) ? $x : $y }");
|
||||
}
|
||||
|
||||
public void testLambdaMax() {
|
||||
parseCheck("(#max = {|x,y| $x > $y ? $x : $y }; #max(5,25))", "(#max={|x,y| ($x > $y) ? $x : $y };#max(5,25))");
|
||||
}
|
||||
|
||||
public void testLambdaFactorial() {
|
||||
parseCheck("(#fact = {|n| $n <= 1 ? 1 : $n * #fact($n-1) }; #fact(5))",
|
||||
"(#fact={|n| ($n <= 1) ? 1 : ($n * #fact(($n - 1))) };#fact(5))");
|
||||
} // 120
|
||||
//
|
||||
// public void testLambdaMax() {
|
||||
// parseCheck("(#max = {|x,y| $x > $y ? $x : $y }; #max(5,25))", "(#max={|x,y| ($x > $y) ? $x : $y };#max(5,25))");
|
||||
// }
|
||||
//
|
||||
// public void testLambdaFactorial() {
|
||||
// parseCheck("(#fact = {|n| $n <= 1 ? 1 : $n * #fact($n-1) }; #fact(5))",
|
||||
// "(#fact={|n| ($n <= 1) ? 1 : ($n * #fact(($n - 1))) };#fact(5))");
|
||||
// } // 120
|
||||
|
||||
// Type references
|
||||
public void testTypeReferences01() {
|
||||
@@ -378,39 +379,10 @@ public class ParsingTests extends TestCase {
|
||||
parseCheck("T(String)");
|
||||
}
|
||||
|
||||
// Nesting expressions and expression lists
|
||||
public void testExpressionLists01() {
|
||||
parseCheck("(3;4;5)");
|
||||
}
|
||||
|
||||
public void testExpressionLists02() {
|
||||
parseCheck("( (3;4);5)", "((3;4);5)");
|
||||
}
|
||||
|
||||
public void testExpressionLists03() {
|
||||
parseCheck("(3;(4;5))");
|
||||
}
|
||||
|
||||
public void testExpressionLists04() {
|
||||
parseCheck("((3;4;5))", "(3;4;5)");
|
||||
}
|
||||
|
||||
public void testExpressionLists05() {
|
||||
parseCheck("((3;4)+(5;6))", "((3;4) + (5;6))");
|
||||
}
|
||||
|
||||
public void testExpressionLists06() {
|
||||
parseCheck("((3;4;)+(5;6))", "((3;4) + (5;6))");
|
||||
}
|
||||
|
||||
public void testExpressionLists07() {
|
||||
parseCheck("((3;4;)+(5;6;))", "((3;4) + (5;6))");
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the supplied expression and then create a string representation of the resultant AST, it should be the same
|
||||
* as the original expression.
|
||||
*
|
||||
*
|
||||
* @param expression the expression to parse *and* the expected value of the string form of the resultant AST
|
||||
*/
|
||||
public void parseCheck(String expression) {
|
||||
@@ -420,7 +392,7 @@ public class ParsingTests extends TestCase {
|
||||
/**
|
||||
* Parse the supplied expression and then create a string representation of the resultant AST, it should be the
|
||||
* expected value.
|
||||
*
|
||||
*
|
||||
* @param expression the expression to parse
|
||||
* @param expectedStringFormOfAST the expected string form of the AST
|
||||
*/
|
||||
|
||||
@@ -26,7 +26,6 @@ public class VariableAndFunctionTests extends ExpressionTestCase {
|
||||
|
||||
public void testVariableAccess() {
|
||||
evaluate("#answer", "42", Integer.class, SHOULD_BE_WRITABLE);
|
||||
evaluate("(#i=5;#i)", 5, Integer.class, SHOULD_BE_WRITABLE);
|
||||
evaluate("#answer / 2", 21, Integer.class, SHOULD_NOT_BE_WRITABLE);
|
||||
}
|
||||
|
||||
@@ -40,40 +39,43 @@ public class VariableAndFunctionTests extends ExpressionTestCase {
|
||||
evaluate("#reverseString('hello')", "olleh", String.class);
|
||||
evaluate("#reverseString(37)", "73", String.class); // requires type conversion of 37 to '37'
|
||||
}
|
||||
|
||||
|
||||
public void testCallVarargsFunction() {
|
||||
evaluate("#varargsFunctionReverseStringsAndMerge('a','b','c')","cba",String.class);
|
||||
evaluate("#varargsFunctionReverseStringsAndMerge('a')","a",String.class);
|
||||
evaluate("#varargsFunctionReverseStringsAndMerge()","",String.class);
|
||||
evaluate("#varargsFunctionReverseStringsAndMerge('b',25)","25b",String.class);
|
||||
evaluate("#varargsFunctionReverseStringsAndMerge(25)","25",String.class);
|
||||
evaluate("#varargsFunctionReverseStringsAndMerge2(1,'a','b','c')","1cba",String.class);
|
||||
evaluate("#varargsFunctionReverseStringsAndMerge2(2,'a')","2a",String.class);
|
||||
evaluate("#varargsFunctionReverseStringsAndMerge2(3)","3",String.class);
|
||||
evaluate("#varargsFunctionReverseStringsAndMerge2(4,'b',25)","425b",String.class);
|
||||
evaluate("#varargsFunctionReverseStringsAndMerge2(5,25)","525",String.class);
|
||||
evaluate("#varargsFunctionReverseStringsAndMerge('a','b','c')", "cba", String.class);
|
||||
evaluate("#varargsFunctionReverseStringsAndMerge('a')", "a", String.class);
|
||||
evaluate("#varargsFunctionReverseStringsAndMerge()", "", String.class);
|
||||
evaluate("#varargsFunctionReverseStringsAndMerge('b',25)", "25b", String.class);
|
||||
evaluate("#varargsFunctionReverseStringsAndMerge(25)", "25", String.class);
|
||||
evaluate("#varargsFunctionReverseStringsAndMerge2(1,'a','b','c')", "1cba", String.class);
|
||||
evaluate("#varargsFunctionReverseStringsAndMerge2(2,'a')", "2a", String.class);
|
||||
evaluate("#varargsFunctionReverseStringsAndMerge2(3)", "3", String.class);
|
||||
evaluate("#varargsFunctionReverseStringsAndMerge2(4,'b',25)", "425b", String.class);
|
||||
evaluate("#varargsFunctionReverseStringsAndMerge2(5,25)", "525", String.class);
|
||||
}
|
||||
|
||||
|
||||
public void testCallingFunctionsIncorrectly() {
|
||||
evaluateAndCheckError("#varargsFunctionReverseStringsAndMerge(new StringBuilder())",SpelMessages.TYPE_CONVERSION_ERROR);
|
||||
evaluateAndCheckError("#varargsFunctionReverseStringsAndMerge(new StringBuilder())",
|
||||
SpelMessages.TYPE_CONVERSION_ERROR);
|
||||
}
|
||||
|
||||
|
||||
public void testCallingIllegalFunctions() throws Exception {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
StandardEvaluationContext ctx = new StandardEvaluationContext();
|
||||
ctx.setVariable("notStatic",this.getClass().getMethod("nonStatic"));
|
||||
ctx.setVariable("notStatic", this.getClass().getMethod("nonStatic"));
|
||||
try {
|
||||
@SuppressWarnings("unused")
|
||||
Object v = parser.parseExpression("#notStatic()").getValue(ctx);
|
||||
fail("Should have failed with exception - cannot call non static method that way");
|
||||
} catch (SpelException se) {
|
||||
if (se.getMessageUnformatted()!=SpelMessages.FUNCTION_MUST_BE_STATIC) {
|
||||
if (se.getMessageUnformatted() != SpelMessages.FUNCTION_MUST_BE_STATIC) {
|
||||
se.printStackTrace();
|
||||
fail("Should have failed a message about the function needing to be static, not: "+se.getMessageUnformatted());
|
||||
fail("Should have failed a message about the function needing to be static, not: "
|
||||
+ se.getMessageUnformatted());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void nonStatic() {}
|
||||
|
||||
|
||||
public void nonStatic() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user