Skip to content

Commit 51263dd

Browse files
committed
add 2 new test
1 parent 41b800d commit 51263dd

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AnyExportable, ExportType, Exported, ExportedFunction, ExportedKeyword, ExportedOperator, OneParameterMethod, ReturnerMethod, SyntaxScriptCompiler, escapeRegex, regexes } from './compiler.js';
1+
import { AnyExportable, ExportType, Exported, ExportedFunction, ExportedKeyword, ExportedOperator, OneParameterMethod, ReturnerMethod, SyntaxScriptCompiler, escapeRegex } from './compiler.js';
22
import { BaseRule, BooleanRule, Functionary, FunctionaryValueType, Rule, RuleType, StringRule, dictionary } from './dictionary/index.js';
33
import { BraceExpression, CompileStatement, CompilerError, Expression, FunctionStatement, GlobalStatement, ImportStatement, ImportsStatement, KeywordStatement, Node, NodeType, OperatorStatement, ParenExpression, PrimitiveTypeExpression, ProgramStatement, RuleStatement, SquareExpression,Statement,StringExpression,SyxConfig,SyxConfigCompile,Token,TokenType,VariableExpression,WhitespaceIdentifierExpression,isCompilerError,statementIsA } from './types.js';
44
import { createSyntaxScriptDiagnosticReport,subRange } from './diagnostic.js';

src/test/compiler.test.ts

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
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';
34
import { tokenizeSys, tokenizeSyx } from '../lexer.js';
4-
import { Range } from 'lsp-types';
5+
import { createSyntaxScriptDiagnosticReport } from '../diagnostic.js';
56
import { expect } from 'chai';
67
import { 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

Comments
 (0)