use of com.google.javascript.jscomp.type.FlowScope in project closure-compiler by google.
the class SemanticReverseAbstractInterpreterTest method testInequalitiesCondition3.
/**
* Tests reverse interpretation of a COMPARE(NUMBER-untyped, NAME) expression, where COMPARE can
* be LE, LT, GE or GT.
*/
@Test
public void testInequalitiesCondition3() {
for (Token op : Arrays.asList(Token.LT, Token.GT, Token.LE, Token.GE)) {
FlowScope[] blind = newScope();
testBinop(blind, op, createUntypedNumber(8), createVar(blind, "a", createUnionType(getNativeStringType(), getNativeVoidType())), ImmutableSet.of(new TypedName("a", getNativeStringType())), ImmutableSet.of(new TypedName("a", createUnionType(getNativeStringType(), getNativeVoidType()))));
}
}
use of com.google.javascript.jscomp.type.FlowScope in project closure-compiler by google.
the class SemanticReverseAbstractInterpreterTest method newScope.
private FlowScope[] newScope() {
TypedScope globalScope = TypedScope.createGlobalScope(new Node(Token.ROOT));
functionScope = new TypedScope(globalScope, new Node(Token.FUNCTION));
return new FlowScope[] { LinkedFlowScope.createEntryLattice(compiler, functionScope) };
}
use of com.google.javascript.jscomp.type.FlowScope in project closure-compiler by google.
the class LinkedFlowScopeTest method testJoin3.
@Test
public void testJoin3() {
localScope.declare("localC", null, getNativeStringType(), null, true);
localScope.declare("localD", null, getNativeStringType(), null, true);
FlowScope childA = localEntry.inferSlotType("localC", getNativeNumberType());
FlowScope childB = localEntry.inferSlotType("localD", getNativeBooleanType());
FlowScope joined = join(childB, childA);
assertTypeEquals(createUnionType(getNativeStringType(), getNativeNumberType()), joined.getSlot("localC").getType());
assertTypeEquals(createUnionType(getNativeStringType(), getNativeBooleanType()), joined.getSlot("localD").getType());
joined = join(childA, childB);
assertTypeEquals(createUnionType(getNativeStringType(), getNativeNumberType()), joined.getSlot("localC").getType());
assertTypeEquals(createUnionType(getNativeStringType(), getNativeBooleanType()), joined.getSlot("localD").getType());
assertWithMessage("Join should be symmetric").that(join(childA, childB)).isEqualTo(join(childB, childA));
}
use of com.google.javascript.jscomp.type.FlowScope in project closure-compiler by google.
the class LinkedFlowScopeTest method testJoin1.
@Test
public void testJoin1() {
FlowScope childA = localEntry.inferSlotType("localB", getNativeNumberType());
FlowScope childAB = childA.inferSlotType("localB", getNativeStringType());
FlowScope childB = localEntry.inferSlotType("localB", getNativeBooleanType());
assertTypeEquals(getNativeStringType(), childAB.getSlot("localB").getType());
assertTypeEquals(getNativeBooleanType(), childB.getSlot("localB").getType());
assertThat(childB.getSlot("localA").getType()).isNull();
FlowScope joined = join(childB, childAB);
assertTypeEquals(createUnionType(getNativeStringType(), getNativeBooleanType()), joined.getSlot("localB").getType());
assertThat(joined.getSlot("localA").getType()).isNull();
joined = join(childAB, childB);
assertTypeEquals(createUnionType(getNativeStringType(), getNativeBooleanType()), joined.getSlot("localB").getType());
assertThat(joined.getSlot("localA").getType()).isNull();
assertWithMessage("Join should be symmetric").that(join(childAB, childB)).isEqualTo(join(childB, childAB));
}
use of com.google.javascript.jscomp.type.FlowScope in project closure-compiler by google.
the class LinkedFlowScopeTest method testDiffer2.
@Test
public void testDiffer2() {
FlowScope childA = localEntry.inferSlotType("localA", getNativeNumberType());
FlowScope childB = localEntry.inferSlotType("localA", getNativeNoType());
assertScopesDiffer(childA, childB);
}
Aggregations