001: //--------------------------------------------------------------------------
002: // Copyright (c) 2004, Drew Davidson and Luke Blanshard
003: // All rights reserved.
004: //
005: // Redistribution and use in source and binary forms, with or without
006: // modification, are permitted provided that the following conditions are
007: // met:
008: //
009: // Redistributions of source code must retain the above copyright notice,
010: // this list of conditions and the following disclaimer.
011: // Redistributions in binary form must reproduce the above copyright
012: // notice, this list of conditions and the following disclaimer in the
013: // documentation and/or other materials provided with the distribution.
014: // Neither the name of the Drew Davidson nor the names of its contributors
015: // may be used to endorse or promote products derived from this software
016: // without specific prior written permission.
017: //
018: // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
019: // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
020: // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
021: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
022: // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
023: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
024: // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
025: // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
026: // AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
027: // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
028: // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
029: // DAMAGE.
030: //--------------------------------------------------------------------------
031: package org.ognl.test;
032:
033: import java.math.BigInteger;
034: import java.util.ArrayList;
035: import java.util.Arrays;
036: import junit.framework.TestSuite;
037:
038: public class LambdaExpressionTest extends OgnlTestCase {
039: private static Object[][] TESTS = {
040: // Lambda expressions
041: { null, "#a=:[33](20).longValue().{0}.toArray().length",
042: new Integer(33) },
043: {
044: null,
045: "#fact=:[#this<=1? 1 : #fact(#this-1) * #this], #fact(30)",
046: new Integer(1409286144) },
047: {
048: null,
049: "#fact=:[#this<=1? 1 : #fact(#this-1) * #this], #fact(30L)",
050: new Long(-8764578968847253504L) },
051: {
052: null,
053: "#fact=:[#this<=1? 1 : #fact(#this-1) * #this], #fact(30h)",
054: new BigInteger("265252859812191058636308480000000") },
055: {
056: null,
057: "#bump = :[ #this.{ #this + 1 } ], (#bump)({ 1, 2, 3 })",
058: new ArrayList(Arrays.asList(new Integer[] {
059: new Integer(2), new Integer(3),
060: new Integer(4) })) },
061: {
062: null,
063: "#call = :[ \"calling \" + [0] + \" on \" + [1] ], (#call)({ \"x\", \"y\" })",
064: "calling x on y" }, };
065:
066: /*===================================================================
067: Public static methods
068: ===================================================================*/
069: public static TestSuite suite() {
070: TestSuite result = new TestSuite();
071:
072: for (int i = 0; i < TESTS.length; i++) {
073: result.addTest(new LambdaExpressionTest(
074: (String) TESTS[i][1], TESTS[i][0],
075: (String) TESTS[i][1], TESTS[i][2]));
076: }
077: return result;
078: }
079:
080: /*===================================================================
081: Constructors
082: ===================================================================*/
083: public LambdaExpressionTest() {
084: super ();
085: }
086:
087: public LambdaExpressionTest(String name) {
088: super (name);
089: }
090:
091: public LambdaExpressionTest(String name, Object root,
092: String expressionString, Object expectedResult,
093: Object setValue, Object expectedAfterSetResult) {
094: super (name, root, expressionString, expectedResult, setValue,
095: expectedAfterSetResult);
096: }
097:
098: public LambdaExpressionTest(String name, Object root,
099: String expressionString, Object expectedResult,
100: Object setValue) {
101: super (name, root, expressionString, expectedResult, setValue);
102: }
103:
104: public LambdaExpressionTest(String name, Object root,
105: String expressionString, Object expectedResult) {
106: super(name, root, expressionString, expectedResult);
107: }
108: }
|