use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class IntegrationTestCase method test.
/**
* Asserts that when compiling with the given compiler options,
* {@code original} is transformed into {@code compiled}.
*/
protected void test(CompilerOptions options, String[] original, String[] compiled) {
Compiler compiler = compile(options, original);
Node root = compiler.getRoot().getLastChild();
// Verify that there are no unexpected errors before checking the compiled output
assertWithMessage("Expected no warnings or errors\n" + "Errors: \n" + Joiner.on("\n").join(compiler.getErrors()) + "\n" + "Warnings: \n" + Joiner.on("\n").join(compiler.getWarnings())).that(compiler.getErrors().size() + compiler.getWarnings().size()).isEqualTo(0);
if (compiled != null) {
Node expectedRoot = parseExpectedCode(compiled, options);
assertNode(root).usingSerializer(compiler::toSource).isEqualTo(expectedRoot);
}
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class IntegrationTestCase method test.
/**
* Asserts that when compiling with the given compiler options, there is an error or warning.
*/
protected void test(CompilerOptions options, String[] original, String[] compiled, DiagnosticGroup[] warnings) {
Compiler compiler = compile(options, original);
checkUnexpectedErrorsOrWarnings(compiler, warnings.length);
if (compiled != null) {
Node root = compiler.getRoot().getLastChild();
Node expectedRoot = parseExpectedCode(compiled, options);
assertNode(root).usingSerializer(compiler::toSource).isEqualTo(expectedRoot);
}
assertThat(ImmutableList.builder().addAll(compiler.getErrors()).addAll(compiler.getWarnings()).build()).comparingElementsUsing(JSCompCorrespondences.OWNING_DIAGNOSTIC_GROUP).containsExactly(warnings);
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class IntegrationTestCase method testNoWarnings.
protected void testNoWarnings(CompilerOptions options, String[] sources) {
Compiler compiler = compile(options, sources);
assertThat(compiler.getErrors()).isEmpty();
assertThat(compiler.getWarnings()).isEmpty();
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class IntegrationTest method testStrictWarningsGuard.
@Test
public void testStrictWarningsGuard() {
CompilerOptions options = createCompilerOptions();
options.setCheckTypes(true);
options.addWarningsGuard(new StrictWarningsGuard());
Compiler compiler = compile(options, "/** @return {number} */ function f() { return true; }");
assertThat(compiler.getErrors()).hasSize(1);
assertThat(compiler.getWarnings()).isEmpty();
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class TypedAstIntegrationTest method removesRegExpCallsIfUnsafelyReferenced.
@Test
public void removesRegExpCallsIfUnsafelyReferenced() throws IOException {
precompileLibrary(extern(new TestExternsBuilder().addRegExp().addConsole().build()), code(//
"(/abc/gi).exec('');", "console.log(RegExp.$1);"));
CompilerOptions options = new CompilerOptions();
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
Compiler compiler = compileTypedAstShards(options);
Node expectedRoot = parseExpectedCode("(/abc/gi).exec(''); console.log(RegExp.$1);");
assertNode(compiler.getRoot().getSecondChild()).usingSerializer(compiler::toSource).isEqualTo(expectedRoot);
}
Aggregations