diff options
-rw-r--r-- | __tests__/lexer.test.js | 24 | ||||
-rw-r--r-- | src/lexer.js | 1 |
2 files changed, 25 insertions, 0 deletions
diff --git a/__tests__/lexer.test.js b/__tests__/lexer.test.js index 37158e6..e887e09 100644 --- a/__tests__/lexer.test.js +++ b/__tests__/lexer.test.js @@ -40,4 +40,28 @@ describe('lex', () => { ]) }) }) + + describe('lexes addition', () => { + it('1d6 + 1d4', () => { + expect(lex('1d6 + 1d4')).toEqual([ + { type: 'number', value: 1 }, + { type: 'd' }, + { type: 'number', value: 6 }, + { type: '+' }, + { type: 'number', value: 1 }, + { type: 'd' }, + { type: 'number', value: 4 } + ]) + }) + + it('2d17 + 4', () => { + expect(lex('2d17 + 4')).toEqual([ + { type: 'number', value: 2 }, + { type: 'd' }, + { type: 'number', value: 17 }, + { type: '+' }, + { type: 'number', value: 4 } + ]) + }) + }) }) diff --git a/src/lexer.js b/src/lexer.js index 7d876fb..eedabd7 100644 --- a/src/lexer.js +++ b/src/lexer.js @@ -20,6 +20,7 @@ const newSkippableLexeme = (type, regex) => { newValueLexeme('number', '\\d+', Number) newLexemeType('d', 'd') +newLexemeType('+', '\\+') newSkippableLexeme('whitespace', '\\s+') const lex = (expressionString) => { |