m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/__tests__
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-08-22 17:03:45 -0400
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-08-22 17:03:45 -0400
commit594f3b0c20c5b12f0d1ef11705187c22c1e40faf (patch)
tree480a141c74304ba3a49f86c44a84d28f82dfd7eb /__tests__
parent1ae29437d03ea010da1b87dc12fd155d414e9c1f (diff)
Lex and parse keepLow
Diffstat (limited to '__tests__')
-rw-r--r--__tests__/lexer.test.js9
-rw-r--r--__tests__/parser.test.js14
2 files changed, 22 insertions, 1 deletions
diff --git a/__tests__/lexer.test.js b/__tests__/lexer.test.js
index d7a4368..1e80c25 100644
--- a/__tests__/lexer.test.js
+++ b/__tests__/lexer.test.js
@@ -160,6 +160,15 @@ describe('lex', () => {
{ type: 'constant', value: 20 }
])
})
+ test('1k2d20', () => {
+ expect(lex('1k2d20')).toEqual([
+ { type: 'constant', value: 1 },
+ { type: 'k' },
+ { type: 'constant', value: 2 },
+ { type: 'd' },
+ { type: 'constant', value: 20 }
+ ])
+ })
})
describe('bonusAdd', () => {
diff --git a/__tests__/parser.test.js b/__tests__/parser.test.js
index 350af03..873972b 100644
--- a/__tests__/parser.test.js
+++ b/__tests__/parser.test.js
@@ -127,7 +127,7 @@ describe('parse', () => {
})
})
- it('parses dice with keep', () => {
+ it('parses dice with keep high', () => {
expect(parse('1K2d20')).toEqual({
type: 'K',
left: { type: 'constant', value: 1 },
@@ -139,6 +139,18 @@ describe('parse', () => {
})
})
+ it('parses dice with keep low', () => {
+ expect(parse('1k2d20')).toEqual({
+ type: 'k',
+ left: { type: 'constant', value: 1 },
+ right: {
+ type: 'd',
+ left: { type: 'constant', value: 2 },
+ right: { type: 'constant', value: 20 }
+ }
+ })
+ })
+
it('parses additive bonuses', () => {
expect(parse('3d4+1')).toEqual({
type: 'bonusAdd',