From 00dc2d73de8cad528931698604dd915c97c21fef Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Thu, 8 Sep 2022 20:48:28 +0530 Subject: [PATCH] fix: Info diagram case sensitivity --- src/diagrams/info/info.spec.ts | 22 +++++++++++++++------- src/diagrams/info/infoParser.ts | 6 +++--- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/diagrams/info/info.spec.ts b/src/diagrams/info/info.spec.ts index b293d1564..7f5741dd0 100644 --- a/src/diagrams/info/info.spec.ts +++ b/src/diagrams/info/info.spec.ts @@ -35,11 +35,19 @@ describe('when parsing an info graph it', function () { }).toThrow(); }); - // TODO - // it('should no throw an error when showInfo is not defined', function () { - // expect(() => { - // infoParser.parse('info'); - // }).not.toThrow(); - // expect(infoDb.getInfo()).toEqual(false); - // }); + it('should not throw an error when showInfo is not defined', function () { + infoParser.parse('info'); + expect(infoDb.getInfo()).toEqual(true); + }); + + it.each([ + `InFo`, + `Info + showinfo`, + `info + shOWINFO`, + ])('should be case insensitive', function (str) { + infoParser.parse(str); + expect(infoDb.getInfo()).toEqual(true); + }); }); diff --git a/src/diagrams/info/infoParser.ts b/src/diagrams/info/infoParser.ts index 80702b2fc..14044a443 100644 --- a/src/diagrams/info/infoParser.ts +++ b/src/diagrams/info/infoParser.ts @@ -2,8 +2,8 @@ import { createToken, EmbeddedActionsParser, Lexer } from 'chevrotain'; import { log } from '../../logger'; import infoDb from './infoDb'; -const Info = createToken({ name: 'Info', pattern: /info/ }); -const ShowInfo = createToken({ name: 'ShowInfo', pattern: /showInfo/ }); +const Info = createToken({ name: 'Info', pattern: /info/i }); +const ShowInfo = createToken({ name: 'ShowInfo', pattern: /showInfo/i }); const NewLine = createToken({ name: 'NewLine', pattern: /\r?\n/, @@ -44,7 +44,7 @@ class InfoParser extends EmbeddedActionsParser { public hdr = this.RULE('hdr', () => { this.CONSUME(Info); - this.CONSUME(NewLine); + this.OPTION(() => this.CONSUME(NewLine)); }); public row = this.RULE('row', () => {