-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprefix_test.go
46 lines (38 loc) · 987 Bytes
/
prefix_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
package arg
import (
"testing"
)
func TestPrefix(t *testing.T) {
pfxStr := "box user -t "
pfx := newPrefix(pfxStr)
if pfx.count != 3 {
t.Errorf("The prefix count should be 3 and not %v", pfx.count)
}
if pfx.str != "box user -t" {
t.Errorf("Incorrect str(%v)", pfx.str)
}
if pfx.len != len("box user -t") {
t.Errorf("Incorrect length %v", pfx.len)
}
pfx2 := newPrefix(pfxStr)
if !pfx.equal(pfx2) {
t.Errorf("Prefixes should be equal")
}
if pfx.equal(newPrefix("a b")) {
t.Errorf("Prefixes should not be equal")
}
if pfx.equal(newPrefix("box user -tt ")) {
t.Errorf("Prefixes should not be equal")
}
if pfx.equal(newPrefix("box user -x ")) {
t.Errorf("Prefixes should not be equal")
}
pfx.addCmd(&Cmd{Prefix: pfxStr, Name: "cmd", Description: "cmd"})
cmd, ok := pfx.getCmd("cmd")
if !ok {
t.Errorf("Prefix should have a command named cmd")
}
if cmd.Name != "cmd" || cmd.Description != "cmd" {
t.Errorf("Prefix has wrong command")
}
}