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 testDelete_spaceBeforeNode.
@Test
public void testDelete_spaceBeforeNode() {
String before = "var foo = new Bar();";
String after = "\n\nvar baz = new Baz();";
String input = before + after;
Compiler compiler = getCompiler(input);
Node root = compileToScriptRoot(compiler);
SuggestedFix fix = new SuggestedFix.Builder().delete(root.getLastChild()).build();
CodeReplacement replacement = CodeReplacement.create(before.length(), after.length(), "");
assertReplacement(fix, replacement);
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testReplaceText.
@Test
public void testReplaceText() {
String input = "var foo = new Bar();";
Compiler compiler = getCompiler(input);
Node root = compileToScriptRoot(compiler);
SuggestedFix fix = new SuggestedFix.Builder().replaceText(root.getFirstFirstChild(), 3, "quux").build();
CodeReplacement replacement = CodeReplacement.create(4, 3, "quux");
assertReplacement(fix, replacement);
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testRenameFunction_justFunctionName.
@Test
public void testRenameFunction_justFunctionName() {
String input = "obj.fnCall();";
Compiler compiler = getCompiler(input);
Node root = compileToScriptRoot(compiler);
SuggestedFix fix = new SuggestedFix.Builder().rename(root.getFirstFirstChild(), "renamedFnCall").build();
CodeReplacement replacement = CodeReplacement.create(4, "fnCall".length(), "renamedFnCall");
assertReplacement(fix, replacement);
}
use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.
the class SuggestedFixTest method testDeleteArgumentMiddle.
@Test
public void testDeleteArgumentMiddle() {
String originalCode = "f(a, 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);
}
Aggregations