use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testInsertBeforeWithNonJSDocLineComment.
@Test
public void testInsertBeforeWithNonJSDocLineComment() {
String before = "var someRandomCode = {};";
String after = "// some comment \ngoog.foo();";
Compiler compiler = getCompiler(before + after);
Node root = compileToScriptRoot(compiler);
Node newNode = IR.exprResult(IR.call(IR.getprop(IR.name("goog2"), "get"), IR.string("service")));
SuggestedFix fix = new SuggestedFix.Builder().insertBefore(root.getLastChild(), newNode, compiler).build();
CodeReplacement replacement = CodeReplacement.create(before.length(), 0, "goog2.get('service');\n");
assertReplacement(fix, replacement);
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testInsertArguments_emptyArguments.
@Test
public void testInsertArguments_emptyArguments() {
String before = "goog.dom.classes.add(";
String after = ");";
Compiler compiler = getCompiler(before + after);
Node root = compileToScriptRoot(compiler);
SuggestedFix fix = new SuggestedFix.Builder().insertArguments(root.getFirstFirstChild(), 0, "baz").build();
CodeReplacement replacement = CodeReplacement.create(before.length(), 0, "baz");
assertReplacement(fix, replacement);
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testDeleteArgumentMiddleWithLineComment.
@Test
public void testDeleteArgumentMiddleWithLineComment() {
String originalCode = "f(a, // blah \n b, c);";
String expectedCode = "f(a, c);";
Compiler compiler = getCompiler(originalCode);
Node root = compileToScriptRoot(compiler);
SuggestedFix fix = new SuggestedFix.Builder().deleteArgument(root.getFirstFirstChild(), 1).build();
assertChanges(fix, "", originalCode, expectedCode);
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testRenameProperty_justPropertyName.
@Test
public void testRenameProperty_justPropertyName() {
String input = "obj.test.property";
Compiler compiler = getCompiler(input);
Node root = compileToScriptRoot(compiler);
SuggestedFix fix = new SuggestedFix.Builder().rename(root.getFirstFirstChild(), "renamedProperty").build();
CodeReplacement replacement = CodeReplacement.create(9, "property".length(), "renamedProperty");
assertReplacement(fix, replacement);
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testInsertArguments_lastArgument.
@Test
public void testInsertArguments_lastArgument() {
String before = "goog.dom.classes.add(foo, bar";
String after = ");";
Compiler compiler = getCompiler(before + after);
Node root = compileToScriptRoot(compiler);
SuggestedFix fix = new SuggestedFix.Builder().insertArguments(root.getFirstFirstChild(), 2, "baz").build();
CodeReplacement replacement = CodeReplacement.create(before.length(), 0, ", baz");
assertReplacement(fix, replacement);
}
Aggregations