use of com.google.javascript.jscomp.type.FlowScope in project closure-compiler by google.
the class SemanticReverseAbstractInterpreterTest method testBinop.
private void testBinop(FlowScope[] blind, Token binop, Node left, Node right, Collection<TypedName> trueOutcome, Collection<TypedName> falseOutcome) {
Node condition = new Node(binop);
condition.addChildToBack(left);
condition.addChildToBack(right);
// true outcome.
FlowScope informedTrue = interpreter.getPreciserScopeKnowingConditionOutcome(condition, blind[0], Outcome.TRUE);
for (TypedName p : trueOutcome) {
assertTypeEquals(p.name, p.type, getVarType(informedTrue, p.name));
}
// false outcome.
FlowScope informedFalse = interpreter.getPreciserScopeKnowingConditionOutcome(condition, blind[0], Outcome.FALSE);
for (TypedName p : falseOutcome) {
assertTypeEquals(p.type, getVarType(informedFalse, p.name));
}
}
use of com.google.javascript.jscomp.type.FlowScope in project closure-compiler by google.
the class SemanticReverseAbstractInterpreterTest method testInequalitiesCondition1.
/**
* Tests reverse interpretation of a COMPARE(NAME, NUMBER) expression, where COMPARE can be LE,
* LT, GE or GT.
*/
@Test
public void testInequalitiesCondition1() {
for (Token op : Arrays.asList(Token.LT, Token.GT, Token.LE, Token.GE)) {
FlowScope[] blind = newScope();
testBinop(blind, op, createVar(blind, "a", createUnionType(getNativeStringType(), getNativeVoidType())), createNumber(8), 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 testTypeof1.
@Test
public void testTypeof1() {
FlowScope[] blind = newScope();
testBinop(blind, Token.EQ, new Node(Token.TYPEOF, createVar(blind, "a", getNativeObjectType())), Node.newString("function"), ImmutableSet.of(new TypedName("a", getNativeFunctionType())), ImmutableSet.of(new TypedName("a", getNativeObjectType())));
}
use of com.google.javascript.jscomp.type.FlowScope in project closure-compiler by google.
the class SemanticReverseAbstractInterpreterTest method testNameCondition.
/**
* Tests reverse interpretation of a NAME expression.
*/
@Test
public void testNameCondition() {
FlowScope[] blind = newScope();
Node condition = createVar(blind, "a", createNullableType(getNativeStringType()));
// true outcome.
FlowScope informedTrue = interpreter.getPreciserScopeKnowingConditionOutcome(condition, blind[0], Outcome.TRUE);
assertTypeEquals(getNativeStringType(), getVarType(informedTrue, "a"));
// false outcome.
FlowScope informedFalse = interpreter.getPreciserScopeKnowingConditionOutcome(condition, blind[0], Outcome.FALSE);
assertTypeEquals(createNullableType(getNativeStringType()), getVarType(informedFalse, "a"));
}
use of com.google.javascript.jscomp.type.FlowScope in project closure-compiler by google.
the class SemanticReverseAbstractInterpreterTest method testEqCondition3.
/**
* Tests reverse interpretation of a EQ(NAME, NULL) expression.
*/
@Test
public void testEqCondition3() {
FlowScope[] blind = newScope();
// (number,undefined,null)
JSType nullableOptionalNumber = createUnionType(getNativeNullType(), getNativeVoidType(), getNativeNumberType());
// (null,undefined)
JSType nullUndefined = createUnionType(getNativeVoidType(), getNativeNullType());
testBinop(blind, Token.EQ, createVar(blind, "a", nullableOptionalNumber), createNull(), ImmutableSet.of(new TypedName("a", nullUndefined)), ImmutableSet.of(new TypedName("a", getNativeNumberType())));
}
Aggregations