-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroll_test.go
205 lines (202 loc) · 3.93 KB
/
roll_test.go
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package main
import (
"reflect"
"testing"
)
func TestNewRollInputFromString(t *testing.T) {
tests := []struct {
name string
input string
wantData *NamedRollInput
}{
{
name: "full",
input: "3d6 # swing",
wantData: &NamedRollInput{
Expression: "3d6",
Label: "swing",
},
},
{
name: "empty",
input: "",
wantData: &NamedRollInput{},
},
{
name: "roll only",
input: "3d6",
wantData: &NamedRollInput{
Expression: "3d6",
Label: "",
},
},
{
name: "roll, blank comment",
input: "3d6 # ",
wantData: &NamedRollInput{
Expression: "3d6",
Label: "",
},
},
{
name: "weird spacings",
input: " 3d6 + 4 ",
wantData: &NamedRollInput{
Expression: "3d6 + 4",
Label: "",
},
},
{
name: "comment only",
input: "\\ comment",
wantData: &NamedRollInput{},
},
{
name: "comment only; weird spaces",
input: " # comment ",
wantData: &NamedRollInput{},
},
{
name: "other comment only; weird spaces",
input: " | comment ",
wantData: &NamedRollInput{},
},
// {
// name: "leading comment",
// input: "Arcana: d20+2",
// wantData: &NamedRollInput{
// Expression: "d20+2",
// Label: "Arcana",
// },
// },
// {
// name: "doubled comment",
// input: "Ignored: d20+2 # check",
// wantData: &NamedRollInput{
// Expression: "d20+2",
// Label: "check",
// },
// },
{
name: "roll response",
input: "`3d6`: `(5+1+4)` = **10**",
wantData: &NamedRollInput{
Expression: "3d6",
},
},
{
name: "roll response",
input: "`3d6` _fire damage_: `(5+1+4)` = **10**",
wantData: &NamedRollInput{
Expression: "3d6",
Label: "fire damage",
},
},
{
name: "roll response; bad",
input: "`3d6 *` _weird_: `(5+1+4)` = **10**",
wantData: &NamedRollInput{
Expression: "3d6 *",
Label: "weird",
},
},
{
name: "formatted message",
input: "roll `3d6 +2` bludgeoning",
wantData: &NamedRollInput{
Expression: "3d6 +2",
},
},
{
name: "formatted message",
input: "`3d6 +2` damage `bogus`",
wantData: &NamedRollInput{
Expression: "3d6 +2",
},
},
{
name: "math",
input: "what's `3+5*8`",
wantData: &NamedRollInput{
Expression: "3+5*8",
},
},
{
name: "response",
input: "<!@12345654> rolled `3+5*8`: nonsense",
wantData: &NamedRollInput{
Expression: "3+5*8",
},
},
{
name: "serialized roll input",
input: "3d6|fire damage",
wantData: &NamedRollInput{
Expression: "3d6",
Label: "fire damage",
},
},
{
name: "old prefix",
input: "/roll 3d6",
wantData: &NamedRollInput{
Expression: "3d6",
},
},
{
name: "empty label",
input: "3d6 # ",
wantData: &NamedRollInput{
Expression: "3d6",
},
},
{
name: "label with mention",
input: "3d6 # @trav#1234 test",
wantData: &NamedRollInput{
Expression: "3d6",
Label: "@trav#1234 test",
},
},
// {
// name: "formatted message; broken",
// input: "roll `3d6 bludgeoning",
// wantData: &NamedRollInput{},
// },
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if gotData := NewRollInputFromString(tt.input); !reflect.DeepEqual(gotData, tt.wantData) {
t.Errorf("NewRollInputFromString() = %+v, want %+v", gotData, tt.wantData)
}
})
}
}
func Test_splitMultirollString(t *testing.T) {
type args struct {
s string
}
tests := []struct {
name string
arg string
want []string
}{
{
name: "basic",
arg: "foo ; bar",
want: []string{"foo ", " bar"},
},
{
name: "single",
arg: "foo",
want: []string{"foo"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := splitMultirollString(tt.arg); !reflect.DeepEqual(got, tt.want) {
t.Errorf("splitMultirollString() = %v, want %v", got, tt.want)
}
})
}
}