@@ -4,6 +4,7 @@ import fs from 'node:fs'
44import { describe , it , expect , vi } from 'vitest'
55
66import Parser from '../src/parser.js'
7+ import type { Group , Property } from '../src/ast.js'
78
89const __dirname = url . fileURLToPath ( new URL ( '.' , import . meta. url ) )
910
@@ -114,4 +115,35 @@ describe('parser', () => {
114115
115116 vi . restoreAllMocks ( )
116117 } )
118+
119+ it ( 'parses quoted reserved words as string literals, not native types' , ( ) => {
120+ vi . spyOn ( fs , 'readFileSync' ) . mockReturnValue ( 'Foo = { a: "null", b: "bool", c: "true", d: "false", e: "undefined" }\n' )
121+ const p = new Parser ( 'foo.cddl' )
122+
123+ const properties = ( p . parse ( ) [ 0 ] as Group ) . Properties as Property [ ]
124+ expect ( properties . map ( ( prop ) => prop . Type ) ) . toEqual ( [
125+ [ { Type : 'literal' , Value : 'null' , Unwrapped : false } ] ,
126+ [ { Type : 'literal' , Value : 'bool' , Unwrapped : false } ] ,
127+ [ { Type : 'literal' , Value : 'true' , Unwrapped : false } ] ,
128+ [ { Type : 'literal' , Value : 'false' , Unwrapped : false } ] ,
129+ [ { Type : 'literal' , Value : 'undefined' , Unwrapped : false } ]
130+ ] )
131+
132+ vi . restoreAllMocks ( )
133+ } )
134+
135+ it ( 'still parses bare reserved words as native types and booleans' , ( ) => {
136+ vi . spyOn ( fs , 'readFileSync' ) . mockReturnValue ( 'Foo = { a: null, b: bool, c: true, d: false }\n' )
137+ const p = new Parser ( 'foo.cddl' )
138+
139+ const properties = ( p . parse ( ) [ 0 ] as Group ) . Properties as Property [ ]
140+ expect ( properties . map ( ( prop ) => prop . Type ) ) . toEqual ( [
141+ [ 'null' ] ,
142+ [ 'bool' ] ,
143+ [ { Type : 'literal' , Value : true , Unwrapped : false } ] ,
144+ [ { Type : 'literal' , Value : false , Unwrapped : false } ]
145+ ] )
146+
147+ vi . restoreAllMocks ( )
148+ } )
117149} )
0 commit comments