Exemplo n.º 1
0
public class TypeInfererTest {
  private final TypeCheckerTestFixture fixture = TypeCheckerTestFixture.build();

  @Test
  public void canInferTypeOfBooleanLiteralsAsBoolean() {
    assertThat(inferType(new BooleanLiteralNode(true)), isType(CoreTypes.BOOLEAN));
    assertThat(inferType(new BooleanLiteralNode(false)), isType(CoreTypes.BOOLEAN));
  }

  @Test
  public void canInferTypeOfNumberLiteralsAsNumber() {
    assertThat(inferType(new NumberLiteralNode("2.2")), isType(CoreTypes.DOUBLE));
  }

  @Test
  public void canInferTypeOfStringLiteralsAsString() {
    assertThat(
        inferType(new StringLiteralNode("Everything's as if we never said")),
        isType(CoreTypes.STRING));
  }

  @Test
  public void canInferTypeOfUnitLiteralsAsUnit() {
    assertThat(inferType(Nodes.unit()), isType(CoreTypes.UNIT));
  }

  private TypeResult<Type> inferType(ExpressionNode expression) {
    return typeInferer().inferType(expression);
  }

  private TypeInferer typeInferer() {
    return fixture.get(TypeInferer.class);
  }

  private Matcher<TypeResult<Type>> isType(Type type) {
    return isSuccessWithValue(type);
  }
}
Exemplo n.º 2
0
 private TypeInferer typeInferer() {
   return fixture.get(TypeInferer.class);
 }