fixing TODOs

This commit is contained in:
Andy Clement 2008-08-17 01:26:11 +00:00
parent 9e7cb0e1cf
commit 80075f18ce
1 changed files with 23 additions and 24 deletions

View File

@ -43,7 +43,6 @@ public class MethodInvocationTests extends ExpressionTestCase {
public void testStringClass() {
evaluate("new java.lang.String('hello').charAt(2)", 'l', Character.class);
// TODO 3 hmmm, have to do the second charAt() because all '' are strings, never chars and cannot do cast
evaluate("new java.lang.String('hello').charAt(2).equals('l'.charAt(0))", true, Boolean.class);
evaluate("'HELLO'.toLowerCase()", "hello", String.class);
evaluate("' abcba '.trim()", "abcba", String.class);
@ -66,29 +65,29 @@ public class MethodInvocationTests extends ExpressionTestCase {
evaluate("new String('hello 2.0 to you').startsWith(7.0d)", false, Boolean.class);
evaluate("new String('7.0 foobar').startsWith(7.0d)", true, Boolean.class);
}
public void testVarargsInvocation01() {
// Calling 'public int aVarargsMethod(String... strings)'
evaluate("aVarargsMethod('a','b','c')",3,Integer.class);
evaluate("aVarargsMethod('a')",1,Integer.class);
evaluate("aVarargsMethod()",0,Integer.class);
evaluate("aVarargsMethod(1,2,3)",3,Integer.class); // all need converting to strings
evaluate("aVarargsMethod(1)",1,Integer.class); // needs string conversion
evaluate("aVarargsMethod(1,'a',3.0d)",3,Integer.class); // first and last need conversion
evaluate("aVarargsMethod(new String[]{'a','b','c'})",3,Integer.class);
evaluate("aVarargsMethod('a','b','c')", 3, Integer.class);
evaluate("aVarargsMethod('a')", 1, Integer.class);
evaluate("aVarargsMethod()", 0, Integer.class);
evaluate("aVarargsMethod(1,2,3)", 3, Integer.class); // all need converting to strings
evaluate("aVarargsMethod(1)", 1, Integer.class); // needs string conversion
evaluate("aVarargsMethod(1,'a',3.0d)", 3, Integer.class); // first and last need conversion
evaluate("aVarargsMethod(new String[]{'a','b','c'})", 3, Integer.class);
}
public void testVarargsInvocation02() {
// Calling 'public int aVarargsMethod2(int i, String... strings)' - returns int+length_of_strings
evaluate("aVarargsMethod2(5,'a','b','c')",8,Integer.class);
evaluate("aVarargsMethod2(2,'a')",3,Integer.class);
evaluate("aVarargsMethod2(4)",4,Integer.class);
evaluate("aVarargsMethod2(8,2,3)",10,Integer.class);
evaluate("aVarargsMethod2(9)",9,Integer.class);
evaluate("aVarargsMethod2(2,'a',3.0d)",4,Integer.class);
evaluate("aVarargsMethod2(8,new String[]{'a','b','c'})",11,Integer.class);
evaluate("aVarargsMethod2(5,'a','b','c')", 8, Integer.class);
evaluate("aVarargsMethod2(2,'a')", 3, Integer.class);
evaluate("aVarargsMethod2(4)", 4, Integer.class);
evaluate("aVarargsMethod2(8,2,3)", 10, Integer.class);
evaluate("aVarargsMethod2(9)", 9, Integer.class);
evaluate("aVarargsMethod2(2,'a',3.0d)", 4, Integer.class);
evaluate("aVarargsMethod2(8,new String[]{'a','b','c'})", 11, Integer.class);
}
// Due to conversion there are two possible methods to call ...
public void testVarargsInvocation03() throws Exception {
// Calling 'm(String... strings)' and 'm(int i,String... strings)'
@ -96,15 +95,15 @@ public class MethodInvocationTests extends ExpressionTestCase {
SpelExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext ctx = new StandardEvaluationContext();
ctx.setClasspath("target/test-classes/testcode.jar");
Object v = null;
v = parser.parseExpression("new TestType().m(1,2,3)").getValue(ctx);
// v = parser.parseExpression("new TestType().m('a','b','c')").getValue(ctx);
// v = parser.parseExpression("new TestType().m(5,'a','b','c')").getValue(ctx);
// v = parser.parseExpression("new TestType().m()").getValue(ctx);
// v = parser.parseExpression("new TestType().m(1)").getValue(ctx);
// v = parser.parseExpression("new TestType().m(1,'a',3.0d)").getValue(ctx);
// v = parser.parseExpression("new TestType().m(new String[]{'a','b','c'})").getValue(ctx);
// v = parser.parseExpression("new TestType().m('a','b','c')").getValue(ctx);
// v = parser.parseExpression("new TestType().m(5,'a','b','c')").getValue(ctx);
// v = parser.parseExpression("new TestType().m()").getValue(ctx);
// v = parser.parseExpression("new TestType().m(1)").getValue(ctx);
// v = parser.parseExpression("new TestType().m(1,'a',3.0d)").getValue(ctx);
// v = parser.parseExpression("new TestType().m(new String[]{'a','b','c'})").getValue(ctx);
fail("Should have detected ambiguity, there are two possible matches");
} catch (EvaluationException ee) {
}