m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/__tests__
diff options
context:
space:
mode:
Diffstat (limited to '__tests__')
-rw-r--r--__tests__/parser.test.js21
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 }
}
})
})