fix: Info diagram case sensitivity

This commit is contained in:
Sidharth Vinod
2022-09-08 20:48:28 +05:30
parent 6138dd8714
commit 00dc2d73de
2 changed files with 18 additions and 10 deletions

View File

@@ -35,11 +35,19 @@ describe('when parsing an info graph it', function () {
}).toThrow(); }).toThrow();
}); });
// TODO it('should not throw an error when showInfo is not defined', function () {
// it('should no throw an error when showInfo is not defined', function () { infoParser.parse('info');
// expect(() => { expect(infoDb.getInfo()).toEqual(true);
// infoParser.parse('info'); });
// }).not.toThrow();
// expect(infoDb.getInfo()).toEqual(false); it.each([
// }); `InFo`,
`Info
showinfo`,
`info
shOWINFO`,
])('should be case insensitive', function (str) {
infoParser.parse(str);
expect(infoDb.getInfo()).toEqual(true);
});
}); });

View File

@@ -2,8 +2,8 @@ import { createToken, EmbeddedActionsParser, Lexer } from 'chevrotain';
import { log } from '../../logger'; import { log } from '../../logger';
import infoDb from './infoDb'; import infoDb from './infoDb';
const Info = createToken({ name: 'Info', pattern: /info/ }); const Info = createToken({ name: 'Info', pattern: /info/i });
const ShowInfo = createToken({ name: 'ShowInfo', pattern: /showInfo/ }); const ShowInfo = createToken({ name: 'ShowInfo', pattern: /showInfo/i });
const NewLine = createToken({ const NewLine = createToken({
name: 'NewLine', name: 'NewLine',
pattern: /\r?\n/, pattern: /\r?\n/,
@@ -44,7 +44,7 @@ class InfoParser extends EmbeddedActionsParser {
public hdr = this.RULE('hdr', () => { public hdr = this.RULE('hdr', () => {
this.CONSUME(Info); this.CONSUME(Info);
this.CONSUME(NewLine); this.OPTION(() => this.CONSUME(NewLine));
}); });
public row = this.RULE('row', () => { public row = this.RULE('row', () => {