-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.test.js
More file actions
79 lines (63 loc) · 1.77 KB
/
bot.test.js
File metadata and controls
79 lines (63 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import test from 'ava'
import { parseDiceCommand } from './dice.js'
// parseDiceCommand returns null for non-dice input
test('ignores plain text', (t) => {
t.is(parseDiceCommand('hello'), null)
})
test('ignores empty string', (t) => {
t.is(parseDiceCommand(''), null)
})
test('ignores partial match', (t) => {
t.is(parseDiceCommand('roll 4d6'), null)
})
test('parses d6', (t) => {
const result = parseDiceCommand('d6')
t.regex(result, /⟵ \[\d\] 1d6$/)
})
test('parses 1d6', (t) => {
const result = parseDiceCommand('1d6')
t.regex(result, /⟵ \[\d\] 1d6$/)
})
test('parses 2d6', (t) => {
const result = parseDiceCommand('2d6')
t.regex(result, /⟵ \[\d, \d\] 2d6$/)
})
test('parses 4d6', (t) => {
const result = parseDiceCommand('4d6')
t.regex(result, /⟵ \[\d, \d, \d, \d\] 4d6$/)
})
test('parses d20+5', (t) => {
const result = parseDiceCommand('d20+5')
t.regex(result, /\+5 1d20\+5$/)
})
test('parses d6-1', (t) => {
const result = parseDiceCommand('d6-1')
t.regex(result, /-1 1d6-1$/)
})
test('is case insensitive', (t) => {
t.not(parseDiceCommand('D6'), null)
t.not(parseDiceCommand('D6N'), null)
})
test('trims whitespace', (t) => {
t.not(parseDiceCommand(' d6 '), null)
})
test('parses d6n', (t) => {
const result = parseDiceCommand('d6n')
t.regex(result, /d6n$/)
})
test('rejects d8n', (t) => {
const result = parseDiceCommand('d8n')
t.is(result, 'Named dice only supports d6n')
})
test('3#d6 returns 3 lines', (t) => {
const result = parseDiceCommand('3#d6')
t.is(result.split('\n').length, 3)
})
test('4#d6n returns 4 lines', (t) => {
const result = parseDiceCommand('4#d6n')
t.is(result.split('\n').length, 4)
})
test('1#d6 returns 1 line', (t) => {
const result = parseDiceCommand('1#d6')
t.is(result.split('\n').length, 1)
})