Skip to content

Commit ff7e66d

Browse files
committed
validate the source number mapping with snapshots
1 parent 98030d4 commit ff7e66d

File tree

3 files changed

+86
-3
lines changed

3 files changed

+86
-3
lines changed

glsl-preprocessor/src/test/java/io/github/douira/glsl_preprocessor/IntegrationTest.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,33 @@ private void preprocessorTestCase(String type, String input, String expectedOutp
4141
prepare.accept(pp);
4242
}
4343

44-
var snapshotOutput = "(no error)";
44+
var snapshotOutput = new StringBuilder();
4545
if (errors) {
4646
var e = assertThrows(Exception.class, pp::printToString);
4747
pp.close();
48-
snapshotOutput = e.toString();
48+
snapshotOutput.append(e.toString());
4949
} else {
5050
var output = pp.printToString();
5151
assertEquals(expectedOutput, output);
52+
snapshotOutput.append("(no error)");
53+
}
54+
55+
for (var entry : pp.getSourceNumbers().entrySet()) {
56+
var source = entry.getKey();
57+
if (source == null) {
58+
continue;
59+
}
60+
var sourceNumber = entry.getValue();
61+
snapshotOutput.append("\n");
62+
snapshotOutput.append(sourceNumber);
63+
snapshotOutput.append("->");
64+
snapshotOutput.append(source);
5265
}
5366

5467
expect
5568
.scenario(type + "_" + getBase64Hash(input))
5669
.toMatchSnapshot(SnapshotUtil.inputOutputSnapshot(
57-
input, snapshotOutput));
70+
input, snapshotOutput.toString()));
5871
}
5972

6073
@SnapshotName("testPreprocessor")

glsl-preprocessor/src/test/java/io/github/douira/glsl_preprocessor/__snapshots__/IntegrationTest.cases

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,48 @@ content 1
123123
#line 3 0
124124
foo
125125

126+
§testIncludeLineMapping LINE_MARKERS:
127+
bar
128+
#include "length!2:a"
129+
baz
130+
#include "length!2:a"
131+
foo
132+
133+
===
134+
#line 1 0
135+
bar
136+
#line 1 1
137+
content 0
138+
content 1
139+
#line 3 0
140+
baz
141+
#line 1 1
142+
content 0
143+
content 1
144+
#line 5 0
145+
foo
146+
147+
§testIncludeLineMapping LINE_MARKERS:
148+
bar
149+
#include "length!2:a"
150+
baz
151+
#include "length!2:b"
152+
foo
153+
154+
===
155+
#line 1 0
156+
bar
157+
#line 1 1
158+
content 0
159+
content 1
160+
#line 3 0
161+
baz
162+
#line 1 2
163+
content 0
164+
content 1
165+
#line 5 0
166+
foo
167+
126168
§testIncludeLineMapping LINE_MARKERS,NAMED_LINE_MARKERS:
127169
bar
128170
#include "length!2:a"

glsl-preprocessor/src/test/java/io/github/douira/glsl_preprocessor/__snapshots__/IntegrationTest.snap

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,41 @@ foo
6363
]
6464

6565

66+
testIncludeLineMapping[LINE_MARKERS_KMXHA9leEtjEQjB1tipNUWRHgsw]=[
67+
bar
68+
#include "length!2:a"
69+
baz
70+
#include "length!2:b"
71+
foo
72+
73+
<><><><><><><><><><><><><><><><><><><><><><><><><>
74+
(no error)
75+
1->length!2:a
76+
2->length!2:b
77+
]
78+
79+
6680
testIncludeLineMapping[LINE_MARKERS_dSPMsT7XryDyTsdqDoJrH6BH3Zo]=[
6781
bar
6882
#include "length!2:a"
6983
foo
7084

7185
<><><><><><><><><><><><><><><><><><><><><><><><><>
7286
(no error)
87+
1->length!2:a
88+
]
89+
90+
91+
testIncludeLineMapping[LINE_MARKERS_x+AzR2u8DVoryMYAQ2zIR24fhCk]=[
92+
bar
93+
#include "length!2:a"
94+
baz
95+
#include "length!2:a"
96+
foo
97+
98+
<><><><><><><><><><><><><><><><><><><><><><><><><>
99+
(no error)
100+
1->length!2:a
73101
]
74102

75103

0 commit comments

Comments
 (0)