jstrachan 2002/10/10 06:51:36
Modified: jexl/src/test/org/apache/commons/jexl JexlTest.java
Log:
Added a few more test cases
Revision Changes Path
1.19 +44 -8 jakarta-commons-sandbox/jexl/src/test/org/apache/commons/jexl/JexlTest.java
Index: JexlTest.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jexl/src/test/org/apache/commons/jexl/JexlTest.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- JexlTest.java 10 Oct 2002 11:09:32 -0000 1.18
+++ JexlTest.java 10 Oct 2002 13:51:36 -0000 1.19
@@ -409,7 +409,7 @@
throws Exception
{
JexlContext jc = JexlHelper.createContext();
- jc.getVars().put("string", "five!");
+ jc.getVars().put("s", "five!");
jc.getVars().put("array", new Object[5]);
Map map = new HashMap();
@@ -432,7 +432,7 @@
jc.getVars().put("list", list);
- assertExpression(jc, "size(string)", new Integer(5));
+ assertExpression(jc, "size(s)", new Integer(5));
assertExpression(jc, "size(array)", new Integer(5));
assertExpression(jc, "size(list)", new Integer(5));
assertExpression(jc, "size(map)", new Integer(5));
@@ -795,10 +795,7 @@
assertTrue("o incorrect", Boolean.TRUE.equals(o));
- e = ExpressionFactory.createExpression("foo == 'bar'");
- o = e.evaluate(jc);
-
- assertTrue("o incorrect", Boolean.TRUE.equals(o));
+ assertExpression(jc, "foo == 'bar'", Boolean.TRUE);
}
/**
@@ -811,11 +808,18 @@
JexlContext jc = JexlHelper.createContext();
Foo foo = new Foo();
-
+
+ // lets check the square function first..
+ assertEquals(4, foo.square(2));
+ assertEquals(4, foo.square(-2));
+
jc.getVars().put("foo", foo );
Object o = e.evaluate(jc);
assertEquals("o incorrect", new Integer(5), o);
+
+ assertExpression(jc, "foo.square(-2)", new Integer(4));
+ assertExpression(jc, "foo.square(2)", new Integer(4));
}
public void testArrayProperty()
@@ -857,6 +861,33 @@
// assertEquals("dot form failed", GET_METHOD_ARRAY2[1][1], o2);
}
+ /**
+ * Attempts to recreate bug http://jira.werken.com/ViewIssue.jspa?key=JELLY-8
+ */
+ public void testCharAtBug()
+ throws Exception
+ {
+ JexlContext jc = JexlHelper.createContext();
+
+ Foo foo = new Foo();
+
+ jc.getVars().put("s", "abc");
+
+ assertExpression(jc, "s.charAt(2)", new Character('b'));
+
+ try {
+ assertExpression(jc, "s.charAt(-2)", null);
+ fail("this test should have thrown an exception" );
+ }
+ catch (IndexOutOfBoundsException e) {
+ // expected behaviour
+ }
+ catch (Exception e) {
+ throw e;
+ }
+ }
+
+
public void testResolver()
throws Exception
{
@@ -961,6 +992,11 @@
public boolean isSimple()
{
return true;
+ }
+
+ public int square(int value)
+ {
+ return value * value;
}
}
--
To unsubscribe, e-mail: <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>
|