Author: grobmeier Date: Tue Jun 16 04:32:59 2009 New Revision: 785074 URL: http://svn.apache.org/viewvc?rev=785074&view=rev Log: added svn:eol-style native
Modified: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Arithmetic.java (props changed) commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Debugger.java (props changed) commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Interpreter.java (props changed) commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/JexlArithmetic.java (props changed) commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/JexlEngine.java (props changed) commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/JexlException.java (props changed) commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/parser/JEXLNode.java (props changed) commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/parser/VisitorAdapter.java (props changed) commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/ArrayListWrapper.java (contents, props changed) commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/MapGetExecutor.java (props changed) commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/introspection/IntrospectionUtils.java (contents, props changed) commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ArithmeticTest.java (contents, props changed) commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ArrayAccessTest.java (contents, props changed) commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/AssignTest.java (props changed) commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/MethodTest.java (contents, props changed) commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ParseFailuresTest.java (props changed) commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/util/introspection/MethodKeyTest.java (props changed) Propchange: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Arithmetic.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Debugger.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/Interpreter.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/JexlArithmetic.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/JexlEngine.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/JexlException.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/parser/JEXLNode.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/parser/VisitorAdapter.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/ArrayListWrapper.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/ArrayListWrapper.java?rev=785074&r1=785073&r2=785074&view=diff ============================================================================== --- commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/ArrayListWrapper.java (original) +++ commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/ArrayListWrapper.java Tue Jun 16 04:32:59 2009 @@ -1,58 +1,58 @@ -/* - * 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.commons.jexl.util; - -import java.lang.reflect.Array; -import java.util.AbstractList; - -/** - * A class that wraps an array with a List interface. - * - * @author Chris Schultz <ch...@christopherschultz.net$gt; - * @version $Revision$ $Date: 2006-04-14 19:40:41 $ - */ -public class ArrayListWrapper extends AbstractList { - /** the array to wrap. */ - private Object array; - - /** - * Create the wrapper. - * @param array {...@link #array} - */ - // CSOFF: HiddenField - public ArrayListWrapper(Object array) { - this.array = array; - } - // CSON: HiddenField - - /** {...@inheritdoc} */ - public Object get(int index) { - return Array.get(array, index); - } - - /** {...@inheritdoc} */ - public Object set(int index, Object element) { - Object old = get(index); - Array.set(array, index, element); - return old; - } - - /** {...@inheritdoc} */ - public int size() { - return Array.getLength(array); - } -} +/* + * 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.commons.jexl.util; + +import java.lang.reflect.Array; +import java.util.AbstractList; + +/** + * A class that wraps an array with a List interface. + * + * @author Chris Schultz <ch...@christopherschultz.net$gt; + * @version $Revision$ $Date: 2006-04-14 19:40:41 $ + */ +public class ArrayListWrapper extends AbstractList { + /** the array to wrap. */ + private Object array; + + /** + * Create the wrapper. + * @param array {...@link #array} + */ + // CSOFF: HiddenField + public ArrayListWrapper(Object array) { + this.array = array; + } + // CSON: HiddenField + + /** {...@inheritdoc} */ + public Object get(int index) { + return Array.get(array, index); + } + + /** {...@inheritdoc} */ + public Object set(int index, Object element) { + Object old = get(index); + Array.set(array, index, element); + return old; + } + + /** {...@inheritdoc} */ + public int size() { + return Array.getLength(array); + } +} Propchange: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/ArrayListWrapper.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/MapGetExecutor.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/introspection/IntrospectionUtils.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/introspection/IntrospectionUtils.java?rev=785074&r1=785073&r2=785074&view=diff ============================================================================== --- commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/introspection/IntrospectionUtils.java (original) +++ commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/introspection/IntrospectionUtils.java Tue Jun 16 04:32:59 2009 @@ -1,172 +1,172 @@ -/* - * 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.commons.jexl.util.introspection; - -/** - * @author <a href="mailto:jvan...@apache.org">Jason van Zyl</a> - * @author <a href="mailto:b...@werken.com">Bob McWhirter</a> - * @author <a href="mailto:christoph.r...@dlr.de">Christoph Reck</a> - * @author <a href="mailto:ge...@optonline.net">Geir Magnusson Jr.</a> - * @author <a href="mailto:szege...@freemail.hu">Attila Szegedi</a> - * @author Nathan Bubna - * @version $Id: IntrospectionUtils.java 476785 2006-11-19 10:06:21Z henning $ - */ -public class IntrospectionUtils { - - /** - * Determines whether a type represented by a class object is - * convertible to another type represented by a class object using a - * method invocation conversion, treating object types of primitive - * types as if they were primitive types (that is, a Boolean actual - * parameter type matches boolean primitive formal type). This behavior - * is because this method is used to determine applicable methods for - * an actual parameter list, and primitive types are represented by - * their object duals in reflective method calls. - * - * @param formal the formal parameter type to which the actual - * parameter type should be convertible - * @param actual the actual parameter type. - * @param possibleVarArg whether or not we're dealing with the last parameter - * in the method declaration - * @return true if either formal type is assignable from actual type, - * or formal is a primitive type and actual is its corresponding object - * type or an object type of a primitive type that can be converted to - * the formal type. - */ - public static boolean isMethodInvocationConvertible(Class formal, - Class actual, - boolean possibleVarArg) { - /* if it's a null, it means the arg was null */ - if (actual == null && !formal.isPrimitive()) { - return true; - } - - /* Check for identity or widening reference conversion */ - if (actual != null && formal.isAssignableFrom(actual)) { - return true; - } - - // CSOFF: NeedBraces - /* Check for boxing with widening primitive conversion. Note that - * actual parameters are never primitives. */ - if (formal.isPrimitive()) { - if (formal == Boolean.TYPE && actual == Boolean.class) - return true; - if (formal == Character.TYPE && actual == Character.class) - return true; - if (formal == Byte.TYPE && actual == Byte.class) - return true; - if (formal == Short.TYPE - && (actual == Short.class || actual == Byte.class)) - return true; - if (formal == Integer.TYPE - && (actual == Integer.class || actual == Short.class - || actual == Byte.class)) - return true; - if (formal == Long.TYPE - && (actual == Long.class || actual == Integer.class - || actual == Short.class || actual == Byte.class)) - return true; - if (formal == Float.TYPE - && (actual == Float.class || actual == Long.class - || actual == Integer.class || actual == Short.class - || actual == Byte.class)) - return true; - if (formal == Double.TYPE - && (actual == Double.class || actual == Float.class - || actual == Long.class || actual == Integer.class - || actual == Short.class || actual == Byte.class)) - return true; - } - // CSON: NeedBraces - - /* Check for vararg conversion. */ - if (possibleVarArg && formal.isArray()) { - if (actual.isArray()) { - actual = actual.getComponentType(); - } - return isMethodInvocationConvertible(formal.getComponentType(), - actual, false); - } - return false; - } - - /** - * Determines whether a type represented by a class object is - * convertible to another type represented by a class object using a - * method invocation conversion, without matching object and primitive - * types. This method is used to determine the more specific type when - * comparing signatures of methods. - * - * @param formal the formal parameter type to which the actual - * parameter type should be convertible - * @param actual the actual parameter type. - * @param possibleVarArg whether or not we're dealing with the last parameter - * in the method declaration - * @return true if either formal type is assignable from actual type, - * or formal and actual are both primitive types and actual can be - * subject to widening conversion to formal. - */ - public static boolean isStrictMethodInvocationConvertible(Class formal, - Class actual, - boolean possibleVarArg) { - /* we shouldn't get a null into, but if so */ - if (actual == null && !formal.isPrimitive()) { - return true; - } - - /* Check for identity or widening reference conversion */ - if (formal.isAssignableFrom(actual)) { - return true; - } - - // CSOFF: NeedBraces - /* Check for widening primitive conversion. */ - if (formal.isPrimitive()) { - if (formal == Short.TYPE && (actual == Byte.TYPE)) - return true; - if (formal == Integer.TYPE - && (actual == Short.TYPE || actual == Byte.TYPE)) - return true; - if (formal == Long.TYPE - && (actual == Integer.TYPE || actual == Short.TYPE - || actual == Byte.TYPE)) - return true; - if (formal == Float.TYPE - && (actual == Long.TYPE || actual == Integer.TYPE - || actual == Short.TYPE || actual == Byte.TYPE)) - return true; - if (formal == Double.TYPE - && (actual == Float.TYPE || actual == Long.TYPE - || actual == Integer.TYPE || actual == Short.TYPE - || actual == Byte.TYPE)) - return true; - } - // CSON: NeedBraces - - /* Check for vararg conversion. */ - if (possibleVarArg && formal.isArray()) { - if (actual.isArray()) { - actual = actual.getComponentType(); - } - return isStrictMethodInvocationConvertible(formal.getComponentType(), - actual, false); - } - return false; - } -} +/* + * 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.commons.jexl.util.introspection; + +/** + * @author <a href="mailto:jvan...@apache.org">Jason van Zyl</a> + * @author <a href="mailto:b...@werken.com">Bob McWhirter</a> + * @author <a href="mailto:christoph.r...@dlr.de">Christoph Reck</a> + * @author <a href="mailto:ge...@optonline.net">Geir Magnusson Jr.</a> + * @author <a href="mailto:szege...@freemail.hu">Attila Szegedi</a> + * @author Nathan Bubna + * @version $Id: IntrospectionUtils.java 476785 2006-11-19 10:06:21Z henning $ + */ +public class IntrospectionUtils { + + /** + * Determines whether a type represented by a class object is + * convertible to another type represented by a class object using a + * method invocation conversion, treating object types of primitive + * types as if they were primitive types (that is, a Boolean actual + * parameter type matches boolean primitive formal type). This behavior + * is because this method is used to determine applicable methods for + * an actual parameter list, and primitive types are represented by + * their object duals in reflective method calls. + * + * @param formal the formal parameter type to which the actual + * parameter type should be convertible + * @param actual the actual parameter type. + * @param possibleVarArg whether or not we're dealing with the last parameter + * in the method declaration + * @return true if either formal type is assignable from actual type, + * or formal is a primitive type and actual is its corresponding object + * type or an object type of a primitive type that can be converted to + * the formal type. + */ + public static boolean isMethodInvocationConvertible(Class formal, + Class actual, + boolean possibleVarArg) { + /* if it's a null, it means the arg was null */ + if (actual == null && !formal.isPrimitive()) { + return true; + } + + /* Check for identity or widening reference conversion */ + if (actual != null && formal.isAssignableFrom(actual)) { + return true; + } + + // CSOFF: NeedBraces + /* Check for boxing with widening primitive conversion. Note that + * actual parameters are never primitives. */ + if (formal.isPrimitive()) { + if (formal == Boolean.TYPE && actual == Boolean.class) + return true; + if (formal == Character.TYPE && actual == Character.class) + return true; + if (formal == Byte.TYPE && actual == Byte.class) + return true; + if (formal == Short.TYPE + && (actual == Short.class || actual == Byte.class)) + return true; + if (formal == Integer.TYPE + && (actual == Integer.class || actual == Short.class + || actual == Byte.class)) + return true; + if (formal == Long.TYPE + && (actual == Long.class || actual == Integer.class + || actual == Short.class || actual == Byte.class)) + return true; + if (formal == Float.TYPE + && (actual == Float.class || actual == Long.class + || actual == Integer.class || actual == Short.class + || actual == Byte.class)) + return true; + if (formal == Double.TYPE + && (actual == Double.class || actual == Float.class + || actual == Long.class || actual == Integer.class + || actual == Short.class || actual == Byte.class)) + return true; + } + // CSON: NeedBraces + + /* Check for vararg conversion. */ + if (possibleVarArg && formal.isArray()) { + if (actual.isArray()) { + actual = actual.getComponentType(); + } + return isMethodInvocationConvertible(formal.getComponentType(), + actual, false); + } + return false; + } + + /** + * Determines whether a type represented by a class object is + * convertible to another type represented by a class object using a + * method invocation conversion, without matching object and primitive + * types. This method is used to determine the more specific type when + * comparing signatures of methods. + * + * @param formal the formal parameter type to which the actual + * parameter type should be convertible + * @param actual the actual parameter type. + * @param possibleVarArg whether or not we're dealing with the last parameter + * in the method declaration + * @return true if either formal type is assignable from actual type, + * or formal and actual are both primitive types and actual can be + * subject to widening conversion to formal. + */ + public static boolean isStrictMethodInvocationConvertible(Class formal, + Class actual, + boolean possibleVarArg) { + /* we shouldn't get a null into, but if so */ + if (actual == null && !formal.isPrimitive()) { + return true; + } + + /* Check for identity or widening reference conversion */ + if (formal.isAssignableFrom(actual)) { + return true; + } + + // CSOFF: NeedBraces + /* Check for widening primitive conversion. */ + if (formal.isPrimitive()) { + if (formal == Short.TYPE && (actual == Byte.TYPE)) + return true; + if (formal == Integer.TYPE + && (actual == Short.TYPE || actual == Byte.TYPE)) + return true; + if (formal == Long.TYPE + && (actual == Integer.TYPE || actual == Short.TYPE + || actual == Byte.TYPE)) + return true; + if (formal == Float.TYPE + && (actual == Long.TYPE || actual == Integer.TYPE + || actual == Short.TYPE || actual == Byte.TYPE)) + return true; + if (formal == Double.TYPE + && (actual == Float.TYPE || actual == Long.TYPE + || actual == Integer.TYPE || actual == Short.TYPE + || actual == Byte.TYPE)) + return true; + } + // CSON: NeedBraces + + /* Check for vararg conversion. */ + if (possibleVarArg && formal.isArray()) { + if (actual.isArray()) { + actual = actual.getComponentType(); + } + return isStrictMethodInvocationConvertible(formal.getComponentType(), + actual, false); + } + return false; + } +} Propchange: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/introspection/IntrospectionUtils.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ArithmeticTest.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ArithmeticTest.java?rev=785074&r1=785073&r2=785074&view=diff ============================================================================== --- commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ArithmeticTest.java (original) +++ commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ArithmeticTest.java Tue Jun 16 04:32:59 2009 @@ -1,115 +1,115 @@ -/* - * 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.commons.jexl; - -import java.math.BigDecimal; -import java.math.BigInteger; - -import org.apache.commons.jexl.junit.Asserter; - -import junit.framework.TestCase; - -public class ArithmeticTest extends TestCase { - private Asserter asserter; - - public void setUp() { - asserter = new Asserter(); - } - - public void testBigDecimal() throws Exception { - asserter.setVariable("left", new BigDecimal(2)); - asserter.setVariable("right", new BigDecimal(6)); - asserter.assertExpression("left + right", new BigDecimal(8)); - asserter.assertExpression("right - left", new BigDecimal(4)); - asserter.assertExpression("right * left", new BigDecimal(12)); - asserter.assertExpression("right / left", new BigDecimal(3)); - asserter.assertExpression("right % left", new BigDecimal(0)); - } - - public void testBigInteger() throws Exception { - asserter.setVariable("left", new BigInteger("2")); - asserter.setVariable("right", new BigInteger("6")); - asserter.assertExpression("left + right", new BigInteger("8")); - asserter.assertExpression("right - left", new BigInteger("4")); - asserter.assertExpression("right * left", new BigInteger("12")); - asserter.assertExpression("right / left", new BigInteger("3")); - asserter.assertExpression("right % left", new BigInteger("0")); - } - - /** - * test some simple mathematical calculations - */ - public void testUnaryMinus() throws Exception { - asserter.setVariable("aByte", new Byte((byte) 1)); - asserter.setVariable("aShort", new Short((short) 2)); - asserter.setVariable("anInteger", new Integer(3)); - asserter.setVariable("aLong", new Long(4)); - asserter.setVariable("aFloat", new Float(5.5)); - asserter.setVariable("aDouble", new Double(6.6)); - asserter.setVariable("aBigInteger", new BigInteger("7")); - asserter.setVariable("aBigDecimal", new BigDecimal("8.8")); - - asserter.assertExpression("-3", new Integer("-3")); - asserter.assertExpression("-3.0", new Float("-3.0")); - asserter.assertExpression("-aByte", new Byte((byte) -1)); - asserter.assertExpression("-aShort", new Short((short) -2)); - asserter.assertExpression("-anInteger", new Integer(-3)); - asserter.assertExpression("-aLong", new Long(-4)); - asserter.assertExpression("-aFloat", new Float(-5.5)); - asserter.assertExpression("-aDouble", new Double(-6.6)); - asserter.assertExpression("-aBigInteger", new BigInteger("-7")); - asserter.assertExpression("-aBigDecimal", new BigDecimal("-8.8")); - } - - /** - * test some simple mathematical calculations - */ - public void testCalculations() throws Exception { - - asserter.setVariable("foo", new Integer(2)); - - asserter.assertExpression("foo + 2", new Long(4)); - asserter.assertExpression("3 + 3", new Long(6)); - asserter.assertExpression("3 + 3 + foo", new Long(8)); - asserter.assertExpression("3 * 3", new Long(9)); - asserter.assertExpression("3 * 3 + foo", new Long(11)); - asserter.assertExpression("3 * 3 - foo", new Long(7)); - - /* - * test some floaty stuff - */ - asserter.assertExpression("3 * \"3.0\"", new Double(9)); - asserter.assertExpression("3 * 3.0", new Double(9)); - - /* - * test / and % - */ - asserter.assertExpression("6 / 3", new Double(6 / 3)); - asserter.assertExpression("6.4 / 3", new Double(6.4 / 3)); - asserter.assertExpression("0 / 3", new Double(0 / 3)); - asserter.assertExpression("3 / 0", new Double(0)); - asserter.assertExpression("4 % 3", new Long(1)); - asserter.assertExpression("4.8 % 3", new Double(4.8 % 3)); - - /* - * test new null coersion - */ - asserter.setVariable("imanull", null); - asserter.assertExpression("imanull + 2", new Long(2)); - asserter.assertExpression("imanull + imanull", new Long(0)); - } -} +/* + * 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.commons.jexl; + +import java.math.BigDecimal; +import java.math.BigInteger; + +import org.apache.commons.jexl.junit.Asserter; + +import junit.framework.TestCase; + +public class ArithmeticTest extends TestCase { + private Asserter asserter; + + public void setUp() { + asserter = new Asserter(); + } + + public void testBigDecimal() throws Exception { + asserter.setVariable("left", new BigDecimal(2)); + asserter.setVariable("right", new BigDecimal(6)); + asserter.assertExpression("left + right", new BigDecimal(8)); + asserter.assertExpression("right - left", new BigDecimal(4)); + asserter.assertExpression("right * left", new BigDecimal(12)); + asserter.assertExpression("right / left", new BigDecimal(3)); + asserter.assertExpression("right % left", new BigDecimal(0)); + } + + public void testBigInteger() throws Exception { + asserter.setVariable("left", new BigInteger("2")); + asserter.setVariable("right", new BigInteger("6")); + asserter.assertExpression("left + right", new BigInteger("8")); + asserter.assertExpression("right - left", new BigInteger("4")); + asserter.assertExpression("right * left", new BigInteger("12")); + asserter.assertExpression("right / left", new BigInteger("3")); + asserter.assertExpression("right % left", new BigInteger("0")); + } + + /** + * test some simple mathematical calculations + */ + public void testUnaryMinus() throws Exception { + asserter.setVariable("aByte", new Byte((byte) 1)); + asserter.setVariable("aShort", new Short((short) 2)); + asserter.setVariable("anInteger", new Integer(3)); + asserter.setVariable("aLong", new Long(4)); + asserter.setVariable("aFloat", new Float(5.5)); + asserter.setVariable("aDouble", new Double(6.6)); + asserter.setVariable("aBigInteger", new BigInteger("7")); + asserter.setVariable("aBigDecimal", new BigDecimal("8.8")); + + asserter.assertExpression("-3", new Integer("-3")); + asserter.assertExpression("-3.0", new Float("-3.0")); + asserter.assertExpression("-aByte", new Byte((byte) -1)); + asserter.assertExpression("-aShort", new Short((short) -2)); + asserter.assertExpression("-anInteger", new Integer(-3)); + asserter.assertExpression("-aLong", new Long(-4)); + asserter.assertExpression("-aFloat", new Float(-5.5)); + asserter.assertExpression("-aDouble", new Double(-6.6)); + asserter.assertExpression("-aBigInteger", new BigInteger("-7")); + asserter.assertExpression("-aBigDecimal", new BigDecimal("-8.8")); + } + + /** + * test some simple mathematical calculations + */ + public void testCalculations() throws Exception { + + asserter.setVariable("foo", new Integer(2)); + + asserter.assertExpression("foo + 2", new Long(4)); + asserter.assertExpression("3 + 3", new Long(6)); + asserter.assertExpression("3 + 3 + foo", new Long(8)); + asserter.assertExpression("3 * 3", new Long(9)); + asserter.assertExpression("3 * 3 + foo", new Long(11)); + asserter.assertExpression("3 * 3 - foo", new Long(7)); + + /* + * test some floaty stuff + */ + asserter.assertExpression("3 * \"3.0\"", new Double(9)); + asserter.assertExpression("3 * 3.0", new Double(9)); + + /* + * test / and % + */ + asserter.assertExpression("6 / 3", new Double(6 / 3)); + asserter.assertExpression("6.4 / 3", new Double(6.4 / 3)); + asserter.assertExpression("0 / 3", new Double(0 / 3)); + asserter.assertExpression("3 / 0", new Double(0)); + asserter.assertExpression("4 % 3", new Long(1)); + asserter.assertExpression("4.8 % 3", new Double(4.8 % 3)); + + /* + * test new null coersion + */ + asserter.setVariable("imanull", null); + asserter.assertExpression("imanull + 2", new Long(2)); + asserter.assertExpression("imanull + imanull", new Long(0)); + } +} Propchange: commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ArithmeticTest.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ArrayAccessTest.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ArrayAccessTest.java?rev=785074&r1=785073&r2=785074&view=diff ============================================================================== --- commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ArrayAccessTest.java (original) +++ commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ArrayAccessTest.java Tue Jun 16 04:32:59 2009 @@ -1,148 +1,148 @@ -/* - * 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.commons.jexl; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.commons.jexl.junit.Asserter; - -import junit.framework.TestCase; - -/** - * Tests for array access operator [] - * - * @since 2.0 - */ -public class ArrayAccessTest extends TestCase { - - private Asserter asserter; - - 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 void setUp() { - asserter = new Asserter(); - } - - /** - * test simple array access - */ - public void testArrayAccess() throws Exception { - - /* - * test List access - */ - - List l = new ArrayList(); - l.add(new Integer(1)); - l.add(new Integer(2)); - l.add(new Integer(3)); - - asserter.setVariable("list", l); - - asserter.assertExpression("list[1]", new Integer(2)); - asserter.assertExpression("list[1+1]", new Integer(3)); - asserter.setVariable("loc", new Integer(1)); - asserter.assertExpression("list[loc+1]", new Integer(3)); - - /* - * test array access - */ - - String[] args = { "hello", "there" }; - asserter.setVariable("array", args); - asserter.assertExpression("array[0]", "hello"); - - /* - * to think that this was an intentional syntax... - */ - asserter.assertExpression("array.0", "hello"); - - /* - * test map access - */ - Map m = new HashMap(); - m.put("foo", "bar"); - - asserter.setVariable("map", m); - asserter.setVariable("key", "foo"); - - asserter.assertExpression("map[\"foo\"]", "bar"); - asserter.assertExpression("map[key]", "bar"); - - /* - * test bean access - */ - asserter.setVariable("foo", new Foo()); - asserter.assertExpression("foo[\"bar\"]", GET_METHOD_STRING); - asserter.assertExpression("foo[\"bar\"] == foo.bar", Boolean.TRUE); - } - - /** - * test some simple double array lookups - */ - public void testDoubleArrays() throws Exception { - Object[][] foo = new Object[2][2]; - foo[0][0] = "one"; - foo[0][1] = "two"; - - asserter.setVariable("foo", foo); - - asserter.assertExpression("foo[0][1]", "two"); - } - - public void testArrayProperty() throws Exception { - Foo foo = new Foo(); - - asserter.setVariable("foo", foo); - - asserter.assertExpression("foo.array[1]", GET_METHOD_ARRAY[1]); - asserter.assertExpression("foo.array.1", GET_METHOD_ARRAY[1]); - asserter.assertExpression("foo.array2[1][1]", GET_METHOD_ARRAY2[1][1]); - // asserter.assertExpression("foo.array2.1.1", GET_METHOD_ARRAY2[1][1]); - } - - // This is JEXL-26 - public void testArrayAndDottedConflict() throws Exception { - Object[] objects = new Object[] {"an", "array", new Long(0)}; - - asserter.setVariable("objects", objects); - asserter.setVariable("status", "Enabled"); - asserter.assertExpression("objects[1].status", null); - - asserter.setVariable("base.status", "Ok"); - asserter.assertExpression("base.objects[1].status", null); - } - - public void testArrayMethods() throws Exception { - Object[] objects = new Object[] {"an", "array", new Long(0)}; - - asserter.setVariable("objects", objects); - asserter.assertExpression("objects.get(1)", "array"); - asserter.assertExpression("objects.size()", new Integer(3)); - // setting an index returns the old value - asserter.assertExpression("objects.set(1, 'dion')", "array"); - asserter.assertExpression("objects[1]", "dion"); - } +/* + * 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.commons.jexl; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.jexl.junit.Asserter; + +import junit.framework.TestCase; + +/** + * Tests for array access operator [] + * + * @since 2.0 + */ +public class ArrayAccessTest extends TestCase { + + private Asserter asserter; + + 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 void setUp() { + asserter = new Asserter(); + } + + /** + * test simple array access + */ + public void testArrayAccess() throws Exception { + + /* + * test List access + */ + + List l = new ArrayList(); + l.add(new Integer(1)); + l.add(new Integer(2)); + l.add(new Integer(3)); + + asserter.setVariable("list", l); + + asserter.assertExpression("list[1]", new Integer(2)); + asserter.assertExpression("list[1+1]", new Integer(3)); + asserter.setVariable("loc", new Integer(1)); + asserter.assertExpression("list[loc+1]", new Integer(3)); + + /* + * test array access + */ + + String[] args = { "hello", "there" }; + asserter.setVariable("array", args); + asserter.assertExpression("array[0]", "hello"); + + /* + * to think that this was an intentional syntax... + */ + asserter.assertExpression("array.0", "hello"); + + /* + * test map access + */ + Map m = new HashMap(); + m.put("foo", "bar"); + + asserter.setVariable("map", m); + asserter.setVariable("key", "foo"); + + asserter.assertExpression("map[\"foo\"]", "bar"); + asserter.assertExpression("map[key]", "bar"); + + /* + * test bean access + */ + asserter.setVariable("foo", new Foo()); + asserter.assertExpression("foo[\"bar\"]", GET_METHOD_STRING); + asserter.assertExpression("foo[\"bar\"] == foo.bar", Boolean.TRUE); + } + + /** + * test some simple double array lookups + */ + public void testDoubleArrays() throws Exception { + Object[][] foo = new Object[2][2]; + foo[0][0] = "one"; + foo[0][1] = "two"; + + asserter.setVariable("foo", foo); + + asserter.assertExpression("foo[0][1]", "two"); + } + + public void testArrayProperty() throws Exception { + Foo foo = new Foo(); + + asserter.setVariable("foo", foo); + + asserter.assertExpression("foo.array[1]", GET_METHOD_ARRAY[1]); + asserter.assertExpression("foo.array.1", GET_METHOD_ARRAY[1]); + asserter.assertExpression("foo.array2[1][1]", GET_METHOD_ARRAY2[1][1]); + // asserter.assertExpression("foo.array2.1.1", GET_METHOD_ARRAY2[1][1]); + } + + // This is JEXL-26 + public void testArrayAndDottedConflict() throws Exception { + Object[] objects = new Object[] {"an", "array", new Long(0)}; + + asserter.setVariable("objects", objects); + asserter.setVariable("status", "Enabled"); + asserter.assertExpression("objects[1].status", null); + + asserter.setVariable("base.status", "Ok"); + asserter.assertExpression("base.objects[1].status", null); + } + + public void testArrayMethods() throws Exception { + Object[] objects = new Object[] {"an", "array", new Long(0)}; + + asserter.setVariable("objects", objects); + asserter.assertExpression("objects.get(1)", "array"); + asserter.assertExpression("objects.size()", new Integer(3)); + // setting an index returns the old value + asserter.assertExpression("objects.set(1, 'dion')", "array"); + asserter.assertExpression("objects[1]", "dion"); + } } \ No newline at end of file Propchange: commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ArrayAccessTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/AssignTest.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/MethodTest.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/MethodTest.java?rev=785074&r1=785073&r2=785074&view=diff ============================================================================== --- commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/MethodTest.java (original) +++ commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/MethodTest.java Tue Jun 16 04:32:59 2009 @@ -1,88 +1,88 @@ -/* - * 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.commons.jexl; - -import org.apache.commons.jexl.junit.Asserter; - -import junit.framework.TestCase; - -/** - * Tests for calling methods on objects - * - * @since 2.0 - */ -public class MethodTest extends TestCase { - - private Asserter asserter; - - private static final String METHOD_STRING = "Method string"; - - public static class TestClass { - public String testVarArgs(Integer[] args) { - return "Test"; - } - } - - public void setUp() { - asserter = new Asserter(); - } - - public void testCallVarArgMethod() throws Exception { - asserter.setVariable("test", new TestClass()); - asserter.assertExpression("test.testVarArgs(1,2,3,4,5)", "Test"); - } - - /** - * test a simple method expression - */ - public void testMethod() throws Exception { - // tests a simple method expression - asserter.setVariable("foo", new Foo()); - asserter.assertExpression("foo.bar()", METHOD_STRING); - } - - public void testMulti() throws Exception { - asserter.setVariable("foo", new Foo()); - asserter.assertExpression("foo.innerFoo.bar()", METHOD_STRING); - } - - /** - * test some String method calls - */ - public void testStringMethods() throws Exception { - asserter.setVariable("foo", "abcdef"); - asserter.assertExpression("foo.substring(3)", "def"); - asserter.assertExpression("foo.substring(0,(size(foo)-3))", "abc"); - asserter.assertExpression("foo.substring(0,size(foo)-3)", "abc"); - asserter.assertExpression("foo.substring(0,foo.length()-3)", "abc"); - asserter.assertExpression("foo.substring(0, 1+1)", "ab"); - } - - /** - * Ensures static methods on objects can be called. - */ - public void testStaticMethodInvocation() throws Exception { - asserter.setVariable("aBool", Boolean.FALSE); - asserter.assertExpression("aBool.valueOf('true')", Boolean.TRUE); - } - - public void testStaticMethodInvocationOnClasses() throws Exception { - asserter.setVariable("Boolean", Boolean.class); - asserter.assertExpression("Boolean.valueOf('true')", Boolean.TRUE); - } - +/* + * 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.commons.jexl; + +import org.apache.commons.jexl.junit.Asserter; + +import junit.framework.TestCase; + +/** + * Tests for calling methods on objects + * + * @since 2.0 + */ +public class MethodTest extends TestCase { + + private Asserter asserter; + + private static final String METHOD_STRING = "Method string"; + + public static class TestClass { + public String testVarArgs(Integer[] args) { + return "Test"; + } + } + + public void setUp() { + asserter = new Asserter(); + } + + public void testCallVarArgMethod() throws Exception { + asserter.setVariable("test", new TestClass()); + asserter.assertExpression("test.testVarArgs(1,2,3,4,5)", "Test"); + } + + /** + * test a simple method expression + */ + public void testMethod() throws Exception { + // tests a simple method expression + asserter.setVariable("foo", new Foo()); + asserter.assertExpression("foo.bar()", METHOD_STRING); + } + + public void testMulti() throws Exception { + asserter.setVariable("foo", new Foo()); + asserter.assertExpression("foo.innerFoo.bar()", METHOD_STRING); + } + + /** + * test some String method calls + */ + public void testStringMethods() throws Exception { + asserter.setVariable("foo", "abcdef"); + asserter.assertExpression("foo.substring(3)", "def"); + asserter.assertExpression("foo.substring(0,(size(foo)-3))", "abc"); + asserter.assertExpression("foo.substring(0,size(foo)-3)", "abc"); + asserter.assertExpression("foo.substring(0,foo.length()-3)", "abc"); + asserter.assertExpression("foo.substring(0, 1+1)", "ab"); + } + + /** + * Ensures static methods on objects can be called. + */ + public void testStaticMethodInvocation() throws Exception { + asserter.setVariable("aBool", Boolean.FALSE); + asserter.assertExpression("aBool.valueOf('true')", Boolean.TRUE); + } + + public void testStaticMethodInvocationOnClasses() throws Exception { + asserter.setVariable("Boolean", Boolean.class); + asserter.assertExpression("Boolean.valueOf('true')", Boolean.TRUE); + } + } \ No newline at end of file Propchange: commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/MethodTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ParseFailuresTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/util/introspection/MethodKeyTest.java ------------------------------------------------------------------------------ svn:eol-style = native