Skip to content

Commit

Permalink
fix: validate line numbers on split bank
Browse files Browse the repository at this point in the history
  • Loading branch information
remy committed Mar 10, 2024
1 parent 8e1c4bc commit 220330c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
22 changes: 22 additions & 0 deletions __tests__/fixtures/bank-split-numbers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#autostart 1
5 RUN AT 3: PRINT "<<< MULTI_BANK_OUTPUT >>>"
10 LOAD "BANK20" BANK 20
15 LOAD "BANK21" BANK 21
17 LOAD "BANK22" BANK 22
20 PRINT "BASIC ON THE..."
30 BANK 20 GO SUB 30
35 BANK 21 GO SUB 30
37 BANK 22 GO SUB 30
40 GO TO 20

#bankfile BANK20
30 PRINT "20 ZX"
40 RETURN

#bankfile BANK21
30 PRINT "21 SPECTRUM"
40 RETURN

#bankfile BANK22
30 PRINT "22 NEXT!"
40 RETURN
11 changes: 11 additions & 0 deletions __tests__/validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ test('hex looking like dec', (t) => {
});
});

test('#bank splitting resets line numbers', async (t) => {
let fixture = await readFile(
__dirname + '/fixtures/bank-split-numbers.txt',
'utf8'
);
fixture = fixture.split('\n').slice(2).join('\n');
const res = validateTxt(fixture);

t.deepEqual(res, [], 'no validation errors');
});

function throws(src, expect, { debug, message } = {}) {
test(src, (t) => {
t.throws(
Expand Down
5 changes: 5 additions & 0 deletions txt2bas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ export function validate(text, debug = {}) {
if (line.startsWith('#autoline')) {
autoline.parse(line);
}

if (line.startsWith('#bank')) {
autoline.reset();
lastLine = -1;
}
// skip
} else {
let ln;
Expand Down

0 comments on commit 220330c

Please sign in to comment.