Add some unit tests for the EL parser based on some recent bugs
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 24 Dec 2008 15:11:07 +0000 (15:11 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 24 Dec 2008 15:11:07 +0000 (15:11 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@729318 13f79535-47bb-0310-9956-ffa450edef68

test/org/apache/el/parser/TestELParser.java [new file with mode: 0644]

diff --git a/test/org/apache/el/parser/TestELParser.java b/test/org/apache/el/parser/TestELParser.java
new file mode 100644 (file)
index 0000000..9ea2c54
--- /dev/null
@@ -0,0 +1,57 @@
+/*\r
+ * Licensed to the Apache Software Foundation (ASF) under one or more\r
+ * contributor license agreements.  See the NOTICE file distributed with\r
+ * this work for additional information regarding copyright ownership.\r
+ * The ASF licenses this file to You under the Apache License, Version 2.0\r
+ * (the "License"); you may not use this file except in compliance with\r
+ * the License.  You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.apache.el.parser;\r
+\r
+import javax.el.ValueExpression;\r
+\r
+import org.apache.el.ExpressionFactoryImpl;\r
+import org.apache.jasper.el.ELContextImpl;\r
+\r
+import junit.framework.TestCase;\r
+\r
+public class TestELParser extends TestCase {\r
+    \r
+    public void testBug45511() {\r
+        // Test cases provided by OP\r
+        assertEquals("true", evaluateExpression("${empty ('')}"));\r
+        assertEquals("true", evaluateExpression("${empty('')}"));\r
+        assertEquals("false", evaluateExpression("${(true) and (false)}"));\r
+        assertEquals("false", evaluateExpression("${(true)and(false)}"));\r
+    }\r
+    \r
+\r
+    public void testBug42565() {\r
+        // Test cases provided by OP\r
+        assertEquals("false", evaluateExpression("${false?true:false}"));\r
+    }\r
+\r
+\r
+    public void testMisc() {\r
+        // From bug 45451 - not a parser bug\r
+        assertEquals("\\", evaluateExpression("\\\\"));\r
+    }\r
+    \r
+\r
+    private String evaluateExpression(String expression) {\r
+        ELContextImpl ctx = new ELContextImpl();\r
+        ExpressionFactoryImpl exprFactory = new ExpressionFactoryImpl();\r
+        ValueExpression ve =\r
+            exprFactory.createValueExpression(ctx, expression, String.class );\r
+        return (String) ve.getValue(ctx);\r
+    }\r
+}\r