m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/__tests__/parser.test.js
diff options
context:
space:
mode:
Diffstat (limited to '__tests__/parser.test.js')
-rw-r--r--__tests__/parser.test.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/__tests__/parser.test.js b/__tests__/parser.test.js
index 6e575b6..5d4288d 100644
--- a/__tests__/parser.test.js
+++ b/__tests__/parser.test.js
@@ -97,6 +97,22 @@ describe('parse', () => {
})
})
+ it('parses dice multiplication', () => {
+ expect(parse('1d6 * 2d8')).toEqual({
+ type: 'multiply',
+ left: {
+ type: 'd',
+ left: { type: 'constant', value: 1 },
+ right: { type: 'constant', value: 6 }
+ },
+ right: {
+ type: 'd',
+ left: { type: 'constant', value: 2 },
+ right: { type: 'constant', value: 8 }
+ }
+ })
+ })
+
it('parses additive bonuses', () => {
expect(parse('3d4+1')).toEqual({
type: 'bonusAdd',
@@ -282,4 +298,30 @@ describe('parse', () => {
})
})
})
+
+ describe('order of operations', () => {
+ test('2 * 3 + 4', () => {
+ expect(parse('2 * 3 + 4')).toEqual({
+ type: 'add',
+ left: {
+ type: 'multiply',
+ left: { type: 'constant', value: 2 },
+ right: { type: 'constant', value: 3 },
+ },
+ right: { type: 'constant', value: 4 },
+ })
+ })
+
+ test('2 + 3 * 4', () => {
+ expect(parse('2 + 3 * 4')).toEqual({
+ type: 'add',
+ left: { type: 'constant', value: 2 },
+ right: {
+ type: 'multiply',
+ left: { type: 'constant', value: 3 },
+ right: { type: 'constant', value: 4 },
+ }
+ })
+ })
+ })
})