use of com.google.copybara.Transformation in project copybara by google.
the class FilterReplaceTest method testCoreReplaceAll.
/**
* Equivalent to core.todo_replace
*/
@Test
public void testCoreReplaceAll() throws Exception {
write("file.txt", "" + "Some text // TODO(foo, bar, baz)\n" + "more text\n");
Transformation t = eval(Core.TODO_FILTER_REPLACE_EXAMPLE);
transform(t);
assertThatPath(checkoutDir).containsFile("file.txt", "Some text // TODO(fooz, bar, bazz)\n" + "more text\n").containsNoMoreFiles();
transform(t.reverse());
assertThatPath(checkoutDir).containsFile("file.txt", "Some text // TODO(foo, bar, baz)\n" + "more text\n").containsNoMoreFiles();
}
use of com.google.copybara.Transformation in project copybara by google.
the class FilterReplaceTest method testPath.
@Test
public void testPath() throws Exception {
write("file1.txt", "foo\n");
write("file2.txt", "foo\n");
Transformation transformation = filterReplace("" + "regex = '.*'," + "mapping = {'foo': 'bar'}," + "paths = glob(['file1.txt']),");
transform(transformation);
assertThatPath(checkoutDir).containsFile("file1.txt", "bar\n").containsFile("file2.txt", "foo\n").containsNoMoreFiles();
transform(transformation.reverse());
assertThatPath(checkoutDir).containsFile("file1.txt", "foo\n").containsFile("file2.txt", "foo\n").containsNoMoreFiles();
}
use of com.google.copybara.Transformation in project copybara by google.
the class ReplaceTest method testAppendFile.
@Test
public void testAppendFile() throws Exception {
Transformation transformation = eval("core.transform([\n" + " core.replace(\n" + " before = '${end}',\n" + " after = 'some append',\n" + " multiline = True,\n" + " regex_groups = { 'end' : r'\\z'},\n" + " )\n" + "],\n" + "reversal = [\n" + " core.replace(\n" + " before = 'some append${end}',\n" + " after = '',\n" + " multiline = True,\n" + " regex_groups = { 'end' : r'\\z'},\n" + " )" + "])");
Path file1 = checkoutDir.resolve("file1.txt");
writeFile(file1, "foo\nbar\nbaz\n");
transform(transformation);
assertThatPath(checkoutDir).containsFile("file1.txt", "foo\nbar\nbaz\nsome append");
transform(transformation.reverse());
assertThatPath(checkoutDir).containsFile("file1.txt", "foo\nbar\nbaz\n");
}
use of com.google.copybara.Transformation in project copybara by google.
the class MetadataModuleTest method testMapAuthor_nonReversible.
@Test
public void testMapAuthor_nonReversible() throws Exception {
Transformation m = skylark.eval("m", "m = " + "metadata.map_author({\n" + " 'a' : 'b <b@example.com>',\n" + "}," + "reversible = True)");
assertThrows(NonReversibleValidationException.class, () -> m.reverse());
}
use of com.google.copybara.Transformation in project copybara by google.
the class MetadataModuleTest method testMapAuthor_noop_reversal.
@Test
public void testMapAuthor_noop_reversal() throws Exception {
Transformation m = skylark.eval("m", "m = " + "metadata.map_author({\n" + " 'a' : 'b <b@example.com>',\n" + "}," + "noop_reverse = True)");
TransformWork work = TransformWorks.of(workdir, "test", testingConsole);
work.setAuthor(new Author("a", "foo@foo"));
m.transform(work);
assertThat(work.getAuthor().getEmail()).isEqualTo("b@example.com");
m.reverse().transform(work);
assertThat(work.getAuthor().getEmail()).isEqualTo("b@example.com");
}
Aggregations