1- import { CompileStatement , FunctionStatement , GlobalStatement , ImportStatement , ImportsStatement , KeywordStatement , NodeType , ProgramStatement , RuleStatement , TokenType } from '../types.js' ;
2- import { describe , it } from '@efekos/es-test/bin/testRunner.js' ;
1+ import { CompileStatement , FunctionStatement , GlobalStatement , ImportStatement , ImportsStatement , KeywordStatement , NodeType , ProgramStatement , RuleStatement , TokenType , isCompilerError } from '../types.js' ;
2+ import { Diagnostic , DiagnosticSeverity , DocumentDiagnosticReportKind , Range } from 'lsp-types' ;
3+ import { describe , it , onError } from '@efekos/es-test/bin/testRunner.js' ;
34import { tokenizeSys , tokenizeSyx } from '../lexer.js' ;
4- import { Range } from 'lsp-types ' ;
5+ import { createSyntaxScriptDiagnosticReport } from '../diagnostic.js ' ;
56import { expect } from 'chai' ;
67import { syxparser } from '../ast.js' ;
78
@@ -136,5 +137,37 @@ describe('Compiler module', () => {
136137
137138 } ) ;
138139
140+ it ( 'for export statements' , ( ) => {
141+
142+ const tokens = tokenizeSyx ( 'export keyword ruleish;' ) ;
143+ const ast = syxparser . parseTokens ( tokens , 'TEST_FILE' ) ;
144+ 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' } ;
145+
146+ astTypeExpectations ( ast ) ;
147+ expect ( ast . body [ 0 ] ) . to . be . a ( 'object' ) . to . be . deep . equal ( stmt ) ;
148+
149+ } ) ;
150+
139151 } ) ;
152+
153+ it ( 'should provide correct diagnostic reports' , ( ) => {
154+
155+ const report = createSyntaxScriptDiagnosticReport ( 'TEST_FILE.syx' , 'keyword ruleis' ) ;
156+
157+ expect ( report ) . to . be . a ( 'object' ) ;
158+ expect ( report ) . to . have . property ( 'items' ) . to . be . a ( 'array' ) . to . have . lengthOf ( 1 ) ;
159+ expect ( report ) . to . have . property ( 'kind' ) . to . be . a ( 'string' ) . to . be . equal ( DocumentDiagnosticReportKind . Full ) ;
160+
161+ const diag = report . items [ 0 ] ;
162+ const item : Diagnostic = { message :'Expected \';\' after statement, found \'EOF\'.' , range :{ start :{ line :0 , character :0 } , end :{ line :0 , character :0 } } , severity :DiagnosticSeverity . Error , source :'syntax-script' , data :[ ] } ;
163+
164+ expect ( diag ) . to . have . property ( 'message' ) . to . be . a ( 'string' ) ;
165+ expect ( diag ) . to . have . property ( 'range' ) ;
166+ expect ( diag ) . to . have . property ( 'severity' ) . to . be . a ( 'number' ) . to . be . equal ( DiagnosticSeverity . Error ) ;
167+ rangeExpectations ( diag . range ) ;
168+ expect ( diag ) . to . have . property ( 'source' ) . to . be . a ( 'string' ) . to . be . equal ( 'syntax-script' ) ;
169+ expect ( diag ) . to . be . a ( 'object' ) . to . be . deep . equal ( item ) ;
170+
171+ } ) ;
172+
140173} ) ;
0 commit comments