Search in sources :

Example 6 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().expectAllWarnings(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", SourceKind.STRONG), source, config, testErrorReporter).ast;
    // verifying that all warnings were seen
    testErrorReporter.verifyHasEncounteredAllWarningsAndErrors();
    return script;
}
Also used : TestErrorReporter(com.google.javascript.rhino.testing.TestErrorReporter) NodeSubject.assertNode(com.google.javascript.rhino.testing.NodeSubject.assertNode) Node(com.google.javascript.rhino.Node) SimpleSourceFile(com.google.javascript.rhino.SimpleSourceFile)

Example 7 with TestErrorReporter

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

the class JsDocInfoParserTest method parse.

private JSDocInfo parse(String comment, JsDocParsing parseDocumentation, boolean parseFileOverview, String... warnings) {
    TestErrorReporter errorReporter = new TestErrorReporter().expectAllWarnings(warnings);
    Config config = Config.builder().setExtraAnnotationNames(extraAnnotations).setJsDocParsingMode(parseDocumentation).setSuppressionNames(extraSuppressions).setClosurePrimitiveNames(extraPrimitives).setLanguageMode(LanguageMode.ECMASCRIPT3).setParseInlineSourceMaps(true).setStrictMode(Config.StrictMode.SLOPPY).build();
    StaticSourceFile file = new SimpleSourceFile("testcode", SourceKind.STRONG);
    Node templateNode = IR.script();
    templateNode.setStaticSourceFile(file);
    JsDocInfoParser jsdocParser = new JsDocInfoParser(stream(comment), comment, 0, templateNode, config, errorReporter);
    jsdocParser.parse();
    this.prevLicense = jsdocParser.getLicenseText();
    errorReporter.verifyHasEncounteredAllWarningsAndErrors();
    final JSDocInfo result;
    if (parseFileOverview) {
        result = jsdocParser.getFileOverviewJSDocInfo();
    } else {
        result = jsdocParser.retrieveAndResetParsedJSDocInfo();
    }
    if (result != null) {
        assertThat(result.getTypeNodes()).comparingElementsUsing(transforming(NodeUtil::getSourceName, "has source name that")).doesNotContain(null);
    }
    return result;
}
Also used : TestErrorReporter(com.google.javascript.rhino.testing.TestErrorReporter) Node(com.google.javascript.rhino.Node) NodeSubject.assertNode(com.google.javascript.rhino.testing.NodeSubject.assertNode) SimpleSourceFile(com.google.javascript.rhino.SimpleSourceFile) StaticSourceFile(com.google.javascript.rhino.StaticSourceFile) JSDocInfo(com.google.javascript.rhino.JSDocInfo) NodeUtil(com.google.javascript.jscomp.NodeUtil)

Example 8 with TestErrorReporter

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

the class ParsingUtilTest method parse.

private static Node parse(String source, String... warnings) {
    TestErrorReporter testErrorReporter = new TestErrorReporter().expectAllWarnings(warnings);
    Config config = ParserRunner.createConfig(LanguageMode.ES_NEXT, Config.JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE, Config.RunMode.KEEP_GOING, null, true, StrictMode.STRICT);
    Node script = ParserRunner.parse(new SimpleSourceFile("input", SourceKind.STRONG), source, config, testErrorReporter).ast;
    // verifying that all warnings were seen
    testErrorReporter.verifyHasEncounteredAllWarningsAndErrors();
    return script;
}
Also used : TestErrorReporter(com.google.javascript.rhino.testing.TestErrorReporter) Node(com.google.javascript.rhino.Node) SimpleSourceFile(com.google.javascript.rhino.SimpleSourceFile)

Example 9 with TestErrorReporter

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

the class JsDocInfoParserTest method parseFull.

private Node parseFull(String code, String... warnings) {
    TestErrorReporter testErrorReporter = new TestErrorReporter().expectAllWarnings(warnings);
    Config config = Config.builder().setExtraAnnotationNames(extraAnnotations).setJsDocParsingMode(JsDocParsing.INCLUDE_DESCRIPTIONS_NO_WHITESPACE).setRunMode(RunMode.KEEP_GOING).setSuppressionNames(extraSuppressions).setLanguageMode(LanguageMode.ECMASCRIPT3).setParseInlineSourceMaps(true).setStrictMode(StrictMode.SLOPPY).build();
    ParseResult result = ParserRunner.parse(new SimpleSourceFile("source", SourceKind.STRONG), code, config, testErrorReporter);
    testErrorReporter.verifyHasEncounteredAllWarningsAndErrors();
    return result.ast;
}
Also used : TestErrorReporter(com.google.javascript.rhino.testing.TestErrorReporter) ParseResult(com.google.javascript.jscomp.parsing.ParserRunner.ParseResult) SimpleSourceFile(com.google.javascript.rhino.SimpleSourceFile)

Example 10 with TestErrorReporter

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

the class CompilerTypeTestCase method setUp.

@Before
public void setUp() throws Exception {
    errorReporter = new TestErrorReporter();
    initializeNewCompiler(getDefaultOptions());
}
Also used : TestErrorReporter(com.google.javascript.rhino.testing.TestErrorReporter) Before(org.junit.Before)

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