commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject cvs commit: jakarta-commons-sandbox/jexl/src/test/org/apache/commons/jexl/parser ParserTest.java
Date Fri, 07 Jun 2002 03:37:07 GMT
geirm       2002/06/06 20:37:07

  Modified:    jexl/src/test/org/apache/commons/jexl JexlTest.java
               jexl/src/test/org/apache/commons/jexl/parser ParserTest.java
  Log:
  add tests for [] and foo.bar.1
  
  Revision  Changes    Path
  1.10      +78 -1     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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- JexlTest.java	25 May 2002 18:40:44 -0000	1.9
  +++ JexlTest.java	7 Jun 2002 03:37:07 -0000	1.10
  @@ -71,13 +71,19 @@
    *  Simple testcases
    *
    *  @author <a href="mailto:geirm@apache.org">Geir Magnusson Jr.</a>
  - *  @version $Id: JexlTest.java,v 1.9 2002/05/25 18:40:44 geirm Exp $
  + *  @version $Id: JexlTest.java,v 1.10 2002/06/07 03:37:07 geirm Exp $
    */
   public class JexlTest extends TestCase
   {
       protected static final String METHOD_STRING = "Method string";
       protected static final String GET_METHOD_STRING = "GetMethod string";
   
  +    protected static final String[] GET_METHOD_ARRAY =
  +        new String[] { "One", "Two", "Three" };
  +
  +    protected static final String[][] GET_METHOD_ARRAY2 =
  +        new String[][] { {"One", "Two", "Three"},{"Four", "Five", "Six"} };
  +
       public static Test suite()
       {
           return new TestSuite(JexlTest.class);
  @@ -586,6 +592,27 @@
       }
   
       /**
  +     *  Tests string literals
  +     */
  +    public void testStringLiterals()
  +        throws Exception
  +    {
  +        Expression e = ExpressionFactory.createExpression("foo == \"bar\"");
  +        JexlContext jc = JexlHelper.createContext();
  +
  +        jc.getVars().put("foo", "bar" );
  +
  +        Object o = e.evaluate(jc);
  +
  +        assertTrue("o incorrect", Boolean.TRUE.equals(o));
  +
  +        e = ExpressionFactory.createExpression("foo == 'bar'");
  +        o = e.evaluate(jc);
  +
  +        assertTrue("o incorrect", Boolean.TRUE.equals(o));
  +    }
  +
  +    /**
         *  test the use of an int based property
         */
       public void testIntProperty()
  @@ -602,6 +629,46 @@
           assertEquals("o incorrect", new Integer(5), o);
       }
   
  +    public void testArrayProperty()
  +        throws Exception
  +    {
  +        Expression bracketForm =
  +            ExpressionFactory.createExpression("foo.array[1]");
  +
  +        Expression dotForm =
  +            ExpressionFactory.createExpression("foo.array.1");
  +
  +        JexlContext jc = JexlHelper.createContext();
  +
  +        Foo foo = new Foo();
  +
  +        jc.getVars().put("foo", foo );
  +
  +        Object o1 = bracketForm.evaluate(jc);
  +        assertEquals("bracket form failed", GET_METHOD_ARRAY[1], o1);
  +
  +        Object o2 = dotForm.evaluate(jc);
  +        assertEquals("dot form failed", GET_METHOD_ARRAY[1], o2);
  +
  +
  +        bracketForm =
  +            ExpressionFactory.createExpression("foo.array2[1][1]");
  +
  +//        dotForm =
  +//            ExpressionFactory.createExpression("foo.array2.1.1");
  +
  +        jc = JexlHelper.createContext();
  +
  +        jc.getVars().put("foo", foo );
  +
  +        o1 = bracketForm.evaluate(jc);
  +        assertEquals("bracket form failed", GET_METHOD_ARRAY2[1][1], o1);
  +
  +//        o2 = dotForm.evaluate(jc);
  +//        assertEquals("dot form failed", GET_METHOD_ARRAY2[1][1], o2);
  +    }
  +
  +
       public class Foo
       {
           public String bar()
  @@ -631,6 +698,16 @@
           
           public int getCount() {
               return 5;
  +        }
  +
  +        public String[] getArray()
  +        {
  +            return GET_METHOD_ARRAY;
  +        }
  +
  +        public String[][] getArray2()
  +        {
  +            return GET_METHOD_ARRAY2;
           }
       }
   
  
  
  
  1.2       +13 -0     jakarta-commons-sandbox/jexl/src/test/org/apache/commons/jexl/parser/ParserTest.java
  
  Index: ParserTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jexl/src/test/org/apache/commons/jexl/parser/ParserTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ParserTest.java	26 Apr 2002 04:46:27 -0000	1.1
  +++ ParserTest.java	7 Jun 2002 03:37:07 -0000	1.2
  @@ -39,6 +39,19 @@
            sn.interpret(jc);
        }
   
  +    public void testParse2()
  +        throws Exception
  +    {
  +        Parser parser = new Parser(new StringReader(";"));
  +
  +        JexlContext jc = JexlHelper.createContext();
  +
  +        SimpleNode sn = parser.parse(new StringReader("foo = \"bar\";"));
  +        sn.interpret(jc);
  +        sn = parser.parse(new StringReader("foo = 'bar';"));
  +        sn.interpret(jc);
  +    }
  +
       public static void main(String[] args)
           throws Exception
       {
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message