|
2 | 2 |
|
3 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; |
4 | 4 |
|
5 | | -import java.util.List; |
6 | 5 | import java.util.Map; |
7 | | -import java.util.TreeMap; |
8 | 6 | import java.util.stream.Collectors; |
9 | 7 |
|
10 | | -import org.junit.jupiter.api.BeforeAll; |
11 | 8 | import org.junit.jupiter.api.Test; |
12 | 9 |
|
13 | 10 | import liquidjava.api.CommandLineLauncher; |
|
19 | 16 | */ |
20 | 17 | class TestGeneratedNames { |
21 | 18 |
|
22 | | - private static Map<Integer, String> messages; |
23 | | - |
24 | | - @BeforeAll |
25 | | - static void verify() { |
26 | | - CommandLineLauncher.launch("../liquidjava-example/src/main/java/testSuite/classes/generated_names_error"); |
27 | | - // a second error on a line fails here instead of replacing the first |
28 | | - messages = Diagnostics.getInstance().getErrors().stream().collect( |
29 | | - Collectors.toMap(error -> error.getPosition().getLine(), error -> plain(error.getMessage()), (a, b) -> { |
30 | | - throw new AssertionError("two errors on one line: " + a + " and " + b); |
31 | | - }, TreeMap::new)); |
32 | | - } |
33 | | - |
34 | | - @Test |
35 | | - void reportsOneErrorPerOrigin() { |
36 | | - assertEquals(List.of(25, 30, 34, 43, 48, 54, 58), List.copyOf(messages.keySet())); |
37 | | - } |
38 | | - |
39 | | - @Test |
40 | | - void ifConditionIsNamedAfterTheIf() { |
41 | | - assertEquals("#if_condition == ready && #if_condition is not a subtype of a > 0", messages.get(25)); |
42 | | - } |
43 | | - |
44 | | - @Test |
45 | | - void loopConditionIsNamedAfterTheLoop() { |
46 | | - assertEquals("#loop_condition == ready && #loop_condition == true is not a subtype of a > 0", messages.get(30)); |
47 | | - } |
48 | | - |
49 | | - @Test |
50 | | - void ternaryConditionIsNamedAfterTheTernary() { |
51 | | - assertEquals("#ternary_condition == ready && #ternary_condition == true is not a subtype of a < 0", |
52 | | - messages.get(34)); |
53 | | - } |
54 | | - |
55 | | - @Test |
56 | | - void tryAndCatchPathsAreNamedAfterTheirBranches() { |
57 | | - assertEquals("!#try_branch && !#catch_branch is not a subtype of a > 0", messages.get(43)); |
58 | | - } |
59 | | - |
60 | | - @Test |
61 | | - void callResultIsNamedAfterTheMethod() { |
62 | | - assertEquals("x == #read_result - 1 is not a subtype of x > 0", messages.get(48)); |
63 | | - } |
64 | | - |
65 | | - @Test |
66 | | - void untranslatedOperationIsNamedAsAnOperationResult() { |
67 | | - assertEquals("#if_condition == #operation_result && #if_condition && x == 0 is not a subtype of x > 0", |
68 | | - messages.get(54)); |
69 | | - } |
70 | | - |
71 | 19 | @Test |
72 | | - void newReceiverIsNamedAfterItsClass() { |
73 | | - assertEquals("found closed(#new_Door) but expected opened(#new_Door)", messages.get(58)); |
74 | | - } |
75 | | - |
76 | | - private static String plain(String text) { |
77 | | - return text.replaceAll("[⁰¹²³⁴⁵⁶⁷⁸⁹]", ""); |
| 20 | + void namesEachGeneratedValueAfterWhatItIs() { |
| 21 | + CommandLineLauncher.launch("../liquidjava-example/src/main/java/testSuite/classes/generated_names_error"); |
| 22 | + Map<Integer, String> messages = Diagnostics.getInstance().getErrors().stream().collect(Collectors.toMap( |
| 23 | + error -> error.getPosition().getLine(), error -> error.getMessage().replaceAll("[⁰¹²³⁴⁵⁶⁷⁸⁹]", ""))); |
| 24 | + |
| 25 | + assertEquals(Map.of(25, "#if_condition == ready && #if_condition is not a subtype of a > 0", 30, |
| 26 | + "#loop_condition == ready && #loop_condition == true is not a subtype of a > 0", 34, |
| 27 | + "#ternary_condition == ready && #ternary_condition == true is not a subtype of a < 0", 43, |
| 28 | + "!#try_branch && !#catch_branch is not a subtype of a > 0", 48, |
| 29 | + "x == #read_result - 1 is not a subtype of x > 0", 54, |
| 30 | + "#if_condition == #operation_result && #if_condition && x == 0 is not a subtype of x > 0", 58, |
| 31 | + "found closed(#new_Door) but expected opened(#new_Door)"), messages); |
78 | 32 | } |
79 | 33 | } |
0 commit comments