Search in sources :

Example 31 with ClassBuilder

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

the class BlockTest method testReadWriteOuterTemp.

@Test
public void testReadWriteOuterTemp() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
    Class stClass = new ClassBuilder("FooObject_testReadWriteOuterTemp").method("foo: bar\n" + "| a ar aw |\n" + "a := 0.\n" + "ar := [a].\n" + "aw := [:x | a := x + 7].\n" + "aw value: bar.	\n" + "^ar value").build();
    Object fooObject = stClass.newInstance();
    Method method = fooObject.getClass().getMethod("foo_", Object.class);
    assertEquals(Integer.valueOf(9), method.invoke(fooObject, 2));
    assertEquals(Integer.valueOf(8), method.invoke(fooObject, 1));
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 32 with ClassBuilder

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

the class BytecodeGeneratorTest method testTemp.

@Test
public void testTemp() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
    Class stClass = new ClassBuilder("FooObject_testTemp").method("foo | a | a := 1. ^a").build();
    Object fooObject = stClass.newInstance();
    Method method = fooObject.getClass().getMethod("foo");
    Object result = method.invoke(fooObject);
    assertEquals(Integer.valueOf(1), result);
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 33 with ClassBuilder

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

the class BytecodeGeneratorTest method testPlusLargeInt.

@Test
public void testPlusLargeInt() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
    Class stClass = new ClassBuilder("FooObject_testPlusLargeInt").method("foo ^2147483647 + 1").build();
    Object fooObject = stClass.newInstance();
    Method method = fooObject.getClass().getMethod("foo");
    Object result = method.invoke(fooObject);
    assertEquals(new BigInteger("2147483648"), result);
}
Also used : BigInteger(java.math.BigInteger) Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 34 with ClassBuilder

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

the class BytecodeGeneratorTest method testSendMessage.

@Test
public void testSendMessage() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
    Class stClass = new ClassBuilder("FooObject_testSendMessage").method("foo ^1").method("bar ^self boo: self").method("boo: anObject ^anObject foo").build();
    Object fooObject = stClass.newInstance();
    Method method = fooObject.getClass().getMethod("bar");
    Object result = method.invoke(fooObject);
    assertEquals(Integer.valueOf(1), result);
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 35 with ClassBuilder

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

the class BytecodeGeneratorTest method testPrintInt.

@Test
public void testPrintInt() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
    Class stClass = new ClassBuilder("FooObject_testPrintInt").method("foo ^7 printString").build();
    Object fooObject = stClass.newInstance();
    Method method = fooObject.getClass().getMethod("foo");
    Object result = method.invoke(fooObject);
    assertEquals("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