@@ -7,6 +7,10 @@ import { createSyntaxScriptDiagnosticReport } from '../diagnostic.js';
7
7
import { expect } from 'chai' ;
8
8
import { syxparser } from '../ast.js' ;
9
9
10
+ function r ( sc :number , ec :number ) :Range {
11
+ return { start :{ line :1 , character :sc } , end :{ line :1 , character :ec } } ;
12
+ }
13
+
10
14
describe ( 'Compiler module' , ( ) => {
11
15
12
16
function rangeExpectations ( r : Range ) {
@@ -200,7 +204,7 @@ describe('Compiler module', () => {
200
204
201
205
const tokens = tokenizeSyx ( 'keyword ruleish;' ) ;
202
206
const ast = syxparser . parseTokens ( tokens , 'TEST_FILE' ) ;
203
- const stmt : KeywordStatement = { type : NodeType . Keyword , modifiers : [ ] , range : { end : { line : 1 , character : 16 } , start : { line : 1 , character : 1 } } , word : 'ruleish' } ;
207
+ const stmt : KeywordStatement = { type : NodeType . Keyword , modifiers : [ ] , range : { end : { line : 1 , character : 16 } , start : { line : 1 , character : 1 } } , word : { value : 'ruleish' , type : NodeType . Identifier , modifiers : [ ] , range : { start : { line : 1 , character : 9 } , end : { line : 1 , character : 16 } } } } ;
204
208
205
209
astTypeExpectations ( ast ) ;
206
210
expect ( ast . body [ 0 ] ) . to . be . a ( 'object' ) . to . be . deep . equal ( stmt ) ;
@@ -211,7 +215,7 @@ describe('Compiler module', () => {
211
215
212
216
const tokens = tokenizeSyx ( 'rule \'function-value-return-enabled\': true;' ) ;
213
217
const ast = syxparser . parseTokens ( tokens , 'TEST_FILE' ) ;
214
- const stmt : RuleStatement = { range : { start : { line : 1 , character : 1 } , end : { line : 1 , character : 43 } } , modifiers : [ ] , rule : 'function-value-return-enabled' , value : 'true' , type : NodeType . Rule } ;
218
+ const stmt : RuleStatement = { range : { start : { line : 1 , character : 1 } , end : { line : 1 , character : 43 } } , modifiers : [ ] , rule : { range : r ( 6 , 38 ) , type : NodeType . String , value : 'function-value-return-enabled' , modifiers : [ ] } , value : 'true' , type : NodeType . Rule } ;
215
219
216
220
astTypeExpectations ( ast ) ;
217
221
expect ( ast . body [ 0 ] ) . to . be . a ( 'object' ) . to . be . deep . equal ( stmt ) ;
@@ -222,7 +226,7 @@ describe('Compiler module', () => {
222
226
223
227
const tokens = tokenizeSyx ( 'compile(ts,js) \'test\';' ) ;
224
228
const ast = syxparser . parseTokens ( tokens , 'TEST_FILE' ) ;
225
- const stmt : CompileStatement = { range : { start : { line : 1 , character : 1 } , end : { line : 1 , character : 22 } } , formats : [ 'ts' , 'js' ] , type : NodeType . Compile , modifiers : [ ] , body : [ { type : NodeType . String , modifiers : [ ] , range : { start : { line : 1 , character : 16 } , end : { line : 1 , character : 22 } } , value : 'test' } ] } ;
229
+ const stmt : CompileStatement = { range : { start : { line : 1 , character : 1 } , end : { line : 1 , character : 22 } } , formats : [ { modifiers : [ ] , type : NodeType . Identifier , range : r ( 9 , 11 ) , value : 'ts' } , { modifiers : [ ] , type : NodeType . Identifier , range : r ( 12 , 14 ) , value : 'js' } ] , type : NodeType . Compile , modifiers : [ ] , body : [ { type : NodeType . String , modifiers : [ ] , range : { start : { line : 1 , character : 16 } , end : { line : 1 , character : 22 } } , value : 'test' } ] } ;
226
230
227
231
astTypeExpectations ( ast ) ;
228
232
expect ( ast . body [ 0 ] ) . to . be . a ( 'object' ) . to . be . deep . equal ( stmt ) ;
@@ -233,7 +237,7 @@ describe('Compiler module', () => {
233
237
234
238
const tokens = tokenizeSyx ( 'imports(ts,js) \'math\';' ) ;
235
239
const ast = syxparser . parseTokens ( tokens , 'TEST_FILE' ) ;
236
- const stmt : ImportsStatement = { range : { start : { line : 1 , character : 1 } , end : { line : 1 , character : 22 } } , formats : [ 'ts' , 'js' ] , type : NodeType . Imports , modifiers : [ ] , module : 'math' } ;
240
+ const stmt : ImportsStatement = { range : { start : { line : 1 , character : 1 } , end : { line : 1 , character : 22 } } , formats : [ { modifiers : [ ] , type : NodeType . Identifier , range : r ( 9 , 11 ) , value : 'ts' } , { modifiers : [ ] , type : NodeType . Identifier , range : r ( 12 , 14 ) , value : 'js' } ] , type : NodeType . Imports , modifiers : [ ] , module : { range : r ( 16 , 22 ) , modifiers : [ ] , type : NodeType . String , value : 'math' } } ;
237
241
238
242
astTypeExpectations ( ast ) ;
239
243
expect ( ast . body [ 0 ] ) . to . be . a ( 'object' ) . to . be . deep . equal ( stmt ) ;
@@ -244,7 +248,7 @@ describe('Compiler module', () => {
244
248
245
249
const tokens = tokenizeSyx ( 'global randomizer {}' ) ;
246
250
const ast = syxparser . parseTokens ( tokens , 'TEST_FILE' ) ;
247
- const stmt : GlobalStatement = { range : { start : { line : 1 , character : 1 } , end : { line : 1 , character : 21 } } , name : 'randomizer' , type : NodeType . Global , modifiers : [ ] , body : [ ] } ;
251
+ const stmt : GlobalStatement = { range : { start : { line : 1 , character : 1 } , end : { line : 1 , character : 21 } } , name : { type : NodeType . Identifier , modifiers : [ ] , range : r ( 8 , 18 ) , value : 'randomizer' } , type : NodeType . Global , modifiers : [ ] , body : [ ] } ;
248
252
249
253
astTypeExpectations ( ast ) ;
250
254
expect ( ast . body [ 0 ] ) . to . be . a ( 'object' ) . to . be . deep . equal ( stmt ) ;
@@ -255,7 +259,7 @@ describe('Compiler module', () => {
255
259
256
260
const tokens = tokenizeSyx ( 'function randomizer <int> {}' ) ;
257
261
const ast = syxparser . parseTokens ( tokens , 'TEST_FILE' ) ;
258
- const stmt : FunctionStatement = { range : { start : { line : 1 , character : 1 } , end : { line : 1 , character : 29 } } , name : 'randomizer' , type : NodeType . Function , modifiers : [ ] , body : [ ] , arguments : [ 'int' ] } ;
262
+ const stmt : FunctionStatement = { range : { start : { line : 1 , character : 1 } , end : { line : 1 , character : 29 } } , name : { type : NodeType . Identifier , modifiers : [ ] , range : r ( 10 , 20 ) , value : 'randomizer' } , type : NodeType . Function , modifiers : [ ] , body : [ ] , arguments : [ { modifiers : [ ] , range : r ( 21 , 26 ) , type : NodeType . PrimitiveType , value : 'int' } ] } ;
259
263
260
264
astTypeExpectations ( ast ) ;
261
265
expect ( ast . body [ 0 ] ) . to . be . a ( 'object' ) . to . be . deep . equal ( stmt ) ;
@@ -266,7 +270,7 @@ describe('Compiler module', () => {
266
270
267
271
const tokens = tokenizeSyx ( 'import \'./math\';' ) ;
268
272
const ast = syxparser . parseTokens ( tokens , 'TEST_FILE' ) ;
269
- const stmt : ImportStatement = { range : { start : { line : 1 , character : 1 } , end : { line : 1 , character : 16 } } , type : NodeType . Import , modifiers : [ ] , path : './math' } ;
273
+ const stmt : ImportStatement = { range : { start : { line : 1 , character : 1 } , end : { line : 1 , character : 16 } } , type : NodeType . Import , modifiers : [ ] , path : { range : r ( 8 , 16 ) , value : './math' , modifiers : [ ] , type : NodeType . String } } ;
270
274
271
275
astTypeExpectations ( ast ) ;
272
276
expect ( ast . body [ 0 ] ) . to . be . a ( 'object' ) . to . be . deep . equal ( stmt ) ;
@@ -277,7 +281,7 @@ describe('Compiler module', () => {
277
281
278
282
const tokens = tokenizeSyx ( 'export keyword ruleish;' ) ;
279
283
const ast = syxparser . parseTokens ( tokens , 'TEST_FILE' ) ;
280
- const stmt : KeywordStatement = { type : NodeType . Keyword , modifiers : [ { range : { end : { line : 1 , character : 7 } , start : { line : 1 , character : 1 } } , type : TokenType . ExportKeyword , value : 'export' } ] , range : { end : { line : 1 , character : 23 } , start : { line : 1 , character : 1 } } , word : 'ruleish' } ;
284
+ const stmt : KeywordStatement = { type : NodeType . Keyword , modifiers : [ { range : { end : { line : 1 , character : 7 } , start : { line : 1 , character : 1 } } , type : TokenType . ExportKeyword , value : 'export' } ] , range : { end : { line : 1 , character : 23 } , start : { line : 1 , character : 1 } } , word : { range : r ( 16 , 23 ) , modifiers : [ ] , type : NodeType . Identifier , value : 'ruleish' } } ;
281
285
282
286
astTypeExpectations ( ast ) ;
283
287
expect ( ast . body [ 0 ] ) . to . be . a ( 'object' ) . to . be . deep . equal ( stmt ) ;
0 commit comments