1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-07-01 10:49:24 +08:00

commands/cli: Added test for single-dash option value

This commit is contained in:
Matt Bell
2014-10-14 15:16:18 -07:00
committed by Juan Batiz-Benet
parent 66e6da3ddd
commit 5d9fa93c85

View File

@ -8,10 +8,14 @@ import (
) )
func TestOptionParsing(t *testing.T) { func TestOptionParsing(t *testing.T) {
cmd := &commands.Command{} cmd := &commands.Command{
Options: []commands.Option{
commands.Option{ []string{"b"}, commands.String },
},
}
cmd.Register("test", &commands.Command{}) cmd.Register("test", &commands.Command{})
opts, input, err := parseOptions([]string{ "--beep", "--boop=\"5", "lol\"", "test2", "-cV" }, opts, input, err := parseOptions([]string{ "--beep", "--boop=\"5", "lol\"", "test2", "-cVb", "beep" },
[]string{"test"}, cmd) []string{"test"}, cmd)
/*for k, v := range opts { /*for k, v := range opts {
fmt.Printf("%s: %s\n", k, v) fmt.Printf("%s: %s\n", k, v)
@ -20,7 +24,7 @@ func TestOptionParsing(t *testing.T) {
if err != nil { if err != nil {
t.Error("Should have passed") t.Error("Should have passed")
} }
if len(opts) != 4 || opts["c"] != "" || opts["V"] != "" || opts["beep"] != "" || opts["boop"] != "5 lol" { if len(opts) != 5 || opts["c"] != "" || opts["V"] != "" || opts["beep"] != "" || opts["boop"] != "5 lol" || opts["b"] != "beep" {
t.Error("Returned options were defferent than expected: %v", opts) t.Error("Returned options were defferent than expected: %v", opts)
} }
if len(input) != 1 || input[0] != "test2" { if len(input) != 1 || input[0] != "test2" {