blob: 361070c5c00199861f0bf48c4aae878cf6f2fa94 (
plain)
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
|
package org.javacs;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import java.util.stream.Collectors;
import org.junit.Test;
public class PrunerTest {
private String contents(String resourceFile) {
try (var in = JavaCompilerServiceTest.class.getResourceAsStream(resourceFile)) {
return new BufferedReader(new InputStreamReader(in)).lines().collect(Collectors.joining("\n"));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Test
public void pruneMethods() {
var actual = new Pruner(URI.create("/PruneMethods.java"), contents("/PruneMethods.java")).prune(6, 19);
var expected = contents("/PruneMethods_erased.java");
assertThat(actual, equalToIgnoringWhiteSpace(expected));
}
@Test
public void pruneToEndOfBlock() {
var actual =
new Pruner(URI.create("/PruneToEndOfBlock.java"), contents("/PruneToEndOfBlock.java")).prune(4, 18);
var expected = contents("/PruneToEndOfBlock_erased.java");
assertThat(actual, equalToIgnoringWhiteSpace(expected));
}
@Test
public void pruneMiddle() {
var actual = new Pruner(URI.create("/PruneMiddle.java"), contents("/PruneMiddle.java")).prune(4, 12);
var expected = contents("/PruneMiddle_erased.java");
assertThat(actual, equalToIgnoringWhiteSpace(expected));
}
@Test
public void pruneDot() {
var actual = new Pruner(URI.create("/PruneDot.java"), contents("/PruneDot.java")).prune(3, 11);
var expected = contents("/PruneDot_erased.java");
assertThat(actual, equalToIgnoringWhiteSpace(expected));
}
}
|