Package gololang

Examples of gololang.Tuple


    Method nested_tuples = moduleClass.getMethod("nested_tuples");
    Object result = nested_tuples.invoke(null);
    assertThat(result, instanceOf(Tuple.class));

    Tuple tuple = (Tuple) result;
    assertThat(tuple.size(), is(4));
    assertThat((Integer) tuple.get(0), is(1));
    assertThat((Integer) tuple.get(1), is(2));
    assertThat((Integer) tuple.get(2), is(3));
    assertThat(tuple.get(3), instanceOf(Tuple.class));

    Tuple nestedTuple = (Tuple) tuple.get(3);
    assertThat(nestedTuple.size(), is(2));
    assertThat((Integer) nestedTuple.get(0), is(10));
    assertThat((Integer) nestedTuple.get(1), is(20));

    Method empty_tuple = moduleClass.getMethod("empty_tuple");
    result = empty_tuple.invoke(null);
    assertThat(result, instanceOf(Tuple.class));
    tuple = (Tuple) result;
View Full Code Here


    Method mrbean_struct = moduleClass.getMethod("mrbean_struct");
    result = mrbean_struct.invoke(null);
    assertThat(result, instanceOf(GoloStruct.class));
    GoloStruct struct = (GoloStruct) result;

    Tuple tuple = struct.members();
    assertThat(tuple.size(), is(2));
    assertThat(tuple.get(0), is((Object) "name"));
    assertThat(tuple.get(1), is((Object) "email"));

    tuple = struct.values();
    assertThat(tuple.size(), is(2));
    assertThat(tuple.get(0), is((Object) "Mr Bean"));
    assertThat(tuple.get(1), is((Object) "mrbean@outlook.com"));

    Iterator<Tuple> structIterator = struct.iterator();
    assertThat(structIterator.hasNext(), is(true));
    tuple = structIterator.next();
    assertThat(tuple.size(), is(2));
    assertThat(tuple.get(0), is((Object) "name"));
    assertThat(tuple.get(1), is((Object) "Mr Bean"));
    assertThat(structIterator.hasNext(), is(true));
    tuple = structIterator.next();
    assertThat(tuple.size(), is(2));
    assertThat(tuple.get(0), is((Object) "email"));
    assertThat(tuple.get(1), is((Object) "mrbean@outlook.com"));
    assertThat(structIterator.hasNext(), is(false));

    assertThat(struct.get("name"), is((Object) "Mr Bean"));
    assertThat(struct.get("email"), is((Object) "mrbean@outlook.com"));
    try {
      struct.get("foo");
      fail("An IllegalArgumentException was expected");
    } catch (IllegalArgumentException ignored) {
    }

    struct = struct.copy();
    struct.set("name", "John");
    assertThat(struct.get("name"), is((Object) "John"));
    try {
      struct.set("foo", "bar");
      fail("An IllegalArgumentException was expected");
    } catch (IllegalArgumentException ignored) {
    }

    assertThat(struct.isFrozen(), is(false));
    struct = struct.frozenCopy();
    assertThat(struct.isFrozen(), is(true));
    assertThat(struct.copy().isFrozen(), is(false));
    try {
      struct.set("name", "John");
      fail("An IllegalStateException was expected");
    } catch (IllegalStateException ignored) {
    }

    Method mrbean_toString = moduleClass.getMethod("mrbean_toString");
    result = mrbean_toString.invoke(null);
    assertThat(result, instanceOf(String.class));
    assertThat((String) result, is("struct Contact{name=Mr Bean, email=mrbean@outlook.com}"));

    Method mrbean_copy = moduleClass.getMethod("mrbean_copy");
    result = mrbean_copy.invoke(null);
    assertThat(result, instanceOf(Tuple.class));
    tuple = (Tuple) result;
    assertThat(tuple.get(0).toString(), is("struct Contact{name=Mr Bean, email=mrbean@outlook.com}"));
    assertThat(tuple.get(1).toString(), is("struct Contact{name=Mr Bean, email=mrbean@outlook.com}"));
    assertThat(tuple.get(0), not(sameInstance(tuple.get(1))));

    Method mrbean_frozenCopy = moduleClass.getMethod("mrbean_frozenCopy");
    result = mrbean_frozenCopy.invoke(null);
    assertThat(result, instanceOf(Tuple.class));
    tuple = (Tuple) result;
    assertThat(tuple.get(0).toString(), is("struct Contact{name=Mr Bean, email=mrbean@outlook.com}"));
    assertThat(tuple.get(1).toString(), is("struct Contact{name=Mr Bean, email=mrbean@outlook.com}"));
    assertThat(tuple.get(0), not(sameInstance(tuple.get(1))));
    try {
      Object instance = tuple.get(1);
      Method name = instance.getClass().getMethod("name", Object.class);
      name.invoke(instance, "Foo");
      fail("A frozen struct shall not allow field mutation");
      name.invoke(tuple.get(0), "Foo");
    } catch (InvocationTargetException e) {
      if (!(e.getCause() instanceof IllegalStateException)) {
        throw e;
      }
    }

    Method mrbean_hashCode = moduleClass.getMethod("mrbean_hashCode");
    result = mrbean_hashCode.invoke(null);
    assertThat(result, instanceOf(Tuple.class));
    tuple = (Tuple) result;
    assertThat(tuple.get(0).hashCode(), not(tuple.get(1).hashCode()));
    assertThat(tuple.get(2).hashCode(), is(tuple.get(3).hashCode()));

    Method mrbean_equals = moduleClass.getMethod("mrbean_equals");
    result = mrbean_equals.invoke(null);
    assertThat(result, instanceOf(Tuple.class));
    tuple = (Tuple) result;
    assertThat(tuple.get(0), not(tuple.get(1)));
    assertThat(tuple.get(0), not(new Object()));
    assertThat(tuple.get(0), not(tuple.get(2)));
    assertThat(tuple.get(2), is(tuple.get(3)));
    assertThat(tuple.get(2), not(tuple.get(4)));
    assertThat(tuple.get(2), not(tuple.get(5)));
    assertThat(tuple.get(2), not(tuple.get(0)));

    Method immutable_factory = moduleClass.getMethod("immutable_factory");
    result = immutable_factory.invoke(null);
    assertThat(result, instanceOf(Tuple.class));
    tuple = (Tuple) result;
    assertThat(tuple.get(0), is(tuple.get(1)));

    Method fun_foo_bar_baz = moduleClass.getMethod("fun_foo_bar_baz");
    result = fun_foo_bar_baz.invoke(null);
    assertThat(result, instanceOf(GoloStruct.class));
    struct = (GoloStruct) result;
    assertThat(struct.members().size(), is(2));
    assertThat(struct.values().size(), is(2));
    structIterator = struct.iterator();
    assertThat(structIterator.hasNext(), is(true));
    assertThat(structIterator.next(), is(new Tuple("foo", 1)));
    assertThat(structIterator.hasNext(), is(true));
    assertThat(structIterator.next(), is(new Tuple("baz", 3)));
    assertThat(structIterator.hasNext(), is(false));
    assertThat(struct.get("foo"), is((Object) 1));
    try {
      struct.get("_bar");
      fail("An IllegalArgumentException was expected");
View Full Code Here

    Class<?> moduleClass = compileAndLoadGoloModule(SRC, "async-features.golo");

    Method check_map = moduleClass.getMethod("check_map");
    Object result = check_map.invoke(null);
    assertThat(result, instanceOf(Tuple.class));
    Tuple tuple = (Tuple) result;
    assertThat(tuple.size(), is(2));
    assertThat(tuple.get(0), is((Object) "Ok!"));
    assertThat(tuple.get(1), instanceOf(RuntimeException.class));
  }
View Full Code Here

    Class<?> moduleClass = compileAndLoadGoloModule(SRC, "async-features.golo");

    Method check_flatMap = moduleClass.getMethod("check_flatMap");
    Object result = check_flatMap.invoke(null);
    assertThat(result, instanceOf(Tuple.class));
    Tuple tuple = (Tuple) result;
    assertThat(tuple.size(), is(2));
    assertThat(tuple.get(0), is((Object) "Ok!"));
    assertThat(tuple.get(1), instanceOf(RuntimeException.class));
  }
View Full Code Here

    Class<?> moduleClass = compileAndLoadGoloModule(SRC, "async-features.golo");

    Method check_filter = moduleClass.getMethod("check_filter");
    Object result = check_filter.invoke(null);
    assertThat(result, instanceOf(Tuple.class));
    Tuple tuple = (Tuple) result;
    assertThat(tuple.size(), is(3));
    assertThat(tuple.get(0), is((Object) "Ok"));
    assertThat(tuple.get(1), instanceOf(NoSuchElementException.class));
    assertThat(tuple.get(2), instanceOf(RuntimeException.class));
  }
View Full Code Here

    Class<?> moduleClass = compileAndLoadGoloModule(SRC, "async-features.golo");

    Method check_fallbackTo = moduleClass.getMethod("check_fallbackTo");
    Object result = check_fallbackTo.invoke(null);
    assertThat(result, instanceOf(Tuple.class));
    Tuple tuple = (Tuple) result;
    assertThat(tuple.size(), is(3));
    assertThat(tuple.get(0), is((Object) "Ok"));
    assertThat(tuple.get(1), is((Object) "Yeah"));
    assertThat(tuple.get(2), instanceOf(AssertionError.class));
  }
View Full Code Here

    Class<?> moduleClass = compileAndLoadGoloModule(SRC, "async-features.golo");

    Method check_reduce = moduleClass.getMethod("check_reduce");
    Object result = check_reduce.invoke(null);
    assertThat(result, instanceOf(Tuple.class));
    Tuple tuple = (Tuple) result;
    assertThat(tuple.size(), is(2));
    assertThat(tuple.get(0), is((Object) "abc"));
    assertThat(tuple.get(1), instanceOf(RuntimeException.class));
  }
View Full Code Here

TOP

Related Classes of gololang.Tuple

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.