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
|
package validate
import "testing"
func TestValidateMobAttackTypes(t *testing.T) {
cases := []struct {
name string
types []string
wantError bool
}{
{"single melee", []string{"crush"}, false},
{"melee plus ranged", []string{"stab", "ranged"}, false},
{"melee plus both", []string{"slash", "ranged", "science"}, false},
{"empty", nil, true},
{"no melee", []string{"ranged"}, true},
{"two melee", []string{"stab", "crush"}, true},
{"invalid entry", []string{"crush", "magic"}, true},
{"duplicate", []string{"crush", "ranged", "ranged"}, true},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
issues := validateMobAttackTypes("test_mob", c.types)
if c.wantError && len(issues) == 0 {
t.Errorf("validateMobAttackTypes(%v): expected error, got none", c.types)
}
if !c.wantError && len(issues) != 0 {
t.Errorf("validateMobAttackTypes(%v): expected no error, got %v", c.types, issues)
}
})
}
}
|