1+ import { describe , it } from 'mocha' ;
2+ import { expect , use } from 'chai' ;
3+ import Compiler from '../../idea-parser/src/Compiler'
4+ import {
5+ DataToken ,
6+ DeclarationToken ,
7+ IdentifierToken ,
8+ ImportToken ,
9+ SchemaToken
10+ } from '../src/types' ;
11+
12+ describe ( 'Compiler Test' , ( ) => {
13+
14+ // Line 46
15+ it ( 'Should throw an exception with the message "Invalid data token type" when an invalid token type is encountered' , ( ) => {
16+ const invalidToken = { type : 'InvalidType' } as unknown as DataToken ;
17+ expect ( ( ) => Compiler . data ( invalidToken ) ) . to . throw ( 'Invalid data token type' ) ;
18+ } ) ;
19+
20+ // Line 54
21+ it ( 'Should throw an exception with the message "Invalid Enum" when an invalid enum is encountered' , ( ) => {
22+ const invalidEnumToken = { kind : 'notAnEnum' , declarations : [ ] } as unknown as DeclarationToken ;
23+ expect ( ( ) => Compiler . enum ( invalidEnumToken ) ) . to . throw ( 'Invalid Enum' ) ;
24+ } ) ;
25+
26+ // Line 86
27+ it ( 'Should throw an exception with the message "Unknown reference {token.name}" when references is an empty object' , ( ) => {
28+ const token = { name : 'someReference' } as IdentifierToken ;
29+ expect ( ( ) => Compiler . identifier ( token , { } ) ) . to . throw ( 'Unknown reference someReference' ) ;
30+ } ) ;
31+
32+
33+ // Line 109
34+ it ( 'Should throw an exception with the message "Expecting a columns property" when the columns property is missing' , ( ) => {
35+ const tokenWithoutColumns = { kind : 'model' ,
36+ declarations : [ {
37+ id : { name : 'TestModel' } ,
38+ init : { properties : [ ] }
39+ } ]
40+ } as unknown as DeclarationToken ;
41+ expect ( ( ) => Compiler . model ( tokenWithoutColumns ) ) . to . throw ( 'Expecting a columns property' ) ;
42+ } ) ;
43+
44+ // Line 152
45+ it ( 'Should throw an exception with the message "Invalid Plugin" when an invalid plugin is encountered' , ( ) => {
46+ const invalidPluginToken = { kind : 'notAPlugin' , declarations : [ ] } as unknown as DeclarationToken ;
47+ expect ( ( ) => Compiler . plugin ( invalidPluginToken ) ) . to . throw ( 'Invalid Plugin' ) ;
48+ } ) ;
49+
50+ // Line 168
51+ it ( 'Should throw an exception with the message "Invalid Prop" when an invalid property is encountered' , ( ) => {
52+ const invalidPropToken = { kind : 'notAProp' , declarations : [ ] } as unknown as DeclarationToken ;
53+ expect ( ( ) => Compiler . prop ( invalidPropToken ) ) . to . throw ( 'Invalid Prop' ) ;
54+ } ) ;
55+
56+ // Line 184
57+ it ( 'Should throw an exception with the message "Invalid Schema" when an invalid schema is encountered' , ( ) => {
58+ const invalidSchemaToken = { kind : 'notASchema' , body : [ ] } as unknown as SchemaToken ;
59+ expect ( ( ) => Compiler . schema ( invalidSchemaToken ) ) . to . throw ( 'Invalid Schema' ) ;
60+ } ) ;
61+
62+ // Line 205
63+ it ( 'Should throw an exception with the message "Duplicate key" when a duplicate key is encountered in the schema' , ( ) => {
64+ const duplicateKeyToken = {
65+ kind : 'schema' ,
66+ body : [
67+ {
68+ kind : 'enum' ,
69+ declarations : [ {
70+ id : { name : 'DuplicateKey' } ,
71+ init : { properties : [ { key : { name : 'key1' } , value : { value : 'value1' } } ] }
72+ } ]
73+ } ,
74+ {
75+ kind : 'enum' ,
76+ declarations : [ {
77+ id : { name : 'DuplicateKey' } ,
78+ init : { properties : [ { key : { name : 'key2' } , value : { value : 'value2' } } ] }
79+ } ]
80+ }
81+ ]
82+ } as unknown as SchemaToken ;
83+ expect ( ( ) => Compiler . schema ( duplicateKeyToken ) ) . to . throw ( 'Duplicate DuplicateKey' ) ;
84+ } ) ;
85+
86+ // Line 260
87+ it ( 'Should throw an exception with the message "Invalid Type" when an invalid type is encountered' , ( ) => {
88+ const invalidTypeToken = { kind : 'notAType' , declarations : [ ] } as unknown as DeclarationToken ;
89+ expect ( ( ) => Compiler . type ( invalidTypeToken ) ) . to . throw ( 'Invalid Type' ) ;
90+ } ) ;
91+
92+ // Line 304
93+ it ( 'Should throw an exception with the message "Invalid Import" when an invalid import is encountered' , ( ) => {
94+ const invalidImportToken = { type : 'NotAnImportDeclaration' , source : { value : './invalid.idea' } } as unknown as ImportToken ;
95+ expect ( ( ) => Compiler . use ( invalidImportToken ) ) . to . throw ( 'Invalid Import' ) ;
96+ } ) ;
97+
98+
99+
100+
101+
102+ } )
0 commit comments