Ejemplo n.º 1
0
  @Test
  public void shouldLoadFunction() {
    ObjectDOS wrapper =
        reader.read(
            "anObject\n"
                + "  {}\n"
                + "  {\n"
                + "    aFunction:Does:This:\n"
                + "      {variable.variable2.}\n"
                + "      {1=FunctionCall.2=SetObject.3=Push.4=PushSymbol.5#34.6.7.}\n"
                + "  }");

    ObjectDOS actual = wrapper.getSlot(Symbol.get("anObject"));

    FunctionDOS function = (FunctionDOS) actual.getFunction(Symbol.get("aFunction:Does:This:"));

    assertThat(function.getRequiredArguments()[0].value(), is("variable"));
    assertThat(function.getRequiredArguments()[1].value(), is("variable2"));

    assertThat(function.getOpCodes()[0], is(OpCode.FunctionCall.class));
    assertThat(function.getOpCodes()[1], is(OpCode.SetObject.class));
    assertThat(function.getOpCodes()[2], is(OpCode.Push.class));
    assertThat(function.getOpCodes()[3], is(OpCode.PushSymbol.class));
    assertThat(function.getOpCodes()[4], is(OpCode.CreateValueObject.class));
    assertThat(function.getOpCodes()[5], is(OpCode.StartOpCodeList.class));
    assertThat(function.getOpCodes()[6], is(OpCode.EndOpCodeList.class));
  }
Ejemplo n.º 2
0
  @Test
  public void shouldLoadEmptyFunction() {
    ObjectDOS wrapper = reader.read("anObject{}{aFunction:Does:This:{}{}}");

    ObjectDOS actual = wrapper.getSlot(Symbol.get("anObject"));

    FunctionDOS function = (FunctionDOS) actual.getFunction(Symbol.get("aFunction:Does:This:"));
    assertThat(function.getOpCodes().length, is(0));
    assertThat(function.getRequiredArguments().length, is(0));
  }
Ejemplo n.º 3
0
  @Test
  public void shouldLoadNestedObject() {
    ObjectDOS wrapper =
        reader.read("anObject{nestedObject{deeplyNestedObject{}{}}{}anotherNestedObject{}{}}{}");

    ObjectDOS actual = wrapper.getSlot(Symbol.get("anObject"));

    assertThat(actual.getFunctions().size(), is(0));
    assertThat(
        actual.getSlot(Symbol.get("nestedObject")).getSlot(Symbol.get("deeplyNestedObject")),
        notNullValue());
    assertThat(actual.getSlot(Symbol.get("anotherNestedObject")), notNullValue());
  }
Ejemplo n.º 4
0
  @Test
  public void shouldDereferenceReferences() {
    ObjectDOS wrapper =
        reader.read(
            "anObject\n"
                + "  {anotherObject{referencedObject{}{}}{}}\n"
                + "  {}\n"
                + "anotherObject{referencingObject$anObject.anotherObject.referencedObject$\n"
                + "someOtherObject{}{} andAnotherReference$anObject$}{}");

    ObjectDOS referencedObject =
        wrapper
            .getSlot(Symbol.get("anObject"))
            .getSlot(Symbol.get("anotherObject"))
            .getSlot(Symbol.get("referencedObject"));
    ObjectDOS referencingObject =
        wrapper.getSlot(Symbol.get("anotherObject")).getSlot(Symbol.get("referencingObject"));

    assertThat(referencingObject, is(referencedObject));

    referencedObject = wrapper.getSlot(Symbol.get("anObject"));
    referencingObject =
        wrapper.getSlot(Symbol.get("anotherObject")).getSlot(Symbol.get("andAnotherReference"));

    assertThat(referencingObject, is(referencedObject));
  }
Ejemplo n.º 5
0
  @Test
  public void shouldLoadSimpleObject() {

    ObjectDOS wrapper = reader.read("anObject1{}{}");

    ObjectDOS actual = wrapper.getSlot(Symbol.get("anObject1"));

    assertThat(actual.getFunctions().size(), is(0));
    assertThat(actual.getSlots().size(), is(0));
  }
Ejemplo n.º 6
0
  @Test
  public void shouldLoadFunctionWithMnemonics() {
    ObjectDOS wrapper =
        reader.read(
            "anObject\n"
                + "  {}\n"
                + "  {\n"
                + "    aFunction:Does:This:\n"
                + "      {variable.variable2.}\n"
                + "      {CALL=FunctionCall.OBJ=SetObject.PUSH=Push.SYM=PushSymbol.VAL#34.START.END.}\n"
                + "  }");

    ObjectDOS actual = wrapper.getSlot(Symbol.get("anObject"));

    FunctionDOS function = (FunctionDOS) actual.getFunction(Symbol.get("aFunction:Does:This:"));

    assertThat(function.getOpCodes()[0], is(OpCode.FunctionCall.class));
    assertThat(function.getOpCodes()[1], is(OpCode.SetObject.class));
    assertThat(function.getOpCodes()[2], is(OpCode.Push.class));
    assertThat(function.getOpCodes()[3], is(OpCode.PushSymbol.class));
    assertThat(function.getOpCodes()[4], is(OpCode.CreateValueObject.class));
    assertThat(function.getOpCodes()[5], is(OpCode.StartOpCodeList.class));
    assertThat(function.getOpCodes()[6], is(OpCode.EndOpCodeList.class));
  }