use of com.google.copybara.Transformation in project copybara by google.
the class FilterReplaceTest method testSimple.
@Test
public void testSimple() throws Exception {
String original = "" + "afoo\n" + "aaaaaa\n" + "bbbbbb\n" + "abaz\n" + "";
write("file1.txt", original);
write("file2.txt", "other\n");
Transformation transformation = eval(Core.SIMPLE_FILTER_REPLACE_EXAMPLE);
transform(transformation);
assertThatPath(checkoutDir).containsFile("file1.txt", "" + "abar\n" + "aaaaaa\n" + "bbbbbb\n" + "abam\n").containsFile("file2.txt", "other\n").containsNoMoreFiles();
transform(transformation.reverse());
assertThatPath(checkoutDir).containsFile("file1.txt", original).containsFile("file2.txt", "other\n").containsNoMoreFiles();
}
use of com.google.copybara.Transformation in project copybara by google.
the class FilterReplaceTest method testNestedFilterReplace.
@Test
public void testNestedFilterReplace() throws Exception {
String original = "" + "before\n" + "// BEGIN SCRUBBER\n" + "// some comment\n" + "// some other comment\n" + "// with indentation\n" + "// END SCRUBBER\n" + "// other comment\n" + "some code" + "// BEGIN SCRUBBER\n" + "// some comment\n" + "// some other comment\n" + "// with indentation\n" + "// END SCRUBBER\n" + "after\n";
write("file.txt", original);
Transformation t = filterReplace("" + "regex = '// BEGIN SCRUBBER\\n((\\n|.)*?\\n)// END SCRUBBER\\n',\n" + "mapping = core.filter_replace(\n" + " regex = '// .*\\n',\n" + " mapping = core.replace_mapper([\n" + " core.replace(before = '// BEGIN SCRUBBER\\n', after = '', multiline = True),\n" + " core.replace(before = '// END SCRUBBER\\n', after = '', multiline = True),\n" + " core.replace(\n" + " before = '// ${content}\\n',\n" + " after = '${content}\\n',\n" + " regex_groups = {'content' : '.*'},\n" + " multiline = True," + " )\n" + " ]),\n" + ")");
transform(t);
assertThatPath(checkoutDir).containsFile("file.txt", "" + "before\n" + "some comment\n" + "some other comment\n" + " with indentation\n" + "// other comment\n" + "some code" + "some comment\n" + "some other comment\n" + " with indentation\n" + "after\n").containsNoMoreFiles();
}
use of com.google.copybara.Transformation in project copybara by google.
the class FilterReplaceTest method testWithVariablesInContent.
@Test
public void testWithVariablesInContent() throws Exception {
String original = "" + "afoo\n" + "a${foo}\\${bar}\n" + "$\n";
write("file1.txt", original);
Transformation transformation = eval("" + "core.filter_replace(\n" + " regex = 'a.*',\n" + " mapping = {\n" + " 'afoo': 'abar',\n" + " }\n" + ")\n");
transform(transformation);
assertThatPath(checkoutDir).containsFile("file1.txt", "" + "abar\n" + "a${foo}\\${bar}\n" + "$\n").containsNoMoreFiles();
}
use of com.google.copybara.Transformation in project copybara by google.
the class FilterReplaceTest method testCustomReverse.
@Test
public void testCustomReverse() throws Exception {
String original = "" + "#import <foo1>\n" + "#import <foo2>\n" + "#import <bar1>\n" + "";
write("file.txt", original);
Transformation t = filterReplace("" + "regex = '#import <fo.*>'," + "reverse = '#import <.*> // by Copybara'," + "mapping = {" + " '#import <foo1>': '#import <bar1> // by Copybara',\n" + " '#import <foo2>': '#import <bar2> // by Copybara',\n" + "},");
transform(t);
assertThatPath(checkoutDir).containsFile("file.txt", "" + "#import <bar1> // by Copybara\n" + "#import <bar2> // by Copybara\n" + "#import <bar1>\n").containsNoMoreFiles();
transform(t.reverse());
assertThatPath(checkoutDir).containsFile("file.txt", original).containsNoMoreFiles();
}
use of com.google.copybara.Transformation in project copybara by google.
the class FilterReplaceTest method testCoreReplace.
@Test
public void testCoreReplace() throws Exception {
String original = "" + "import foo.bar.last.Class;\n" + "import other.bar.last.Class;\n" + "import bar.foo.last.Class;\n";
write("file.txt", original);
Transformation t = filterReplace("" + "regex = '(^|\\n)import (.*);\\n'," + "group = 2," + "mapping = core.replace_mapper([" + " core.replace(" + " before = '${start}foo${pkg}.${last_pkg}.${n}'," + " after = '${start}prefix.foo${pkg}.${last_pkg}.${last_pkg}.${n}'," + " regex_groups = {'start': '^', 'pkg' : '.*', 'last_pkg' : '.*','n' : '[A-Z].*', }," + " repeated_groups = True," + " )," + " core.replace(" + " before = '${start}bar${pkg}.${last_pkg}.${n}'," + " after = '${start}prefix.bar${pkg}.${last_pkg}.${last_pkg}.${n}'," + " regex_groups = {'start': '^', 'pkg' : '.*', 'last_pkg' : '.*','n' : '[A-Z].*', }," + " repeated_groups = True," + " )," + "]),");
transform(t);
assertThatPath(checkoutDir).containsFile("file.txt", "" + "import prefix.foo.bar.last.last.Class;\n" + "import other.bar.last.Class;\n" + "import prefix.bar.foo.last.last.Class;\n").containsNoMoreFiles();
transform(t.reverse());
assertThatPath(checkoutDir).containsFile("file.txt", original).containsNoMoreFiles();
}
Aggregations