|
| 1 | +package cli |
| 2 | + |
| 3 | +import ( |
| 4 | + "strings" |
| 5 | + "testing" |
| 6 | + |
| 7 | + cmds "github.com/ipfs/go-ipfs/commands" |
| 8 | +) |
| 9 | + |
| 10 | +func TestSynopsisGenerator(t *testing.T) { |
| 11 | + command := &cmds.Command{ |
| 12 | + Arguments: []cmds.Argument{ |
| 13 | + cmds.StringArg("required", true, false, ""), |
| 14 | + cmds.StringArg("variadic", false, true, ""), |
| 15 | + }, |
| 16 | + Options: []cmds.Option{ |
| 17 | + cmds.StringOption("opt", "o", "Option"), |
| 18 | + }, |
| 19 | + Helptext: cmds.HelpText{ |
| 20 | + SynopsisOptionsValues: map[string]string{ |
| 21 | + "opt": "OPTION", |
| 22 | + }, |
| 23 | + }, |
| 24 | + } |
| 25 | + syn := generateSynopsis(command, "cmd") |
| 26 | + t.Logf("Synopsis is: %s", syn) |
| 27 | + if !strings.HasPrefix(syn, "cmd ") { |
| 28 | + t.Fatal("Synopsis should start with command name") |
| 29 | + } |
| 30 | + if !strings.Contains(syn, "[--opt=<OPTION> | -o]") { |
| 31 | + t.Fatal("Synopsis should contain option descriptor") |
| 32 | + } |
| 33 | + if !strings.Contains(syn, "<required>") { |
| 34 | + t.Fatal("Synopsis should contain required argument") |
| 35 | + } |
| 36 | + if !strings.Contains(syn, "<variadic>...") { |
| 37 | + t.Fatal("Synopsis should contain variadic argument") |
| 38 | + } |
| 39 | + if !strings.Contains(syn, "[<variadic>...]") { |
| 40 | + t.Fatal("Synopsis should contain optional argument") |
| 41 | + } |
| 42 | + if !strings.Contains(syn, "[--]") { |
| 43 | + t.Fatal("Synopsis should contain options finalizer") |
| 44 | + } |
| 45 | +} |
0 commit comments