m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/__tests__
diff options
context:
space:
mode:
Diffstat (limited to '__tests__')
-rw-r--r--__tests__/lexer.test.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/__tests__/lexer.test.js b/__tests__/lexer.test.js
new file mode 100644
index 0000000..20d461f
--- /dev/null
+++ b/__tests__/lexer.test.js
@@ -0,0 +1,29 @@
+const { lex } = require('../src/lexer.js')
+
+describe('lex', () => {
+ it('lexes the empty string', () => {
+ expect(lex('')).toEqual([])
+ })
+
+ it('signals an error on unexpected input', () => {
+ expect(lex('q')).toBe('error')
+ })
+
+ describe('basic dice', () => {
+ it('1d6', () => {
+ expect(lex('1d6')).toEqual([
+ { type: 'number', value: 1 },
+ { type: 'd' },
+ { type: 'number', value: 6 }
+ ])
+ })
+
+ it('42d172', () => {
+ expect(lex('42d172')).toEqual([
+ { type: 'number', value: 42 },
+ { type: 'd' },
+ { type: 'number', value: 172 }
+ ])
+ })
+ })
+})