MCPcopy Create free account
hub / github.com/docopt/docopt.go / TestDocopt

Function TestDocopt

docopt_test.go:1139–1180  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1137}
1138
1139func TestDocopt(t *testing.T) {
1140 doc := `Usage: prog [-v] A
1141
1142 Options: -v Be verbose.`
1143 if v, err := Parse(doc, []string{"arg"}, true, "", false, false); reflect.DeepEqual(v, map[string]interface{}{"-v": false, "A": "arg"}) != true {
1144 t.Error(err)
1145 }
1146 if v, err := Parse(doc, []string{"-v", "arg"}, true, "", false, false); reflect.DeepEqual(v, map[string]interface{}{"-v": true, "A": "arg"}) != true {
1147 t.Error(err)
1148 }
1149
1150 doc = `Usage: prog [-vqr] [FILE]
1151 prog INPUT OUTPUT
1152 prog --help
1153
1154 Options:
1155 -v print status messages
1156 -q report only file names
1157 -r show all occurrences of the same error
1158 --help
1159
1160 `
1161 if v, err := Parse(doc, []string{"-v", "file.py"}, true, "", false, false); reflect.DeepEqual(v, map[string]interface{}{"-v": true, "-q": false, "-r": false, "--help": false, "FILE": "file.py", "INPUT": nil, "OUTPUT": nil}) != true {
1162 t.Error(err)
1163 }
1164 if v, err := Parse(doc, []string{"-v"}, true, "", false, false); reflect.DeepEqual(v, map[string]interface{}{"-v": true, "-q": false, "-r": false, "--help": false, "FILE": nil, "INPUT": nil, "OUTPUT": nil}) != true {
1165 t.Error(err)
1166 }
1167
1168 _, err := Parse(doc, []string{"-v", "input.py", "output.py"}, true, "", false, false) // does not match
1169 if _, ok := err.(*UserError); !ok {
1170 t.Error(err)
1171 }
1172 _, err = Parse(doc, []string{"--fake"}, true, "", false, false)
1173 if _, ok := err.(*UserError); !ok {
1174 t.Error(err)
1175 }
1176 _, output, err := parseOutput(doc, []string{"--hel"}, true, "", false)
1177 if err != nil || len(output) == 0 {
1178 t.Error(err)
1179 }
1180}
1181
1182func TestLanguageErrors(t *testing.T) {
1183 _, err := Parse("no usage with colon here", []string{}, true, "", false, false)

Callers

nothing calls this directly

Calls 3

ParseFunction · 0.85
parseOutputFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected