Search in sources :

Example 1 with ClassBuilder

use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.

the class LiteralsTest method testArrayLiteral.

@Test
public void testArrayLiteral() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
    Class classA = new ClassBuilder("ClassA_testArrayLiteral").method("foo ^#(aap 1 nil)").method("bar ^#(aap 1 nil)").method("eq ^self foo == self bar").build();
    Object classAObj = classA.newInstance();
    Method foo = classAObj.getClass().getMethod("foo");
    Method bar = classAObj.getClass().getMethod("bar");
    Method eq = classAObj.getClass().getMethod("eq");
    Object fooValue = foo.invoke(classAObj);
    Object barValue = bar.invoke(classAObj);
    Object eqValue = eq.invoke(classAObj);
    assertEquals(Boolean.TRUE, eqValue);
    assertEquals(fooValue, barValue);
    Object[] arr = (Object[]) fooValue;
    assertEquals(3, arr.length);
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 2 with ClassBuilder

use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.

the class LiteralsTest method testLargeIntegerLiteral.

@Test
public void testLargeIntegerLiteral() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
    Class classA = new ClassBuilder("ClassA_testLargeIntegerLiteral").method("foo ^12389471234798172348979183249871234").method("bar ^12389471234798172348979183249871234").build();
    Object classAObj = classA.newInstance();
    Method foo = classAObj.getClass().getMethod("foo");
    Method bar = classAObj.getClass().getMethod("bar");
    Object fooValue = foo.invoke(classAObj);
    Object barValue = bar.invoke(classAObj);
    assertEquals(fooValue, barValue);
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 3 with ClassBuilder

use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.

the class LoopTest method test_whileFalse_.

@Test
public void test_whileFalse_() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
    Class stClass = new ClassBuilder("FooObject_test_whileFalse_").method("foo: sz  | sum arr | arr := (1 to: sz) asArray.  sum := 0. [sum := sum + arr first. arr size = 1] whileFalse: [arr := arr tail].  ^sum").build();
    Object fooObject = stClass.newInstance();
    Method method = fooObject.getClass().getMethod("foo_", Object.class);
    assertEquals(Integer.valueOf(1), method.invoke(fooObject, 1));
    assertEquals(Integer.valueOf(21), method.invoke(fooObject, 6));
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 4 with ClassBuilder

use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.

the class LoopTest method test_BigInt_to_BigInt_do_.

@Test
public void test_BigInt_to_BigInt_do_() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
    Class stClass = new ClassBuilder("FooObject_test_BigInt_to_BigInt_do_").method("foo | sum | sum := 0. 2934758938247592387459832475 to: 2934758938247592387459832475 do: [:i | sum := sum + i].  ^sum").build();
    Object fooObject = stClass.newInstance();
    Method method = fooObject.getClass().getMethod("foo");
    assertEquals(new BigInteger("2934758938247592387459832475"), method.invoke(fooObject));
}
Also used : BigInteger(java.math.BigInteger) Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 5 with ClassBuilder

use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.

the class LoopTest method test_whileTrue.

@Test
public void test_whileTrue() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
    Class stClass = new ClassBuilder("FooObject_test_whileTrue").method("foo: sz | sum arr | arr := (1 to: sz) asArray.  sum := 0. [sum := sum + arr first.  arr := arr tail.  arr isEmpty not] whileTrue.  ^sum").build();
    Object fooObject = stClass.newInstance();
    Method method = fooObject.getClass().getMethod("foo_", Object.class);
    assertEquals(Integer.valueOf(1), method.invoke(fooObject, 1));
    assertEquals(Integer.valueOf(21), method.invoke(fooObject, 6));
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)69 ClassBuilder (st.gravel.support.compiler.testtools.ClassBuilder)69 Method (java.lang.reflect.Method)65 BigInteger (java.math.BigInteger)4 Date (java.util.Date)1