From 403f2ed88dbef7ce1bbb07a13bca4bc6e35cbcf3 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Tue, 22 Aug 2017 15:35:21 -0400 Subject: Lex and parse additive bonus --- __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 6900764..d7a4368 100644 --- a/__tests__/lexer.test.js +++ b/__tests__/lexer.test.js @@ -161,4 +161,16 @@ describe('lex', () => { ]) }) }) + + describe('bonusAdd', () => { + test('3d4+1', () => { + expect(lex('3d4+1')).toEqual([ + { type: 'constant', value: 3 }, + { type: 'd' }, + { type: 'constant', value: 4 }, + { type: 'plus' }, + { type: 'constant', value: 1 } + ]) + }) + }) }) diff --git a/__tests__/parser.test.js b/__tests__/parser.test.js index bc88894..350af03 100644 --- a/__tests__/parser.test.js +++ b/__tests__/parser.test.js @@ -139,6 +139,18 @@ describe('parse', () => { }) }) + it('parses additive bonuses', () => { + expect(parse('3d4+1')).toEqual({ + type: 'bonusAdd', + left: { + type: 'd', + left: { type: 'constant', value: 3 }, + right: { type: 'constant', value: 4 } + }, + right: { type: 'constant', value: 1 } + }) + }) + describe('parsing parentheses', () => { test('(1d6)d6', () => { expect(parse('(1d6)d6')).toEqual({ -- cgit v1.2.3