001: /*
002: * Copyright 2006 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.jexl;
017:
018: import junit.framework.TestCase;
019:
020: import org.apache.commons.jexl.parser.ParseException;
021:
022: /**
023: * Tests for malformed expressions and scripts.
024: * ({@link ExpressionFactory} and {@link ScriptFactory} should throw
025: * {@link ParseException}s).
026: *
027: * @since 1.1
028: */
029: public class ParseFailuresTest extends TestCase {
030:
031: /**
032: * Create the test.
033: *
034: * @param testName name of the test
035: */
036: public ParseFailuresTest(String testName) {
037: super (testName);
038: }
039:
040: public void testMalformedExpression1() throws Exception {
041: // this will throw a ParseException
042: String badExpression = "eq";
043: try {
044: Expression e = ExpressionFactory
045: .createExpression(badExpression);
046: fail("Parsing \"" + badExpression
047: + "\" should result in a ParseException");
048: } catch (ParseException pe) {
049: // expected
050: }
051: }
052:
053: public void testMalformedExpression2() throws Exception {
054: // this will throw a TokenMgrErr, which we rethrow as a ParseException
055: String badExpression = "?";
056: try {
057: Expression e = ExpressionFactory
058: .createExpression(badExpression);
059: fail("Parsing \"" + badExpression
060: + "\" should result in a ParseException");
061: } catch (ParseException pe) {
062: // expected
063: }
064: }
065:
066: public void testMalformedScript1() throws Exception {
067: // this will throw a TokenMgrErr, which we rethrow as a ParseException
068: String badScript = "eq";
069: try {
070: Script s = ScriptFactory.createScript(badScript);
071: fail("Parsing \"" + badScript
072: + "\" should result in a ParseException");
073: } catch (ParseException pe) {
074: // expected
075: }
076: }
077:
078: public void testMalformedScript2() throws Exception {
079: // this will throw a TokenMgrErr, which we rethrow as a ParseException
080: String badScript = "?";
081: try {
082: Script s = ScriptFactory.createScript(badScript);
083: fail("Parsing \"" + badScript
084: + "\" should result in a ParseException");
085: } catch (ParseException pe) {
086: // expected
087: }
088: }
089:
090: public void testMalformedScript3() throws Exception {
091: // this will throw a TokenMgrErr, which we rethrow as a ParseException
092: String badScript = "foo=1;bar=2;a?b:c;";
093: try {
094: Script s = ScriptFactory.createScript(badScript);
095: fail("Parsing \"" + badScript
096: + "\" should result in a ParseException");
097: } catch (ParseException pe) {
098: // expected
099: }
100: }
101:
102: }
|