@@ -508,6 +508,47 @@ describe('Parser calls value converter', () => {
508508 // Any value that cannot be parsed correctly is automatically false
509509 expectEqual ( 'd 2022-Peach' , false ) ;
510510 } ) ;
511+
512+ test ( 'Enums are correctly parsed with types' , async ( ) => {
513+ const parser = await parserFromGrammar ( `
514+ grammar Test
515+
516+ entry Main:
517+ value=Enum;
518+
519+ Enum returns Enum: 'A' | 'B' | 'C';
520+ type Enum: 'A' | 'B' | 'C';
521+
522+ hidden terminal WS: /\\s+/;
523+ ` ) ;
524+
525+ const result = parser . parse ( 'A' ) ;
526+ expect ( result . lexerErrors . length ) . toBe ( 0 ) ;
527+ expect ( result . parserErrors . length ) . toBe ( 0 ) ;
528+ const value = result . value as unknown as { value : string } ;
529+ expect ( value . value ) . toBeTypeOf ( 'string' ) ;
530+ expect ( value . value ) . toBe ( 'A' ) ;
531+ } ) ;
532+
533+ test ( 'Enums are correctly parsed without types' , async ( ) => {
534+ const parser = await parserFromGrammar ( `
535+ grammar Test
536+
537+ entry Main:
538+ value=Enum;
539+
540+ Enum returns string: 'A' | 'B' | 'C';
541+
542+ hidden terminal WS: /\\s+/;
543+ ` ) ;
544+
545+ const result = parser . parse ( 'A' ) ;
546+ expect ( result . lexerErrors . length ) . toBe ( 0 ) ;
547+ expect ( result . parserErrors . length ) . toBe ( 0 ) ;
548+ const value = result . value as unknown as { value : string } ;
549+ expect ( value . value ) . toBeTypeOf ( 'string' ) ;
550+ expect ( value . value ) . toBe ( 'A' ) ;
551+ } ) ;
511552} ) ;
512553
513554// Constructs a grammar w/ a special token-builder to support multi-mode lexing
0 commit comments