use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.
the class BytecodeGeneratorTest method testDispatch.
@Test
public void testDispatch() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
Class constructor1 = new ClassBuilder("FooObject_testDispatch").method("boo: anObject ^anObject foo").build();
Class constructor2 = new ClassBuilder("BorkObject_testDispatch").method("foo ^2").build();
Object fooObject = constructor1.newInstance();
Object borkObject = constructor2.newInstance();
Method method = fooObject.getClass().getMethod("boo_", Object.class);
Object result = method.invoke(fooObject, borkObject);
assertEquals(Integer.valueOf(2), result);
}
use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.
the class BytecodeGeneratorTest method testAssignTemp.
@Test
public void testAssignTemp() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
Class fooClass = new ClassBuilder("FooObject_testAssignTemp").method("foo: bar | a b |\n" + " a := 3.\n" + " b := a + bar.\n" + " ^b").build();
Object fooObject = fooClass.newInstance();
Method method = fooObject.getClass().getMethod("foo_", Object.class);
Object result = method.invoke(fooObject, 4);
assertEquals(Integer.valueOf(7), result);
}
use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.
the class BytecodeGeneratorTest method testPlusInt.
@Test
public void testPlusInt() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
Class stClass = new ClassBuilder("FooObject_testPlusInt").method("foo ^3 + 4").build();
Object fooObject = stClass.newInstance();
Method method = fooObject.getClass().getMethod("foo");
Object result = method.invoke(fooObject);
assertEquals(Integer.valueOf(7), result);
}
use of st.gravel.support.compiler.testtools.ClassBuilder in project gravel by gravel-st.
the class BytecodeGeneratorTest method testReturnAssignment.
@Test
public void testReturnAssignment() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
Class stClass = new ClassBuilder("FooObject_testReturnAssignment").method("foo | a | ^a := 3").build();
Object fooObject = stClass.newInstance();
Method method = fooObject.getClass().getMethod("foo");
Object result = method.invoke(fooObject);
assertEquals(Integer.valueOf(3), result);
}
Aggregations