001: package org.jicengine.expression;
002:
003: import org.jicengine.expression.Utils;
004: import org.jicengine.operation.SimpleContext;
005: import org.jicengine.operation.Context;
006: import org.jicengine.operation.Operation;
007: import junit.framework.TestCase;
008: import junit.framework.Test;
009: import junit.framework.TestSuite;
010:
011: /**
012: *
013: *
014: * <p>
015: * Copyright (C) 2004 Timo Laitinen
016: * </p>
017: *
018: * @author Timo Laitinen
019: * @created 2004-09-20
020: * @since JICE-0.10
021: *
022: */
023:
024: public class Tests {
025:
026: public static class LJETest extends TestCase {
027: protected void expressionEquals(String expression,
028: Object expected) throws Exception {
029: Context dummyContext = new SimpleContext("empty-context");
030: Operation resultOp = LJEParser.getInstance().parse(
031: expression);
032: Object result = resultOp.execute(dummyContext);
033: assertEquals(expected, result);
034: }
035:
036: public void testNumbers() throws Exception {
037: expressionEquals("123", new Integer(123));
038: expressionEquals("-1", new Integer(-1));
039: expressionEquals("0", new Integer(0));
040: expressionEquals("1.23", new Double(1.23));
041: expressionEquals("-1.01", new Double(-1.01));
042: expressionEquals("0.0", new Double(0.0));
043: expressionEquals("12345l", new Long(12345l));
044: expressionEquals("-1L", new Long(-1L));
045: expressionEquals("-11f", new Float(-11f));
046: }
047:
048: public void testStrings() throws Exception {
049: expressionEquals("'hello' ", "hello");
050: expressionEquals("'hello()'", "hello()");
051: expressionEquals("'(hel,lo)'", "(hel,lo)");
052: expressionEquals("'h,e,l,l,o'", "h,e,l,l,o");
053: expressionEquals("'h e l l o'", "h e l l o");
054: expressionEquals("'-123'", "-123");
055: expressionEquals("''", "");
056: }
057:
058: public void testBoolean() throws Exception {
059: expressionEquals("true ", new Boolean(true));
060: expressionEquals("false ", new Boolean(false));
061: }
062:
063: }
064:
065: public static class UtilsTest extends TestCase {
066: /*
067: public void doParseSignatureTest(String signature, String expectedType, String[] exprectedParams) throws Exception
068: {
069: Object[] result = Utils.parseSignature(signature);
070: assertEquals("Testing the type in signature '" + signature + "'.","type", result[0]);
071: Object[] params = (Object[]) result[1];
072: java.util.List paramsList = java.util.Arrays.asList(params);
073: java.util.List expectedParamsList = java.util.Arrays.asList(exprectedParams);
074: assertEquals("Expected " + expectedParamsList.size() + " params " + expectedParamsList + ", got " + paramsList.size() + " params " + paramsList,exprectedParams.length, params.length );
075:
076: for (int i = 0; i < params.length; i++) {
077: assertEquals("Testing param " + (i+1) + " in '" + signature + "'", exprectedParams[i], params[i]);
078: }
079: }
080: */
081:
082: /*
083: public void testParseSignature() throws Exception
084: {
085: doParseSignatureTest(
086: "type(param1,param2)",
087: "type",
088: new String[]{"param1","param2"}
089: );
090:
091: doParseSignatureTest(
092: "type('p()aram1',param2)",
093: "type",
094: new String[]{"'p()aram1'","param2"}
095: );
096:
097: doParseSignatureTest(
098: "type('a,b,c',param2)",
099: "type",
100: new String[]{"'a,b,c'","param2"}
101: );
102:
103: }
104: */
105: }
106:
107: public static Test createTests() {
108: TestSuite suite = new TestSuite();
109:
110: // add here all the TestCase-classes that are to
111: // be run.
112: Class[] testClasses = new Class[] { LJETest.class,
113: UtilsTest.class };
114:
115: for (int i = 0; i < testClasses.length; i++) {
116: suite.addTestSuite(testClasses[i]);
117: }
118:
119: return suite;
120: }
121:
122: public static void main(String[] args) {
123: //RunTests runTests1 = new RunTests();
124: junit.textui.TestRunner.run(createTests());
125: }
126: }
|