-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes remy/vscode-nextbasic#45
- Loading branch information
Showing
8 changed files
with
217 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import test from 'ava'; | ||
import { Statement } from '../txt2bas'; | ||
|
||
/** | ||
* @param {require("~/index.d.ts").Token} token string | ||
* @returns {string} | ||
*/ | ||
function text(token) { | ||
return token.text || token.value; | ||
} | ||
|
||
test('multi statement peek', (t) => { | ||
let src, | ||
token, | ||
peek, | ||
pos = 0; | ||
src = '10 IF %z THEN: ELSE IF %z=34 THEN: ELSE PRINT "3"'; | ||
|
||
const statement = new Statement(src); | ||
|
||
token = statement.nextToken(); // move to IF | ||
t.is(text(token), 'IF'); | ||
pos = statement.pos; | ||
peek = statement.peekToken(pos); | ||
t.is(text(peek), '%'); | ||
pos = peek.pos; | ||
peek = statement.peekToken(pos); | ||
t.is(text(peek), 'z'); | ||
pos = peek.pos; | ||
peek = statement.peekToken(pos); | ||
t.is(text(peek), 'THEN'); | ||
pos = peek.pos; | ||
peek = statement.peekToken(pos); | ||
t.is(peek.name, 'STATEMENT_SEP'); // should be nothing | ||
}); | ||
|
||
test.only('multi statement peek with preview', (t) => { | ||
let src, token, hasThen, statement; | ||
|
||
src = '10 IF %z THEN: ELSE IF %z=34 THEN: ELSE PRINT "3"'; | ||
statement = new Statement(src); | ||
token = statement.nextToken(); // move to IF | ||
t.is(text(token), 'IF'); | ||
hasThen = statement.peekStatementContains('THEN'); | ||
|
||
t.is(hasThen, true, 'first IF contains THEN'); | ||
|
||
src = '10 ELSE IF %z=34 THEN: ELSE PRINT "3"'; | ||
statement = new Statement(src); | ||
token = statement.nextToken(); // move to ELSE | ||
t.is(text(token), 'ELSE'); | ||
hasThen = statement.peekStatementContains('THEN'); | ||
t.is(hasThen, true, 'first IF contains THEN'); | ||
|
||
src = '20 ELSE IF 1 < 2 PRINT "ELSE"'; | ||
statement = new Statement(src); | ||
token = statement.nextToken(); // move to ELSE | ||
t.is(text(token), 'ELSE'); | ||
hasThen = statement.peekStatementContains('THEN'); | ||
t.is(hasThen, false, 'first IF does not contain THEN'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
type Token = { | ||
name: string; | ||
value: number | string; | ||
text: string; | ||
numeric: number; | ||
integer: boolean; | ||
}; | ||
|
||
type ParsedBasic = { | ||
basic: Uint8Array; | ||
line: string; | ||
length: number; | ||
lineNumber: number; | ||
tokens: Token[]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters