Search in sources :

Example 66 with ClassBuilder

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);
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 67 with ClassBuilder

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);
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 68 with ClassBuilder

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);
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 69 with ClassBuilder

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