From de517d06737f77a0cfc818c159b388b4e0c4d6b1 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Fri, 14 Jul 2017 23:35:23 -0400 Subject: Lex and parse negatives --- __tests__/parser.test.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to '__tests__') diff --git a/__tests__/parser.test.js b/__tests__/parser.test.js index a741007..74ca442 100644 --- a/__tests__/parser.test.js +++ b/__tests__/parser.test.js @@ -73,6 +73,24 @@ describe('parse', () => { }) }) + it('parses negatives', () => { + expect(parse('-1 + (-(2d6))')).toEqual({ + type: 'add', + left: { + type: 'negative', + value: { type: 'constant', value: 1 } + }, + right: { + type: 'negative', + value: { + type: 'd', + left: { type: 'constant', value: 2 }, + right: { type: 'constant', value: 6 } + } + } + }) + }) + describe('parsing parentheses', () => { test('(1d6)d6', () => { expect(parse('(1d6)d6')).toEqual({ -- cgit v1.2.3