Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions test/advplParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { parseAdvpl , lexAdvpl, gettokenVocabulary } from "../src/parser/advplPa
import { expect } from 'chai';
import 'mocha';
import { tokenMatcher } from "chevrotain";

describe('Minimal lex', () => {
it('should return 0 erros', () => {
const lexingResult = lexAdvpl("function tste()\nreturn");
Expand All @@ -13,4 +14,65 @@ describe('Minimal lex', () => {
expect(tokenMatcher(tokens[1], tokenVocabulary["Identifier"])).to.be.true;

});
});

describe('Function with parameters', () => {
it('should return 0 erros', () => {
const lexingResult = lexAdvpl("function testing(param01,param02,param03)\nreturn nil");
expect(lexingResult.errors).to.be.empty;
let tokenVocabulary = gettokenVocabulary();
let tokens = lexingResult.tokens
expect(tokenMatcher(tokens[0], tokenVocabulary["FunctionToken"])).to.be.true;
expect(tokenMatcher(tokens[1], tokenVocabulary["Identifier"])).to.be.true;

});
});

describe('Main function with parameters', () => {
it('should return 0 erros', () => {
const lexingResult = lexAdvpl("main function testing(param01,param02)\nreturn nil");
expect(lexingResult.errors).to.be.empty;
let tokenVocabulary = gettokenVocabulary();
let tokens = lexingResult.tokens
expect(tokenMatcher(tokens[0], tokenVocabulary["MainToken"])).to.be.true;
expect(tokenMatcher(tokens[1], tokenVocabulary["FunctionToken"])).to.be.true;
expect(tokenMatcher(tokens[2], tokenVocabulary["Identifier"])).to.be.true;

});
});

describe('User function with parameters', () => {
it('should return 0 erros', () => {
const lexingResult = lexAdvpl("user function testing(param01,param02)\nreturn nil");
expect(lexingResult.errors).to.be.empty;
let tokenVocabulary = gettokenVocabulary();
let tokens = lexingResult.tokens
expect(tokenMatcher(tokens[0], tokenVocabulary["UserToken"])).to.be.true;
expect(tokenMatcher(tokens[1], tokenVocabulary["FunctionToken"])).to.be.true;
expect(tokenMatcher(tokens[2], tokenVocabulary["Identifier"])).to.be.true;

});
});

describe('Static function with parameters', () => {
it('should return 0 erros', () => {
const lexingResult = lexAdvpl("static function testing(param01,param02)\nreturn nil");
expect(lexingResult.errors).to.be.empty;
let tokenVocabulary = gettokenVocabulary();
let tokens = lexingResult.tokens
expect(tokenMatcher(tokens[0], tokenVocabulary["StaticToken"])).to.be.true;
expect(tokenMatcher(tokens[1], tokenVocabulary["FunctionToken"])).to.be.true;
expect(tokenMatcher(tokens[2], tokenVocabulary["Identifier"])).to.be.true;

});
});

describe('Start function name with number', () => {
it('should return 1 erros', () => {
const lexingResult = lexAdvpl("function 666func()\nreturn");
let tokenVocabulary = gettokenVocabulary();
let tokens = lexingResult.tokens
expect(tokenMatcher(tokens[0], tokenVocabulary["FunctionToken"])).to.be.true;
expect(tokenMatcher(tokens[1], tokenVocabulary["Identifier"])).to.be.false;
});
});