From 38e82ade6fd207af21f2df6a3e98298338e85eb8 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Wed, 12 Jul 2017 22:54:33 -0400 Subject: Lex basic dice --- __tests__/lexer.test.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 __tests__/lexer.test.js (limited to '__tests__') diff --git a/__tests__/lexer.test.js b/__tests__/lexer.test.js new file mode 100644 index 0000000..20d461f --- /dev/null +++ b/__tests__/lexer.test.js @@ -0,0 +1,29 @@ +const { lex } = require('../src/lexer.js') + +describe('lex', () => { + it('lexes the empty string', () => { + expect(lex('')).toEqual([]) + }) + + it('signals an error on unexpected input', () => { + expect(lex('q')).toBe('error') + }) + + describe('basic dice', () => { + it('1d6', () => { + expect(lex('1d6')).toEqual([ + { type: 'number', value: 1 }, + { type: 'd' }, + { type: 'number', value: 6 } + ]) + }) + + it('42d172', () => { + expect(lex('42d172')).toEqual([ + { type: 'number', value: 42 }, + { type: 'd' }, + { type: 'number', value: 172 } + ]) + }) + }) +}) -- cgit v1.2.3