123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- import { assert } from 'chai';
- import { IASTParserFacadeInputData } from '../../../src/interfaces/IASTParserFacadeInputData';
- import { ecmaVersion } from '../../../src/constants/EcmaVersion';
- import { ASTParserFacade } from '../../../src/ASTParserFacade';
- describe('ASTParserFacade', () => {
- describe(`parse`, () => {
- describe(`\`Unexpected token\` error code preview`, () => {
- describe('Variant #1: 5 lines of code', () => {
- const sourceCode: string = `` +
- `var foo = 1;
- var bar = 2;
- var baz = 3;,
- var bark = 4;
- var hawk = 5;`;
- let testFunc: () => void;
- before(() => {
- const inputData: IASTParserFacadeInputData = {sourceCode};
- testFunc = () => ASTParserFacade.parse(inputData, { ecmaVersion });
- });
- it('should output code preview when AST parser throws a parse error', () => {
- assert.throws(testFunc, /ERROR in line 3: Unexpected token \(3:28\)\n.*\.\.\.var baz = 3;,\.\.\./);
- });
- });
- describe('Variant #2: 15 lines of code', () => {
- const sourceCode: string = `` +
- `var var1 = 1;
- var var2 = 2;
- var var3 = 3;
- var var4 = 4;
- var var5 = 5;
- var var6 = 6;
- var var7 = 7;
- var var8 = 8;
- var var9 = 9;
- var var10 = 10;
- var foo = 1;
- var bar = 2;
- var baz = 3;,
- var bark = 4;
- var hawk = 5;`;
- let testFunc: () => void;
- before(() => {
- const inputData: IASTParserFacadeInputData = {sourceCode};
- testFunc = () => ASTParserFacade.parse(inputData, { ecmaVersion });
- });
- it('should output code preview when AST parser throws a parse error', () => {
- assert.throws(testFunc, /ERROR in line 13: Unexpected token \(13:28\)\n.*\.\.\.var baz = 3;,\.\.\./);
- });
- });
- describe('Variant #3: code with functions', () => {
- const sourceCode: string = `` +
- `function bar () {
- var a = 1;
- }
- functin baz () {
- var a = 1;
- }
- function bark () {
- var a = 1;
- }`;
- let testFunc: () => void;
- before(() => {
- const inputData: IASTParserFacadeInputData = {sourceCode};
- testFunc = () => ASTParserFacade.parse(inputData, { ecmaVersion });
- });
- it('should output code preview when AST parser throws a parse error', () => {
- assert.throws(testFunc, /ERROR in line 4: Unexpected token \(4:28\)\n.*\.\.\.functin baz \(\) {\.\.\./);
- });
- });
- describe('Variant #4: input file path is set', () => {
- const sourceCode: string = `` +
- `var foo = 1;
- var bar = 2;
- var baz = 3;,
- var bark = 4;
- var hawk = 5;`;
- let testFunc: () => void;
- before(() => {
- const inputData: IASTParserFacadeInputData = {
- sourceCode,
- inputFilePath: '/src/foo.js'
- };
- testFunc = () => ASTParserFacade.parse(inputData, { ecmaVersion });
- });
- it('should output code preview when AST parser throws a parse error', () => {
- assert.throws(testFunc, /ERROR in \/src\/foo\.js, line 3: Unexpected token \(3:32\)\n.*\.\.\.var baz = 3;,\.\.\./);
- });
- });
- });
- });
- });
|