forked from MemeLabs/modbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands_test.go
49 lines (43 loc) · 1.02 KB
/
commands_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
package main
import (
"fmt"
"testing"
)
func TestParseModifiers(t *testing.T) {
// correct modifiers
s1 := []string{"nsfw", "hidden"}
result, err := parseModifiers(s1)
if err != nil || result.Hidden != "true" || result.Nsfw != "true" {
t.Error("Error in modifier s1")
}
// wrong modifier
s2 := []string{"nsfw", "hide"}
result, err = parseModifiers(s2)
if err == nil {
t.Error("Error in modifier s2")
}
// fmt.Println(err.Error())
}
func TestComputeRoll(t *testing.T) {
testInputs := [11]string{
"!roll 2d2+100 foo biz baz",
"!roll 2d2 + 100",
"!roll 2d2 +100",
"!roll 2d2+ 100",
"!roll 2d2-100",
"!roll 2d2 - 100",
"!roll 2d2 -100",
"!roll 2d2- 100",
"!roll 2d2- 100 foo biz baz",
"!roll 23904823904823904823490d20 +1",
"!roll 2d20"}
for _, input := range testInputs {
result, err := computeRoll(input)
errorMessage := fmt.Sprintf("%v", err)
if err != nil {
if errorMessage != "Sides, count or modifier too large" {
t.Error(fmt.Sprintf("Error: %v\n %d", err, result))
}
}
}
}