diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-07-15 23:04:50 -0400 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-07-15 23:09:26 -0400 |
commit | 80df0f9425e8b64b8a3fcca308cb784d02d52f62 (patch) | |
tree | 9135b9cae1c34e6851f8c3bcfa5b59b8a33ac861 /__tests__ | |
parent | e0ab43bcdc050ca3cac2adea927817d99700737e (diff) |
Implement the unary 'd' operation
Diffstat (limited to '__tests__')
-rw-r--r-- | __tests__/parser.test.js | 21 |
1 files changed, 14 insertions, 7 deletions
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 } } }) }) |