-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser_test.go
378 lines (371 loc) · 10.4 KB
/
parser_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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
package main
import (
"database/sql"
"encoding/xml"
"reflect"
"testing"
_ "github.com/lib/pq"
)
func TestXMLSpell_ToDbSpell(t *testing.T) {
type fields struct {
XMLName xml.Name
Name string
Level string
School string
Ritual string
Time string
Range string
Components string
Duration string
Classes string
Texts []string
}
tests := []struct {
name string
fields fields
want Spell
wantErr bool
}{
{
"Zone of truth. Should work.",
fields{
Name: "Zone of Truth",
Level: "2",
School: "EN",
Ritual: "",
Time: "1 action",
Range: "60 feet",
Components: "V, S, M",
Duration: "10 minutes",
Classes: "Bard, Cleric, Paladin, Paladin (Devotion), Paladin (Crown)",
Texts: []string{"You create a magical zone that guards against deception in a 15-foot-radius sphere centered on a point of your choice within range. Until the spell ends, a creature that enters the spell's area for the first time on a turn or starts its turn there must make a Charisma saving throw. On a failed save, a creature can't speak a deliberate lie while in the radius. You know whether each creature succeeds or fails on its saving throw.",
"",
"An affected creature is aware of the spell and can thus avoid answering questions to which it would normally respond with a lie. Such creatures can be evasive in its answers as long as it remains within the boundaries of the truth.",
},
},
Spell{
Name: "Zone of Truth",
Level: "2",
School: "Enchantment",
CastTime: "1 action",
Duration: "10 minutes",
Range: "60 feet",
Verbal: true,
Somatic: true,
Material: true,
MaterialDesc: sql.NullString{
String: "",
Valid: false,
},
Concentration: false,
Ritual: false,
Description: "You create a magical zone that guards against deception in a 15-foot-radius sphere centered on a point of your choice within range. Until the spell ends, a creature that enters the spell's area for the first time on a turn or starts its turn there must make a Charisma saving throw. On a failed save, a creature can't speak a deliberate lie while in the radius. You know whether each creature succeeds or fails on its saving throw.\n\nAn affected creature is aware of the spell and can thus avoid answering questions to which it would normally respond with a lie. Such creatures can be evasive in its answers as long as it remains within the boundaries of the truth.",
SourceID: PHBid,
},
false,
},
{
"Absorb Elements. Should be EE.",
fields{
Name: "Absorb Elements (EE)",
Level: "1",
School: "A",
Ritual: "",
Time: "1 reaction, which you take when you take acid, cold, fire, lightning, or thunder damage",
Range: "",
Components: "S",
Duration: "1 round",
Classes: "Druid, Ranger, Wizard, Fighter (Eldritch Knight)",
Texts: []string{"The spell captures some of the incoming energy, lessening its effect on you and storing it for your next melee attack. You have resistance to the triggering damage type until the start of your next turn. Also, the first time you hit with a melee attack on your next turn, the target takes an extra 1d6 damage of the triggering type, and the spell ends.",
"",
"At Higher Levels: When you cast this spell using a spell slot of 2nd level or higher, the extra damage increases by 1d6 for each slot level above 1st.",
"",
"This spell can be found in the Elemental Evil Player's Companion",
},
},
Spell{
Name: "Absorb Elements",
Level: "1",
School: "Abjuration",
CastTime: "1 reaction, which you take when you take acid, cold, fire, lightning, or thunder damage",
Duration: "1 round",
Range: "",
Verbal: false,
Somatic: true,
Material: false,
MaterialDesc: sql.NullString{
String: "",
Valid: false,
},
Concentration: false,
Ritual: false,
Description: "The spell captures some of the incoming energy, lessening its effect on you and storing it for your next melee attack. You have resistance to the triggering damage type until the start of your next turn. Also, the first time you hit with a melee attack on your next turn, the target takes an extra 1d6 damage of the triggering type, and the spell ends.\n\nAt Higher Levels: When you cast this spell using a spell slot of 2nd level or higher, the extra damage increases by 1d6 for each slot level above 1st.\n\nThis spell can be found in the Elemental Evil Player's Companion",
SourceID: EEid,
},
false,
},
}
for _, tt := range tests {
x := XMLSpell{
Name: tt.fields.Name,
Level: tt.fields.Level,
School: tt.fields.School,
Ritual: tt.fields.Ritual,
Time: tt.fields.Time,
Range: tt.fields.Range,
Components: tt.fields.Components,
Duration: tt.fields.Duration,
Classes: tt.fields.Classes,
Texts: tt.fields.Texts,
}
got, err := x.ToDbSpell()
if (err != nil) != tt.wantErr {
t.Errorf("%q. XMLSpell.ToDbSpell() error = %v, wantErr %v", tt.name, err, tt.wantErr)
continue
}
if !reflect.DeepEqual(got, tt.want) {
// spew.Dump(got, tt.want)
t.Errorf("%q. XMLSpell.ToDbSpell() = %v, want %v", tt.name, got, tt.want)
}
}
}
func TestXMLSpell_ParseClasses(t *testing.T) {
type fields struct {
Name string
Level string
School string
Ritual string
Time string
Range string
Components string
Duration string
Classes string
Texts []string
}
tests := []struct {
name string
fields fields
want []Class
want1 bool
}{
{
"3 classes",
fields{
Classes: "Cleric, Cleric (Arcana), Druid",
},
[]Class{
Class{
ID: 2,
Name: "Cleric",
BaseClass: sql.NullInt64{
Int64: 0,
Valid: false,
},
},
Class{
ID: 3,
Name: "Cleric (Arcana)",
BaseClass: sql.NullInt64{
Int64: 2,
Valid: true,
},
},
Class{
ID: 12,
Name: "Druid",
BaseClass: sql.NullInt64{
Int64: 0,
Valid: false,
},
},
},
true,
},
{
"No classes",
fields{},
[]Class{},
false,
},
{
"One class",
fields{
Classes: "Bard",
},
[]Class{
Class{
ID: 1,
Name: "Bard",
BaseClass: sql.NullInt64{
Int64: 0,
Valid: false,
},
},
},
true,
},
{
"Absorb Elements (EE)",
fields{
Classes: "Druid, Ranger, Wizard, Fighter (Eldritch Knight)",
},
[]Class{
Class{
ID: 12,
Name: "Druid",
BaseClass: sql.NullInt64{
Int64: 0,
Valid: false,
},
},
Class{
ID: 27,
Name: "Ranger",
BaseClass: sql.NullInt64{
Int64: 0,
Valid: false,
},
},
Class{
ID: 34,
Name: "Wizard",
BaseClass: sql.NullInt64{
Int64: 0,
Valid: false,
},
},
Class{
ID: 36,
Name: "Fighter (Eldritch Knight)",
BaseClass: sql.NullInt64{
Int64: 35,
Valid: true,
},
},
},
true,
},
}
for _, tt := range tests {
x := &XMLSpell{
Name: tt.fields.Name,
Level: tt.fields.Level,
School: tt.fields.School,
Ritual: tt.fields.Ritual,
Time: tt.fields.Time,
Range: tt.fields.Range,
Components: tt.fields.Components,
Duration: tt.fields.Duration,
Classes: tt.fields.Classes,
Texts: tt.fields.Texts,
}
got, got1 := x.ParseClasses()
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("%q. XMLSpell.ParseClasses() got = %v, want %v", tt.name, got, tt.want)
}
if got1 != tt.want1 {
t.Errorf("%q. XMLSpell.ParseClasses() got1 = %v, want %v", tt.name, got1, tt.want1)
}
}
}
func TestXMLSpell_parseComponents(t *testing.T) {
type fields struct {
Name string
Level string
School string
Ritual string
Time string
Range string
Components string
Duration string
Classes string
Texts []string
}
tests := []struct {
name string
fields fields
want components
}{
{
"V",
fields{Components: "V"},
components{Verb: true, Som: false, Mat: false, Matdesc: sql.NullString{
String: "",
Valid: false},
},
},
{
"V, S",
fields{Components: "V, S"},
components{Verb: true, Som: true, Mat: false, Matdesc: sql.NullString{
String: "",
Valid: false},
},
},
{
"V, S, M",
fields{Components: "V, S, M"},
components{Verb: true, Som: true, Mat: true, Matdesc: sql.NullString{
String: "",
Valid: false},
},
},
{
"V, S, M (text)",
fields{Components: "V, S, M (a jade circlet worth at least 1,500 gp, which you must place on your head before you cast the spell)"},
components{Verb: true, Som: true, Mat: true, Matdesc: sql.NullString{
String: "A jade circlet worth at least 1,500 gp, which you must place on your head before you cast the spell",
Valid: true},
},
},
{
"S",
fields{Components: "S"},
components{Verb: false, Som: true, Mat: false, Matdesc: sql.NullString{
String: "",
Valid: false},
},
},
{
"V, M (text)",
fields{Components: "V, M (bat fur and a drop of pitch or piece of coal)"},
components{Verb: true, Som: false, Mat: true, Matdesc: sql.NullString{
String: "Bat fur and a drop of pitch or piece of coal",
Valid: true},
},
},
{
"S, M",
fields{Components: "S, M"},
components{Verb: false, Som: true, Mat: true, Matdesc: sql.NullString{
String: "",
Valid: false},
},
},
{
"S, M (text)",
fields{Components: "S, M (a glowing stick of incense or a crystal vial filled with phosphorescent material)"},
components{Verb: false, Som: true, Mat: true, Matdesc: sql.NullString{
String: "A glowing stick of incense or a crystal vial filled with phosphorescent material",
Valid: true},
},
},
}
for _, tt := range tests {
x := &XMLSpell{
Name: tt.fields.Name,
Level: tt.fields.Level,
School: tt.fields.School,
Ritual: tt.fields.Ritual,
Time: tt.fields.Time,
Range: tt.fields.Range,
Components: tt.fields.Components,
Duration: tt.fields.Duration,
Classes: tt.fields.Classes,
Texts: tt.fields.Texts,
}
if got := x.parseComponents(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("%q. XMLSpell.parseComponents() = %v, want %v", tt.name, got, tt.want)
}
}
}