Search in sources :

Example 11 with TestErrorReporter

use of com.google.javascript.rhino.testing.TestErrorReporter in project closure-compiler by google.

the class NodeTest method testSerializeProperties_typeBeforeCast.

@Test
public void testSerializeProperties_typeBeforeCast() {
    TestErrorReporter testErrorReporter = new TestErrorReporter();
    JSTypeRegistry registry = new JSTypeRegistry(testErrorReporter);
    Node node = Node.newString(Token.NAME, "f");
    node.setJSTypeBeforeCast(registry.getNativeType(JSTypeNative.NUMBER_TYPE));
    EnumSet<NodeProperty> result = node.serializeProperties();
    // Special case: Rhino node prop TYPE_BEFORE_CAST is converted to NodeProperty.COLOR_FROM_CAST
    assertThat(result).containsExactly(NodeProperty.COLOR_FROM_CAST);
}
Also used : TestErrorReporter(com.google.javascript.rhino.testing.TestErrorReporter) JSTypeRegistry(com.google.javascript.rhino.jstype.JSTypeRegistry) NodeProperty(com.google.javascript.jscomp.serialization.NodeProperty) NodeSubject.assertNode(com.google.javascript.rhino.testing.NodeSubject.assertNode) Test(org.junit.Test)

Example 12 with TestErrorReporter

use of com.google.javascript.rhino.testing.TestErrorReporter in project closure-compiler by google.

the class NodeTest method testCheckTreeTypeAwareEqualsDifferent.

@Test
public void testCheckTreeTypeAwareEqualsDifferent() {
    TestErrorReporter testErrorReporter = new TestErrorReporter();
    JSTypeRegistry registry = new JSTypeRegistry(testErrorReporter);
    Node node1 = Node.newString(Token.NAME, "f");
    node1.setJSType(registry.getNativeType(JSTypeNative.NUMBER_TYPE));
    Node node2 = Node.newString(Token.NAME, "f");
    node2.setJSType(registry.getNativeType(JSTypeNative.STRING_TYPE));
    assertThat(node1.isEquivalentToTyped(node2)).isFalse();
    testErrorReporter.verifyHasEncounteredAllWarningsAndErrors();
}
Also used : TestErrorReporter(com.google.javascript.rhino.testing.TestErrorReporter) JSTypeRegistry(com.google.javascript.rhino.jstype.JSTypeRegistry) NodeSubject.assertNode(com.google.javascript.rhino.testing.NodeSubject.assertNode) Test(org.junit.Test)

Aggregations

TestErrorReporter (com.google.javascript.rhino.testing.TestErrorReporter)12 NodeSubject.assertNode (com.google.javascript.rhino.testing.NodeSubject.assertNode)7 SimpleSourceFile (com.google.javascript.rhino.SimpleSourceFile)6 Node (com.google.javascript.rhino.Node)4 JSTypeRegistry (com.google.javascript.rhino.jstype.JSTypeRegistry)4 Test (org.junit.Test)4 ParseResult (com.google.javascript.jscomp.parsing.ParserRunner.ParseResult)3 StaticSourceFile (com.google.javascript.rhino.StaticSourceFile)2 Before (org.junit.Before)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 NodeUtil (com.google.javascript.jscomp.NodeUtil)1 NodeProperty (com.google.javascript.jscomp.serialization.NodeProperty)1 JSDocInfo (com.google.javascript.rhino.JSDocInfo)1 RecordTypeBuilder (com.google.javascript.rhino.jstype.RecordTypeBuilder)1