Package st.gravel.support.compiler.testtools

Examples of st.gravel.support.compiler.testtools.ClassBuilder


  public void test_whileFalse_() throws NoSuchMethodException,
      SecurityException, IllegalAccessException,
      IllegalArgumentException, InvocationTargetException,
      InstantiationException {

    Class stClass = new ClassBuilder("FooObject_test_whileFalse_").method(
        "foo: sz  | sum arr | arr := (1 to: sz) asArray.  sum := 0. [sum := sum + arr first. arr size = 1] whileFalse: [arr := arr tail].  ^sum").build();

    Object fooObject = stClass.newInstance();
    Method method = fooObject.getClass().getMethod("foo_", Object.class);
    assertEquals(Integer.valueOf(1), method.invoke(fooObject, 1));
View Full Code Here


  public void test_whileTrue() throws NoSuchMethodException,
      SecurityException, IllegalAccessException,
      IllegalArgumentException, InvocationTargetException,
      InstantiationException {

    Class stClass = new ClassBuilder("FooObject_test_whileTrue").method(
        "foo: sz | sum arr | arr := (1 to: sz) asArray.  sum := 0. [sum := sum + arr first.  arr := arr tail.  arr isEmpty not] whileTrue.  ^sum").build();

    Object fooObject = stClass.newInstance();
    Method method = fooObject.getClass().getMethod("foo_", Object.class);
    assertEquals(Integer.valueOf(1), method.invoke(fooObject, 1));
View Full Code Here

  public void test_whileTrue_() throws NoSuchMethodException,
      SecurityException, IllegalAccessException,
      IllegalArgumentException, InvocationTargetException,
      InstantiationException {

    Class stClass = new ClassBuilder("FooObject_test_whileTrue_").method(
        "foo: sz | sum arr | arr := (1 to: sz) asArray.  sum := 0. [sum := sum + arr first. arr size ~= 1] whileTrue: [arr := arr tail].  ^sum").build();

    Object fooObject = stClass.newInstance();
    Method method = fooObject.getClass().getMethod("foo_", Object.class);
    assertEquals(Integer.valueOf(1), method.invoke(fooObject, 1));
View Full Code Here

  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));
View Full Code Here

  @Test
  public void test_BigInt_to_int_do_() throws NoSuchMethodException,
      SecurityException, IllegalAccessException,
      IllegalArgumentException, InvocationTargetException,
      InstantiationException {
    Class stClass = new ClassBuilder("FooObject_test_BigInt_to_int_do_").
        method("start Transcript cr; show: 'start'. ^2934758938247592387459832475").
        method("stop Transcript cr; show: 'stop'. ^7").
        method("foo | sum | sum := 0. self start to: self stop do: [:i | sum := sum + i].  ^sum").
        build();
View Full Code Here

  public void test_BigInt_to_BigInt_do_() throws NoSuchMethodException,
      SecurityException, IllegalAccessException,
      IllegalArgumentException, InvocationTargetException,
      InstantiationException {

    Class stClass = new ClassBuilder("FooObject_test_BigInt_to_BigInt_do_").method(
        "foo | sum | sum := 0. 2934758938247592387459832475 to: 2934758938247592387459832475 do: [:i | sum := sum + i].  ^sum").build();

    Object fooObject = stClass.newInstance();
    Method method = fooObject.getClass().getMethod("foo");
    assertEquals(new BigInteger("2934758938247592387459832475"), method.invoke(fooObject));
View Full Code Here

  }

  @Test
  public void test_int_to_BigInt_do_() throws Throwable {

    Class stClass = new ClassBuilder("FooObject_test_int_to_BigInt_do_").
        instVar("startRuns").
        instVar("stopRuns").
        method("initialize startRuns := 0. stopRuns := 0").
        method("validateRun ^startRuns = 1 and: [stopRuns = 1]").
        method("start startRuns := startRuns + 1. ^16r7FFFFFFF").
View Full Code Here

  @Test
  public void testCreateInstance() throws InstantiationException,
      IllegalAccessException, IllegalArgumentException,
      InvocationTargetException, NoSuchMethodException, SecurityException {

    Class classA = new ClassBuilder("ClassA")
        .method("foo ^3")
        .build();

    Class classB = new ClassBuilder("ClassB")
    .method("newClassA ^ClassA new")
    .build();

    Object classBObject = classB.newInstance();
    Method method = classBObject.getClass().getMethod("newClassA");
View Full Code Here

  @Test
  public void testSendClassMethod() throws InstantiationException,
      IllegalAccessException, IllegalArgumentException,
      InvocationTargetException, NoSuchMethodException, SecurityException {

    Class classA = new ClassBuilder("ClassA_testSendClassMethod")
        .classMethod("foo ^3")
        .build();

    Class classB = new ClassBuilder("ClassB_testSendClassMethod")
    .method("bar ^ClassA_testSendClassMethod foo")
    .build();

    Object classBObject = classB.newInstance();
    Method method = classBObject.getClass().getMethod("bar");
View Full Code Here

  public void test_String_equals() throws NoSuchMethodException,
      SecurityException, IllegalAccessException,
      IllegalArgumentException, InvocationTargetException,
      InstantiationException {

    Class stClass = new ClassBuilder("FooObject_String_equals").
        method("foo: x equals: y ^x=y").
        method("foo ^self foo: 'abc' equals: 'ab','c'").
        build();

    Object fooObject = stClass.newInstance();
View Full Code Here

TOP

Related Classes of st.gravel.support.compiler.testtools.ClassBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.