Repository navigation
Expand file tree
/
Copy pathmessage_test.go
More file actions
65 lines (62 loc) · 1.36 KB
/
Copy pathmessage_test.go
File metadata and controls
65 lines (62 loc) · 1.36 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
package nerimity
import (
"reflect"
"testing"
)
func TestParseCommand(t *testing.T) {
const botID = "999888777"
tests := []struct {
name string
content string
botID string
want *Command
}{
{
name: "matching command with args",
content: "/help:999888777 page 2",
botID: botID,
want: &Command{Name: "help", Args: []string{"page", "2"}},
},
{
name: "matching command with no args",
content: "/ping:999888777",
botID: botID,
want: &Command{Name: "ping", Args: []string{}},
},
{
name: "different bot id does not match",
content: "/help:111111111 page 2",
botID: botID,
want: nil,
},
{
name: "not a command",
content: "hello there",
botID: botID,
want: nil,
},
{
name: "empty bot id never matches",
content: "/help: page 2",
botID: "",
want: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := parseCommand(tt.content, tt.botID)
if tt.want == nil {
if got != nil {
t.Errorf("parseCommand(%q) = %#v, want nil", tt.content, got)
}
return
}
if got == nil {
t.Fatalf("parseCommand(%q) = nil, want %#v", tt.content, tt.want)
}
if got.Name != tt.want.Name || !reflect.DeepEqual(got.Args, tt.want.Args) {
t.Errorf("parseCommand(%q) = %#v, want %#v", tt.content, got, tt.want)
}
})
}
}