Search in sources :

Example 41 with ClassBuilder

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

the class LoopTest method test_to_do_.

@Test
public void test_to_do_() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
    Class stClass = new ClassBuilder("FooObject_test_to_do_").method("foo | sum | sum := 0. 1 to: 7 do: [:i | sum := sum + i].  ^sum").build();
    Object fooObject = stClass.newInstance();
    Method method = fooObject.getClass().getMethod("foo");
    assertEquals(Integer.valueOf(28), method.invoke(fooObject));
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 42 with ClassBuilder

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

the class ProcessTest method test_ForkProcesses.

@Test
public void test_ForkProcesses() throws Throwable {
    Class stClass = new ClassBuilder("FooObject_ForkProcesses").method("runForked: aName semaphore: sema " + "[1 to: 10 do: [:i |" + "Transcript cr; show: aName,': ', i printString. " + "(Delay forMilliseconds: 100) wait]. " + " sema signal] fork." + "").method("runForked" + "| sema |" + "sema := Semaphore new. " + "self runForked: 'A' semaphore: sema. " + "self runForked: 'B' semaphore: sema. " + "self runForked: 'C' semaphore: sema. " + "sema wait. " + "sema wait. " + "sema wait. ").build();
    Object fooObject = stClass.newInstance();
    MethodTools.perform(fooObject, "runForked");
}
Also used : ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 43 with ClassBuilder

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

the class BlockTest method testFullCopyingBlock.

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

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

the class BlockTest method testEmptyBlockReturnsNil.

@Test
public void testEmptyBlockReturnsNil() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
    Class stClass = new ClassBuilder("FooObject_testEmptyBlockReturnsNil").method("foo ^[] value").build();
    Object fooObject = stClass.newInstance();
    Method method = fooObject.getClass().getMethod("foo");
    assertEquals(null, method.invoke(fooObject));
}
Also used : Method(java.lang.reflect.Method) ClassBuilder(st.gravel.support.compiler.testtools.ClassBuilder) Test(org.junit.Test)

Example 45 with ClassBuilder

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

the class BlockTest method testReadWriteInstVarInNameBlock.

@Test
public void testReadWriteInstVarInNameBlock() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
    Class stClass = new ClassBuilder("FooObject_testReadWriteInstVarInNameBlock").method("foo: bar\n" + "|bl|\n" + "bl := bar nameBlock.\n" + "bar setNameInBlock: 'Fromage'.\n" + "^bl value").build();
    Class barClass = new ClassBuilder("BarObject_testReadWriteInstVarInNameBlock").method("setNameInBlock: anObject\n" + "	[name := anObject] value").method("nameBlock\n" + "	^[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)

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