-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_test.go
More file actions
36 lines (28 loc) · 882 Bytes
/
command_test.go
File metadata and controls
36 lines (28 loc) · 882 Bytes
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
// SPDX-FileCopyrightText: 2019-2024 caixw
//
// SPDX-License-Identifier: MIT
package cmdopt
import (
"flag"
"io"
"os"
"testing"
"github.com/issue9/assert/v4"
)
func TestCmdOpt_Commands(t *testing.T) {
a := assert.New(t, false)
opt := New(os.Stdout, flag.ExitOnError, "usage\nusage", nil, func(s string) string { return "not found " + s })
a.NotNil(opt)
a.Length(opt.Commands(), 0)
_, _, found := opt.Command("cmd")
a.False(found)
opt.New("c1", "c1 title", "c1 usage", func(fs *flag.FlagSet) DoFunc { return func(io.Writer) error { return nil } })
opt.New("c2", "c2 title", "c2 usage", func(fs *flag.FlagSet) DoFunc { return func(io.Writer) error { return nil } })
a.Length(opt.Commands(), 2)
_, _, found = opt.Command("cmd")
a.False(found)
title, usage, found := opt.Command("c1")
a.True(found).
Equal(title, "c1 title").
Equal(usage, "c1 usage\n")
}