From: markt Date: Wed, 24 Dec 2008 15:11:07 +0000 (+0000) Subject: Add some unit tests for the EL parser based on some recent bugs X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=e915f5ffce0f4ebda8286fdc0d227e8848e10087;p=tomcat7.0 Add some unit tests for the EL parser based on some recent bugs git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@729318 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/test/org/apache/el/parser/TestELParser.java b/test/org/apache/el/parser/TestELParser.java new file mode 100644 index 000000000..9ea2c54da --- /dev/null +++ b/test/org/apache/el/parser/TestELParser.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.el.parser; + +import javax.el.ValueExpression; + +import org.apache.el.ExpressionFactoryImpl; +import org.apache.jasper.el.ELContextImpl; + +import junit.framework.TestCase; + +public class TestELParser extends TestCase { + + public void testBug45511() { + // Test cases provided by OP + assertEquals("true", evaluateExpression("${empty ('')}")); + assertEquals("true", evaluateExpression("${empty('')}")); + assertEquals("false", evaluateExpression("${(true) and (false)}")); + assertEquals("false", evaluateExpression("${(true)and(false)}")); + } + + + public void testBug42565() { + // Test cases provided by OP + assertEquals("false", evaluateExpression("${false?true:false}")); + } + + + public void testMisc() { + // From bug 45451 - not a parser bug + assertEquals("\\", evaluateExpression("\\\\")); + } + + + private String evaluateExpression(String expression) { + ELContextImpl ctx = new ELContextImpl(); + ExpressionFactoryImpl exprFactory = new ExpressionFactoryImpl(); + ValueExpression ve = + exprFactory.createValueExpression(ctx, expression, String.class ); + return (String) ve.getValue(ctx); + } +}