m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/__tests__
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-07-14 18:14:14 -0400
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-07-14 18:14:14 -0400
commitd3132a5463908bcabd0578ad48a457b2bec30a9a (patch)
tree4c752b28616663c418fa44b1f56219a3a4dd1e44 /__tests__
parenta15a2986c95131a13d3707ae50f8a215dcaac564 (diff)
Lex and parse subtraction
Diffstat (limited to '__tests__')
-rw-r--r--__tests__/lexer.test.js24
-rw-r--r--__tests__/parser.test.js16
2 files changed, 40 insertions, 0 deletions
diff --git a/__tests__/lexer.test.js b/__tests__/lexer.test.js
index 6434e17..e9115a1 100644
--- a/__tests__/lexer.test.js
+++ b/__tests__/lexer.test.js
@@ -64,4 +64,28 @@ describe('lex', () => {
])
})
})
+
+ describe('lexes subtraction', () => {
+ it('1d6 - 1d4', () => {
+ expect(lex('1d6 - 1d4')).toEqual([
+ { type: 'constant', value: 1 },
+ { type: 'd' },
+ { type: 'constant', value: 6 },
+ { type: '-' },
+ { type: 'constant', value: 1 },
+ { type: 'd' },
+ { type: 'constant', value: 4 }
+ ])
+ })
+
+ it('2d17 - 4', () => {
+ expect(lex('2d17 - 4')).toEqual([
+ { type: 'constant', value: 2 },
+ { type: 'd' },
+ { type: 'constant', value: 17 },
+ { type: '-' },
+ { type: 'constant', value: 4 }
+ ])
+ })
+ })
})
diff --git a/__tests__/parser.test.js b/__tests__/parser.test.js
index b0dc28d..6fe296c 100644
--- a/__tests__/parser.test.js
+++ b/__tests__/parser.test.js
@@ -56,4 +56,20 @@ describe('parse', () => {
}
})
})
+
+ it('parses dice subtraction', () => {
+ expect(parse('1d6 - 2d8')).toEqual({
+ type: 'subtract',
+ 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 }
+ }
+ })
+ })
})