Skip to content

Commit 2672211

Browse files
committed
Add roundtrip test for sub-range decoding
1 parent d3f87eb commit 2672211

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

src/roundtrip.test.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,70 @@ describe("round trip", () => {
203203

204204
assertCodec(builder.build());
205205
});
206+
207+
it("handles sub-range bindings", () => {
208+
builder.startScope(0, 0, {
209+
key: "scope",
210+
variables: ["v1", "v2", "v3", "v4"],
211+
}).endScope(10, 0);
212+
213+
builder.startRange(0, 0, {
214+
scopeKey: "scope",
215+
values: [
216+
// v1: no sub-ranges
217+
"v1_expr",
218+
// v2: one sub-range transition
219+
[
220+
{
221+
from: { line: 0, column: 0 },
222+
to: { line: 5, column: 0 },
223+
value: "v2_initial_expr",
224+
},
225+
{
226+
from: { line: 5, column: 0 },
227+
to: { line: 10, column: 0 },
228+
value: "v2_final_expr",
229+
},
230+
],
231+
// v3: multiple sub-range transitions
232+
[
233+
{
234+
from: { line: 0, column: 0 },
235+
to: { line: 2, column: 0 },
236+
value: "v3_expr1",
237+
},
238+
{
239+
from: { line: 2, column: 0 },
240+
to: { line: 6, column: 0 },
241+
value: "v3_expr2",
242+
},
243+
{
244+
from: { line: 6, column: 0 },
245+
to: { line: 10, column: 0 },
246+
value: "v3_expr3",
247+
},
248+
],
249+
// v4: multiple sub-ranges with unavailable parts
250+
[
251+
{
252+
from: { line: 0, column: 0 },
253+
to: { line: 3, column: 0 },
254+
value: "v4_expr1",
255+
},
256+
{
257+
from: { line: 3, column: 0 },
258+
to: { line: 7, column: 0 },
259+
value: undefined, // unavailable
260+
},
261+
{
262+
from: { line: 7, column: 0 },
263+
to: { line: 10, column: 0 },
264+
value: "v4_expr2",
265+
},
266+
],
267+
],
268+
}).endRange(10, 0);
269+
270+
assertCodec(builder.build());
271+
});
206272
});

0 commit comments

Comments
 (0)