-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes_test.go
More file actions
94 lines (92 loc) · 1.75 KB
/
Copy pathtypes_test.go
File metadata and controls
94 lines (92 loc) · 1.75 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
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
package ted
import (
"testing"
)
func TestMessage_CommandAndArgs(t *testing.T) {
tests := []struct {
name string
message Message
wantCommand string
wantArgs string
}{
{
name: "removes leading slash from command",
message: Message{
Text: "/eta",
Entities: []MessageEntity{
{
Type: "bot_command",
Offset: 0,
Length: 4,
},
},
},
wantCommand: "eta",
wantArgs: "",
},
{
name: "trims whitespace from args",
message: Message{
Text: "/cmd hello",
Entities: []MessageEntity{
{
Type: "bot_command",
Offset: 0,
Length: 4,
},
},
},
wantCommand: "cmd",
wantArgs: "hello",
},
{
name: "removes bot mention from command",
message: Message{
Text: "/cmd@username args",
Entities: []MessageEntity{
{
Type: "bot_command",
Offset: 0,
Length: 13,
},
},
},
wantCommand: "cmd",
wantArgs: "args",
},
{
name: "returns message text as args when command not present",
message: Message{
Text: "args",
},
wantCommand: "",
wantArgs: "args",
},
{
name: "ignores command not at beginning of message",
message: Message{
Text: "Try this command: /cmd",
Entities: []MessageEntity{
{
Type: "bot_command",
Offset: 18,
Length: 4,
},
},
},
wantCommand: "",
wantArgs: "Try this command: /cmd",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
command, args := tt.message.CommandAndArgs()
if command != tt.wantCommand {
t.Fatalf("command: want %q, got %q", tt.wantCommand, command)
}
if args != tt.wantArgs {
t.Fatalf("args: want %q, got %q", tt.wantCommand, args)
}
})
}
}