Search in sources :

Example 11 with ClassBuilder

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

the class FlowControlTest method testIfTrue2.

@Test
public void testIfTrue2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
    Class stClass = new ClassBuilder("FooObject_testIfTrue2").method("foo: bar |t| t := 2. bar ifTrue:  [t := 1]. ^t").build();
    Object fooObject = stClass.newInstance();
    Method method = fooObject.getClass().getMethod("foo_", Object.class);
    assertEquals(Integer.valueOf(1), method.invoke(fooObject, true));
    assertEquals(Integer.valueOf(2), method.invoke(fooObject, false));
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 12 with ClassBuilder

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

the class FlowControlTest method testIfTrueIfFalse_withSameTempNames.

@Test
public void testIfTrueIfFalse_withSameTempNames() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
    Class stClass = new ClassBuilder("FooObject_testIfTrueIfFalse_withSameTempNames").method("foo: bar\n" + "	|res|\n" + "	bar ifTrue: [|tmp| tmp := 1. res := tmp] ifFalse: [|tmp| tmp := 2. res := tmp].\n" + "	^res").build();
    Object fooObject = stClass.newInstance();
    Method method = fooObject.getClass().getMethod("foo_", Object.class);
    assertEquals(Integer.valueOf(1), method.invoke(fooObject, true));
    assertEquals(Integer.valueOf(2), method.invoke(fooObject, false));
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 13 with ClassBuilder

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

the class FlowControlTest method testIfTrueIfFalse1.

@Test
public void testIfTrueIfFalse1() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
    Class stClass = new ClassBuilder("FooObject_testIfTrueIfFalse1").method("foo: bar\n" + "	bar ifTrue: [^1] ifFalse: [^2]").build();
    Object fooObject = stClass.newInstance();
    Method method = fooObject.getClass().getMethod("foo_", Object.class);
    assertEquals(Integer.valueOf(1), method.invoke(fooObject, true));
    assertEquals(Integer.valueOf(2), method.invoke(fooObject, false));
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 14 with ClassBuilder

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

the class FlowControlTest method testIfFalse2.

@Test
public void testIfFalse2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
    Class stClass = new ClassBuilder("FooObject_testIfFalse2").method("foo: bar\n" + "	|t| t := 2.\n" + "	bar ifFalse:  [t := 1].\n" + "	^t").build();
    Object fooObject = stClass.newInstance();
    Method method = fooObject.getClass().getMethod("foo_", Object.class);
    assertEquals(Integer.valueOf(2), method.invoke(fooObject, true));
    assertEquals(Integer.valueOf(1), method.invoke(fooObject, false));
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 15 with ClassBuilder

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

the class InheritanceTest method testSuperSend1.

@Test
public void testSuperSend1() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
    Class classA = new ClassBuilder("ClassA_testSuperSend1").method("sendSuper: bar ^bar + 1").build();
    Class classB = new ClassBuilder("ClassB_testSuperSend1").superclassName("ClassA_testSuperSend1").method("sendSuper: bar ^(super sendSuper: bar) + 2").build();
    Object fooObject = classB.newInstance();
    Method method = fooObject.getClass().getMethod("sendSuper_", Object.class);
    Object result = method.invoke(fooObject, 4);
    assertEquals(Integer.valueOf(7), result);
}
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