-
Notifications
You must be signed in to change notification settings - Fork 0
/
context_test.go
38 lines (33 loc) · 959 Bytes
/
context_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
package subcmd
import (
"context"
"testing"
)
func TestSubcmdPairs(t *testing.T) {
ctx := context.Background()
got := subcmdPairList(ctx)
if len(got) != 0 {
t.Errorf("got %d subcmd pair(s), want 0", len(got))
}
subcmd1 := Subcmd{Desc: "foo"}
ctx = addSubcmdPair(ctx, "foo", subcmd1)
got = subcmdPairList(ctx)
if len(got) != 1 {
t.Errorf("got %d subcmd pair(s), want 1", len(got))
} else if got[0].subcmd.Desc != "foo" {
t.Errorf(`got subcmd pair with description "%s", want "foo"`, got[0].subcmd.Desc)
}
subcmd2 := Subcmd{Desc: "bar"}
ctx = addSubcmdPair(ctx, "bar", subcmd2)
got = subcmdPairList(ctx)
if len(got) != 2 {
t.Errorf("got %d subcmd pair(s), want 2", len(got))
} else {
if got[0].subcmd.Desc != "foo" {
t.Errorf(`subcmd pair 0 has description "%s", want "foo"`, got[0].subcmd.Desc)
}
if got[1].subcmd.Desc != "bar" {
t.Errorf(`subcmd pair 1 has description "%s", want "var"`, got[1].subcmd.Desc)
}
}
}