From 71a5cc94a1c0fe2ce035f9c0c26ee5df8bc2953b Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Thu, 20 Jul 2017 13:13:57 -0400 Subject: Lex and parse keepHigh --- __tests__/lexer.test.js | 12 ++++++++++++ __tests__/parser.test.js | 12 ++++++++++++ 2 files changed, 24 insertions(+) (limited to '__tests__') diff --git a/__tests__/lexer.test.js b/__tests__/lexer.test.js index 3003fb9..04a95e1 100644 --- a/__tests__/lexer.test.js +++ b/__tests__/lexer.test.js @@ -136,4 +136,16 @@ describe('lex', () => { ]) }) }) + + describe('keep', () => { + test('1K2d20', () => { + expect(lex('1K2d20')).toEqual([ + { type: 'constant', value: 1 }, + { type: 'K' }, + { type: 'constant', value: 2 }, + { type: 'd' }, + { type: 'constant', value: 20 } + ]) + }) + }) }) diff --git a/__tests__/parser.test.js b/__tests__/parser.test.js index 26febef..fb554f9 100644 --- a/__tests__/parser.test.js +++ b/__tests__/parser.test.js @@ -127,6 +127,18 @@ describe('parse', () => { }) }) + it('parses dice with keep', () => { + expect(parse('1K2d20')).toEqual({ + type: 'K', + left: { type: 'constant', value: 1 }, + right: { + type: 'd', + left: { type: 'constant', value: 2 }, + right: { type: 'constant', value: 20 } + } + }) + }) + describe('parsing parentheses', () => { test('(1d6)d6', () => { expect(parse('(1d6)d6')).toEqual({ -- cgit v1.2.3