Search in sources :

Example 1 with TestErrorReporter

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

the class AttachJsdocsTest method parse.

private Node parse(String source, String... warnings) {
    TestErrorReporter testErrorReporter = new TestErrorReporter(null, warnings);
    Config config = ParserRunner.createConfig(mode, Config.JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE, Config.RunMode.KEEP_GOING, null, true, StrictMode.SLOPPY);
    Node script = ParserRunner.parse(new SimpleSourceFile("input", false), source, config, testErrorReporter).ast;
    // verifying that all warnings were seen
    testErrorReporter.assertHasEncounteredAllErrors();
    testErrorReporter.assertHasEncounteredAllWarnings();
    return script;
}
Also used : TestErrorReporter(com.google.javascript.rhino.testing.TestErrorReporter) Node(com.google.javascript.rhino.Node) SimpleSourceFile(com.google.javascript.rhino.SimpleSourceFile)

Example 2 with TestErrorReporter

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

the class TypeTransformationTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    errorReporter = new TestErrorReporter(null, null);
    initRecordTypeTests();
    typeVars = new ImmutableMap.Builder<String, JSType>().put("S", STRING_TYPE).put("N", NUMBER_TYPE).put("B", BOOLEAN_TYPE).put("BOT", NO_TYPE).put("TOP", ALL_TYPE).put("UNK", UNKNOWN_TYPE).put("CHKUNK", CHECKED_UNKNOWN_TYPE).put("SO", STRING_OBJECT_TYPE).put("NO", NUMBER_OBJECT_TYPE).put("BO", BOOLEAN_OBJECT_TYPE).put("NULL", NULL_TYPE).put("OBJ", OBJECT_TYPE).put("UNDEF", VOID_TYPE).put("ARR", ARRAY_TYPE).put("ARRNUM", type(ARRAY_TYPE, NUMBER_TYPE)).put("REC", recordTypeTest).put("NESTEDREC", nestedRecordTypeTest).put("ASYNCH", asynchRecord).build();
    nameVars = new ImmutableMap.Builder<String, String>().put("s", "string").put("n", "number").put("b", "boolean").build();
}
Also used : TestErrorReporter(com.google.javascript.rhino.testing.TestErrorReporter) RecordTypeBuilder(com.google.javascript.rhino.jstype.RecordTypeBuilder) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 3 with TestErrorReporter

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

the class ParserTest method doParse.

private ParserRunner.ParseResult doParse(String string, String... warnings) {
    TestErrorReporter testErrorReporter = new TestErrorReporter(null, warnings);
    StaticSourceFile file = new SimpleSourceFile("input", false);
    ParserRunner.ParseResult result = ParserRunner.parse(file, string, createConfig(), testErrorReporter);
    // check expected features if specified
    assertFS(result.features).contains(expectedFeatures);
    // verifying that all warnings were seen
    testErrorReporter.assertHasEncounteredAllErrors();
    testErrorReporter.assertHasEncounteredAllWarnings();
    return result;
}
Also used : TestErrorReporter(com.google.javascript.rhino.testing.TestErrorReporter) SimpleSourceFile(com.google.javascript.rhino.SimpleSourceFile) StaticSourceFile(com.google.javascript.rhino.StaticSourceFile) ParseResult(com.google.javascript.jscomp.parsing.ParserRunner.ParseResult)

Example 4 with TestErrorReporter

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

the class ParserTest method parseError.

/**
 * Verify that the given code has the given parse errors.
 * @return If in IDE mode, returns a partial tree.
 */
private Node parseError(String source, String... errors) {
    TestErrorReporter testErrorReporter = new TestErrorReporter(errors, null);
    ParseResult result = ParserRunner.parse(new SimpleSourceFile("input", false), source, createConfig(), testErrorReporter);
    Node script = result.ast;
    // check expected features if specified
    assertFS(result.features).contains(expectedFeatures);
    // verifying that all errors were seen
    testErrorReporter.assertHasEncounteredAllErrors();
    testErrorReporter.assertHasEncounteredAllWarnings();
    return script;
}
Also used : TestErrorReporter(com.google.javascript.rhino.testing.TestErrorReporter) ParseResult(com.google.javascript.jscomp.parsing.ParserRunner.ParseResult) NodeSubject.assertNode(com.google.javascript.jscomp.testing.NodeSubject.assertNode) Node(com.google.javascript.rhino.Node) SimpleSourceFile(com.google.javascript.rhino.SimpleSourceFile)

Example 5 with TestErrorReporter

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

the class NodeTest method testCheckTreeTypeAwareEqualsSame.

public void testCheckTreeTypeAwareEqualsSame() {
    TestErrorReporter testErrorReporter = new TestErrorReporter(null, null);
    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.NUMBER_TYPE));
    assertTrue(node1.isEquivalentToTyped(node2));
}
Also used : TestErrorReporter(com.google.javascript.rhino.testing.TestErrorReporter) JSTypeRegistry(com.google.javascript.rhino.jstype.JSTypeRegistry)

Aggregations

TestErrorReporter (com.google.javascript.rhino.testing.TestErrorReporter)7 SimpleSourceFile (com.google.javascript.rhino.SimpleSourceFile)3 JSTypeRegistry (com.google.javascript.rhino.jstype.JSTypeRegistry)3 ParseResult (com.google.javascript.jscomp.parsing.ParserRunner.ParseResult)2 Node (com.google.javascript.rhino.Node)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 NodeSubject.assertNode (com.google.javascript.jscomp.testing.NodeSubject.assertNode)1 StaticSourceFile (com.google.javascript.rhino.StaticSourceFile)1 RecordTypeBuilder (com.google.javascript.rhino.jstype.RecordTypeBuilder)1