diff options
Diffstat (limited to '__tests__/parser.test.js')
-rw-r--r-- | __tests__/parser.test.js | 96 |
1 files changed, 48 insertions, 48 deletions
diff --git a/__tests__/parser.test.js b/__tests__/parser.test.js index fc47576..25edbfc 100644 --- a/__tests__/parser.test.js +++ b/__tests__/parser.test.js @@ -97,6 +97,54 @@ 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 } + }) + }) + + it('parses negative bonuses', () => { + expect(parse('3d4-1')).toEqual({ + type: 'bonusSubtract', + left: { + type: 'd', + left: { type: 'constant', value: 3 }, + right: { type: 'constant', value: 4 } + }, + right: { type: 'constant', value: 1 } + }) + }) + + test('bonus binds stronger than addition', () => { + expect(parse('2d6 + 2d6+2d6')).toEqual({ + type: 'add', + left: { + type: 'd', + left: { type: 'constant', value: 2 }, + right: { type: 'constant', value: 6 } + }, + right: { + type: 'bonusAdd', + left: { + type: 'd', + left: { type: 'constant', value: 2 }, + right: { type: 'constant', value: 6 } + }, + right: { + type: 'd', + left: { type: 'constant', value: 2 }, + right: { type: 'constant', value: 6 } + } + } + }) + }) + it('parses negatives', () => { expect(parse('-1 + (-(2d6))')).toEqual({ type: 'add', @@ -151,54 +199,6 @@ 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 } - }) - }) - - it('parses negative bonuses', () => { - expect(parse('3d4-1')).toEqual({ - type: 'bonusSubtract', - left: { - type: 'd', - left: { type: 'constant', value: 3 }, - right: { type: 'constant', value: 4 } - }, - right: { type: 'constant', value: 1 } - }) - }) - - test('bonus binds stronger than addition', () => { - expect(parse('2d6 + 2d6+2d6')).toEqual({ - type: 'add', - left: { - type: 'd', - left: { type: 'constant', value: 2 }, - right: { type: 'constant', value: 6 } - }, - right: { - type: 'bonusAdd', - left: { - type: 'd', - left: { type: 'constant', value: 2 }, - right: { type: 'constant', value: 6 } - }, - right: { - type: 'd', - left: { type: 'constant', value: 2 }, - right: { type: 'constant', value: 6 } - } - } - }) - }) - describe('parsing parentheses', () => { test('(1d6)d6', () => { expect(parse('(1d6)d6')).toEqual({ |