diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-08-22 15:19:56 -0400 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-08-22 15:19:56 -0400 |
commit | 845ed56bb448e52a7f708504b91a6c5d492f228d (patch) | |
tree | 0026f5a04f20fc1be718faf1b863e67ad7b9d6f5 /__tests__ | |
parent | a31c3a1fd44a37cf0fcfff8c1cc52792565247b3 (diff) | |
parent | 034d62f90d9c748f38209991c812692e5a99bbd9 (diff) |
Merge branch 'addToken' into bonus
Diffstat (limited to '__tests__')
-rw-r--r-- | __tests__/lexer.test.js | 39 | ||||
-rw-r--r-- | __tests__/parser.test.js | 4 |
2 files changed, 28 insertions, 15 deletions
diff --git a/__tests__/lexer.test.js b/__tests__/lexer.test.js index 04a95e1..6900764 100644 --- a/__tests__/lexer.test.js +++ b/__tests__/lexer.test.js @@ -10,24 +10,24 @@ describe('lex', () => { }) it('throws on unexpected input at the end', () => { - expect(() => { lex('1d6 `') }).toThrow(/Syntax error/) + expect(() => { lex('1d6`') }).toThrow(/Syntax error/) }) it('throws on unexpected input in the middle', () => { - expect(() => { lex('2d3 + b 3d4') }).toThrow(/Syntax error/) + expect(() => { lex('2d3 + b3d4') }).toThrow(/Syntax error/) }) - describe('ignores whitespace', () => { + describe('throws on unexpected whitespace', () => { it('2 d 4', () => { - expect(lex('2 d 4')).not.toBe('error') + expect(() => { lex('2 d 4') }).toThrow(/Syntax error/) }) it(' 1d8', () => { - expect(lex(' 1d8')).not.toBe('error') + expect(() => { lex(' 1d8') }).toThrow(/Syntax error/) }) it('3d4 ', () => { - expect(lex('3d4 ')).not.toBe('error') + expect(() => { lex('3d4 ') }).toThrow(/Syntax error/) }) }) @@ -55,7 +55,7 @@ describe('lex', () => { { type: 'constant', value: 1 }, { type: 'd' }, { type: 'constant', value: 6 }, - { type: '+' }, + { type: 'bigPlus' }, { type: 'constant', value: 1 }, { type: 'd' }, { type: 'constant', value: 4 } @@ -67,7 +67,7 @@ describe('lex', () => { { type: 'constant', value: 2 }, { type: 'd' }, { type: 'constant', value: 17 }, - { type: '+' }, + { type: 'bigPlus' }, { type: 'constant', value: 4 } ]) }) @@ -79,7 +79,7 @@ describe('lex', () => { { type: 'constant', value: 1 }, { type: 'd' }, { type: 'constant', value: 6 }, - { type: '-' }, + { type: 'bigMinus' }, { type: 'constant', value: 1 }, { type: 'd' }, { type: 'constant', value: 4 } @@ -91,7 +91,7 @@ describe('lex', () => { { type: 'constant', value: 2 }, { type: 'd' }, { type: 'constant', value: 17 }, - { type: '-' }, + { type: 'bigMinus' }, { type: 'constant', value: 4 } ]) }) @@ -110,13 +110,13 @@ describe('lex', () => { ]) }) - it('2d(6+3)d4', () => { - expect(lex('2d(6+3)d4')).toEqual([ + it('2d(6 + 3)d4', () => { + expect(lex('2d(6 + 3)d4')).toEqual([ { type: 'constant', value: 2 }, { type: 'd' }, { type: '(' }, { type: 'constant', value: 6 }, - { type: '+' }, + { type: 'bigPlus' }, { type: 'constant', value: 3 }, { type: ')' }, { type: 'd' }, @@ -125,6 +125,19 @@ describe('lex', () => { }) }) + describe('lexes negatives', () => { + it('-(1d6)', () => { + expect(lex('-(1d6)')).toEqual([ + { type: 'minus' }, + { type: '(' }, + { type: 'constant', value: 1 }, + { type: 'd' }, + { type: 'constant', value: 6 }, + { type: ')' } + ]) + }) + }) + describe('exploding dice', () => { test('1E1d6', () => { expect(lex('1E1d6')).toEqual([ diff --git a/__tests__/parser.test.js b/__tests__/parser.test.js index fb554f9..bc88894 100644 --- a/__tests__/parser.test.js +++ b/__tests__/parser.test.js @@ -152,8 +152,8 @@ describe('parse', () => { }) }) - test('2d(6+3)d4', () => { - expect(parse('2d(6+3)d4')).toEqual({ + test('2d(6 + 3)d4', () => { + expect(parse('2d(6 + 3)d4')).toEqual({ type: 'd', left: { type: 'constant', value: 2 }, right: { |