File tree Expand file tree Collapse file tree
packages/idea-parser/tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { expect, use } from 'chai';
44import deepEqualInAnyOrder from 'deep-equal-in-any-order' ;
55import SchemaTree from '../src/trees/SchemaTree' ;
66import Compiler from '../src/Compiler' ;
7+ import Exception from '../src/Exception' ;
78
89use ( deepEqualInAnyOrder ) ;
910const cleanAST = ( node : any ) => {
@@ -36,4 +37,12 @@ describe('Schema Tree', () => {
3637 const final = JSON . parse ( fs . readFileSync ( `${ __dirname } /fixtures/final.json` , 'utf8' ) ) ;
3738 expect ( Compiler . final ( actual ) ) . to . deep . equalInAnyOrder ( final ) ;
3839 } ) ;
40+
41+
42+ // Line 81 - 86
43+ it ( 'Should throw an exception when there is an unexpected token at the end of the code' , ( ) => {
44+ const codeWithUnexpectedToken = 'enum TestEnum { VALUE1, VALUE2, } unexpectedToken' ;
45+
46+ expect ( ( ) => SchemaTree . parse ( codeWithUnexpectedToken ) ) . to . throw ( Exception , / U n e x p e c t e d t o k e n , / ) ;
47+ } ) ;
3948} ) ;
Original file line number Diff line number Diff line change @@ -37,4 +37,37 @@ describe('Type Tree', () => {
3737 //console.log(JSON.stringify(actual, null, 2));
3838 expect ( actual ) . to . deep . equalInAnyOrder ( expected ) ;
3939 } ) ;
40+
41+
42+ // Line 39 - 40
43+ it ( 'Should correctly identify "typeword" token at the start of the input string' , ( ) => {
44+ const lexerMock = {
45+ define : ( name : string , callback : Function ) => {
46+ if ( name === 'TypeWord' ) {
47+ const result = callback ( 'type Example' , 0 ) ;
48+ expect ( result ) . to . deep . equal ( {
49+ type : '_TypeWord' ,
50+ start : 0 ,
51+ end : 4 ,
52+ value : 'type' ,
53+ raw : 'type'
54+ } ) ;
55+ }
56+ }
57+ } ;
58+ TypeTree . definitions ( lexerMock as any ) ;
59+ } ) ;
60+
61+ // Line 55
62+ it ( 'Should throw an error when the input code is an empty string' , ( ) => {
63+ expect ( ( ) => {
64+ const lexerMock = {
65+ expect : ( tokenType : string ) => { throw new Error ( 'Unexpected end of input' ) ; } ,
66+ load : ( ) => { }
67+ } ;
68+ const typeTree = new TypeTree ( ) ;
69+ ( typeTree as any ) . _lexer = lexerMock ;
70+ typeTree . parse ( '' ) ;
71+ } ) . to . throw ( Error , 'Unexpected end of input' ) ;
72+ } ) ;
4073} ) ;
You can’t perform that action at this time.
0 commit comments