Search in sources :

Example 46 with ClassBuilder

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

the class BlockTest method testBooleanOr.

@Test
public void testBooleanOr() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
    Class stClass = new ClassBuilder("FooObject_testBooleanOr").method("foo: a bar: b ^a or: [b]").build();
    Object fooObject = stClass.newInstance();
    Method method = fooObject.getClass().getMethod("foo_bar_", Object.class, Object.class);
    assertEquals(Boolean.TRUE, method.invoke(fooObject, true, true));
    assertEquals(Boolean.TRUE, method.invoke(fooObject, true, false));
    assertEquals(Boolean.TRUE, method.invoke(fooObject, false, true));
    assertEquals(Boolean.FALSE, method.invoke(fooObject, false, false));
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 47 with ClassBuilder

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

the class BlockTest method testReadWriteOuterTempDoubleNested.

@Test
public void testReadWriteOuterTempDoubleNested() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
    Class stClass = new ClassBuilder("FooObject_testReadWriteOuterTempDoubleNested").method("foo: bar\n" + "| a ar aw |\n" + "a := 0.\n" + "ar := [[a] value].\n" + "aw := [:x | [:y | a := y + 7] value: x].\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 48 with ClassBuilder

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

the class BlockTest method testFullBlock.

@Test
public void testFullBlock() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
    Class stClass = new ClassBuilder("FooObject_testFullBlock").method("foo: bar\n" + "	| block |\n" + "	block := [^1].\n" + "	bar ifFalse:  [block value].\n" + "	^2").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 49 with ClassBuilder

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

the class BlockTest method testReadWriteInstVar.

@Test
public void testReadWriteInstVar() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
    Class stClass = new ClassBuilder("FooObject_testReadWriteInstVar").method("foo: bar\n" + "bar name: 'Fromage'.\n" + "^bar name").build();
    Class barClass = new ClassBuilder("BarObject_testReadWriteInstVar").method("name: aString name := aString").method("name ^name").instVar("name").build();
    Object fooObject = stClass.newInstance();
    Object barObject = barClass.newInstance();
    Method method = fooObject.getClass().getMethod("foo_", Object.class);
    assertEquals("Fromage", method.invoke(fooObject, barObject));
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 50 with ClassBuilder

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

the class BlockTest method testBooleanAnd.

@Test
public void testBooleanAnd() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
    Class stClass = new ClassBuilder("FooObject_testBooleanAnd").method("foo: a bar: b ^a and: [b]").build();
    Object fooObject = stClass.newInstance();
    Method method = fooObject.getClass().getMethod("foo_bar_", Object.class, Object.class);
    assertEquals(Boolean.TRUE, method.invoke(fooObject, true, true));
    assertEquals(Boolean.FALSE, method.invoke(fooObject, true, false));
    assertEquals(Boolean.FALSE, method.invoke(fooObject, false, true));
    assertEquals(Boolean.FALSE, method.invoke(fooObject, false, false));
}
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