use of com.google.javascript.jscomp.type.FlowScope in project closure-compiler by google.
the class LinkedFlowScopeTest method verifyLongChains.
// Common chain verification for testLongChainN for all N.
private void verifyLongChains(FlowScope chainA, FlowScope chainB) {
FlowScope joined = join(chainA, chainB);
for (int i = 0; i < LONG_CHAIN_LENGTH; i++) {
assertTypeEquals(i % 2 == 0 ? NUMBER_TYPE : BOOLEAN_TYPE, chainA.getSlot("local" + i).getType());
assertTypeEquals(i % 3 == 0 ? STRING_TYPE : BOOLEAN_TYPE, chainB.getSlot("local" + i).getType());
JSType joinedSlotType = joined.getSlot("local" + i).getType();
if (i % 6 == 0) {
assertTypeEquals(createUnionType(STRING_TYPE, NUMBER_TYPE), joinedSlotType);
} else if (i % 2 == 0) {
assertTypeEquals(createUnionType(NUMBER_TYPE, BOOLEAN_TYPE), joinedSlotType);
} else if (i % 3 == 0) {
assertTypeEquals(createUnionType(STRING_TYPE, BOOLEAN_TYPE), joinedSlotType);
} else {
assertTypeEquals(BOOLEAN_TYPE, joinedSlotType);
}
}
assertScopesDiffer(chainA, chainB);
assertScopesDiffer(chainA, joined);
assertScopesDiffer(chainB, joined);
}
use of com.google.javascript.jscomp.type.FlowScope in project closure-compiler by google.
the class LinkedFlowScopeTest method testLongChain3.
/**
* Create a long chain of flow scopes where every 4 links in the chain
* contain a slot.
*/
public void testLongChain3() {
FlowScope chainA = localEntry.createChildFlowScope();
FlowScope chainB = localEntry.createChildFlowScope();
for (int i = 0; i < LONG_CHAIN_LENGTH * 7; i++) {
if (i % 7 == 0) {
int j = i / 7;
localScope.declare("local" + j, null, null, null);
chainA.inferSlotType("local" + j, j % 2 == 0 ? NUMBER_TYPE : BOOLEAN_TYPE);
chainB.inferSlotType("local" + j, j % 3 == 0 ? STRING_TYPE : BOOLEAN_TYPE);
}
chainA = chainA.createChildFlowScope();
chainB = chainB.createChildFlowScope();
}
verifyLongChains(chainA, chainB);
}
use of com.google.javascript.jscomp.type.FlowScope in project closure-compiler by google.
the class SemanticReverseAbstractInterpreterTest method testSheqCondition1.
/**
* Tests reverse interpretation of a SHEQ(NAME, NUMBER) expression.
*/
@SuppressWarnings("unchecked")
public void testSheqCondition1() throws Exception {
FlowScope blind = newScope();
testBinop(blind, Token.SHEQ, createVar(blind, "a", createUnionType(STRING_TYPE, NUMBER_TYPE)), createNumber(56), ImmutableSet.of(new TypedName("a", NUMBER_TYPE)), ImmutableSet.of(new TypedName("a", createUnionType(STRING_TYPE, NUMBER_TYPE))));
}
use of com.google.javascript.jscomp.type.FlowScope in project closure-compiler by google.
the class SemanticReverseAbstractInterpreterTest method testSheqCondition2.
/**
* Tests reverse interpretation of a SHEQ(NUMBER, NAME) expression.
*/
@SuppressWarnings("unchecked")
public void testSheqCondition2() throws Exception {
FlowScope blind = newScope();
testBinop(blind, Token.SHEQ, createNumber(56), createVar(blind, "a", createUnionType(STRING_TYPE, NUMBER_TYPE)), ImmutableSet.of(new TypedName("a", NUMBER_TYPE)), ImmutableSet.of(new TypedName("a", createUnionType(STRING_TYPE, NUMBER_TYPE))));
}
use of com.google.javascript.jscomp.type.FlowScope in project closure-compiler by google.
the class SemanticReverseAbstractInterpreterTest method testShneCondition2.
/**
* Tests reverse interpretation of a SHNE(NUMBER, NAME) expression.
*/
@SuppressWarnings("unchecked")
public void testShneCondition2() throws Exception {
FlowScope blind = newScope();
testBinop(blind, Token.SHNE, createNumber(56), createVar(blind, "a", createUnionType(STRING_TYPE, NUMBER_TYPE)), ImmutableSet.of(new TypedName("a", createUnionType(STRING_TYPE, NUMBER_TYPE))), ImmutableSet.of(new TypedName("a", NUMBER_TYPE)));
}
Aggregations