|
1
|
package scroll_test |
|
2
|
|
|
3
|
import ( |
|
4
|
"strings" |
|
5
|
"testing" |
|
6
|
|
|
7
|
"github.com/conflicthq/scuttlebot/internal/bots/scroll" |
|
8
|
) |
|
9
|
|
|
10
|
func TestParseCommand(t *testing.T) { |
|
11
|
cases := []struct { |
|
12
|
name string |
|
13
|
input string |
|
14
|
wantCh string |
|
15
|
wantLim int |
|
16
|
wantErr bool |
|
17
|
}{ |
|
18
|
{"basic", "replay #fleet", "#fleet", 50, false}, |
|
19
|
{"with last", "replay #fleet last=100", "#fleet", 100, false}, |
|
20
|
{"last capped at max", "replay #fleet last=9999", "#fleet", 500, false}, |
|
21
|
{"missing channel", "replay", "", 0, true}, |
|
22
|
{"no hash", "replay fleet", "", 0, true}, |
|
23
|
{"unknown command", "history #fleet", "", 0, true}, |
|
24
|
{"invalid last", "replay #fleet last=abc", "", 0, true}, |
|
25
|
{"unknown arg", "replay #fleet foo=bar", "", 0, true}, |
|
26
|
} |
|
27
|
|
|
28
|
for _, tc := range cases { |
|
29
|
t.Run(tc.name, func(t *testing.T) { |
|
30
|
req, err := scroll.ParseCommand(tc.input) |
|
31
|
if tc.wantErr { |
|
32
|
if err == nil { |
|
33
|
t.Errorf("ParseCommand(%q): expected error, got nil", tc.input) |
|
34
|
} |
|
35
|
return |
|
36
|
} |
|
37
|
if err != nil { |
|
38
|
t.Fatalf("ParseCommand(%q): unexpected error: %v", tc.input, err) |
|
39
|
} |
|
40
|
if req.Channel != tc.wantCh { |
|
41
|
t.Errorf("Channel: got %q, want %q", req.Channel, tc.wantCh) |
|
42
|
} |
|
43
|
if req.Limit != tc.wantLim { |
|
44
|
t.Errorf("Limit: got %d, want %d", req.Limit, tc.wantLim) |
|
45
|
} |
|
46
|
}) |
|
47
|
} |
|
48
|
} |
|
49
|
|
|
50
|
func TestParseCommandCaseInsensitive(t *testing.T) { |
|
51
|
req, err := scroll.ParseCommand("REPLAY #fleet last=10") |
|
52
|
if err != nil { |
|
53
|
t.Fatalf("ParseCommand: %v", err) |
|
54
|
} |
|
55
|
if req.Channel != "#fleet" { |
|
56
|
t.Errorf("Channel: got %q", req.Channel) |
|
57
|
} |
|
58
|
_ = strings.ToLower // just confirming case insensitivity is tested |
|
59
|
} |
|
60
|
|