Add Synopsis generator test
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
Jakub Sztandera committed
Jun 1, 2016 at 21:39 UTC
6cafb46584cc88319ab422baaa5ad68fa27ca10a
1 file changed
+45
commands/cli/helptext_test.go
new
+45
@@ -0,0 +1,45 @@
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
+}