Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
61 lines (52 loc) · 2.22 KB

File metadata and controls

61 lines (52 loc) · 2.22 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package diffr.patch;
import com.google.common.collect.Lists;
import com.google.common.io.Files;
import com.google.common.io.Resources;
import diffr.util.instruction.IllegalPatchInstructionException;
import org.testng.annotations.Test;
import java.io.File;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
/**
* Tests {@link Patchr}
*/
public class PatchrTest {
/**
* Tests patch on ready made files.
*/
@Test
public void testExistingFiles() throws Exception {
final File originalFile = new File(Resources.getResource("files/copyright.txt").toURI());
final File patchFile = new File(Resources.getResource("patches/cp.patch").toURI());
final List<String> firstFileStrings = Files.readLines(originalFile, Charset.defaultCharset());
final List<String> patchFileStrings = Files.readLines(patchFile, Charset.defaultCharset());
new Patchr(firstFileStrings, patchFileStrings).patch();
}
/**
* Tests whether an artificial example works.
*/
@Test
public void testPatch() throws IllegalPatchInstructionException, IllegalPatchFileException {
final List<String> original = Lists.newArrayList("hello world!", "2", "");
final List<String> next = Lists.newArrayList("hello world.", "2", "3", "2", "", "hello world!");
final List<String> patch = Lists.newArrayList("> hello world.", "1,1", "> 3", "1,2", "0,0");
final Patchr patchr = new Patchr(original, patch);
final List<String> result = patchr.patch();
System.out.println(result.toString());
assertThat(next.size(), is(result.size()));
for (int i = 0; i < next.size(); i++) {
assertThat(result.get(i), is(next.get(i)));
}
}
/**
* Tests whether the Constructor throws an exception when given an illegal instruction.
*/
@Test(expectedExceptions = IllegalPatchFileException.class)
public void testIllegalInstructionConstructor() throws IllegalPatchFileException {
final List<String> broken = Lists.newArrayList("brokenInstruction");
new Patchr(new ArrayList<String>(), broken);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.