From c5b9b7d03a37b807b212c29a9bdf7afc837c5423 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Fri, 14 Jul 2017 23:34:55 -0400 Subject: Lex and parse parentheses --- __tests__/parser.test.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to '__tests__/parser.test.js') diff --git a/__tests__/parser.test.js b/__tests__/parser.test.js index 6fe296c..a741007 100644 --- a/__tests__/parser.test.js +++ b/__tests__/parser.test.js @@ -72,4 +72,34 @@ describe('parse', () => { } }) }) + + describe('parsing parentheses', () => { + test('(1d6)d6', () => { + expect(parse('(1d6)d6')).toEqual({ + type: 'd', + left: { + type: 'd', + left: { type: 'constant', value: 1 }, + right: { type: 'constant', value: 6 } + }, + right: { type: 'constant', value: 6 }, + }) + }) + + test('2d(6+3)d4', () => { + expect(parse('2d(6+3)d4')).toEqual({ + type: 'd', + left: { type: 'constant', value: 2 }, + right: { + type: 'd', + left: { + type: 'add', + left: { type: 'constant', value: 6 }, + right: { type: 'constant', value: 3 } + }, + right: { type: 'constant', value: 4 } + }, + }) + }) + }) }) -- cgit v1.2.3