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));
}
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);
}
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);
}
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);
}
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);
}
Aggregations