From 80df0f9425e8b64b8a3fcca308cb784d02d52f62 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Sat, 15 Jul 2017 23:04:50 -0400 Subject: Implement the unary 'd' operation --- __tests__/parser.test.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to '__tests__') diff --git a/__tests__/parser.test.js b/__tests__/parser.test.js index f3c6e97..47944d2 100644 --- a/__tests__/parser.test.js +++ b/__tests__/parser.test.js @@ -8,8 +8,7 @@ describe('parse', () => { }) it('throws when two binary operations follow each other', () => { - expect(() => { parse('1dd2') }).toThrow(/Syntax error/) - expect(() => { parse('1+d2') }).toThrow(/Syntax error/) + expect(() => { parse('1++2') }).toThrow(/Syntax error/) }) it('throws when two dice not combined with a binary operation', () => { @@ -22,6 +21,14 @@ describe('parse', () => { expect(parse('5')).toEqual({ type: 'constant', value: 5 }) }) + it('parses a simple die with no left side', () => { + expect(parse('d6')).toEqual({ + type: 'd', + left: { type: 'constant', value: 1 }, + right: { type: 'constant', value: 6 } + }) + }) + it('parses a simple die (1d6)', () => { expect(parse('1d6')).toEqual({ type: 'd', @@ -59,17 +66,17 @@ describe('parse', () => { }) it('parses dice addition', () => { - expect(parse('1d6 + 2d8')).toEqual({ + expect(parse('2d8 + d6')).toEqual({ type: 'add', left: { type: 'd', - left: { type: 'constant', value: 1 }, - right: { type: 'constant', value: 6 } + left: { type: 'constant', value: 2 }, + right: { type: 'constant', value: 8 } }, right: { type: 'd', - left: { type: 'constant', value: 2 }, - right: { type: 'constant', value: 8 } + left: { type: 'constant', value: 1 }, + right: { type: 'constant', value: 6 } } }) }) -- cgit v1.2.3