Created
June 19, 2015 17:35
-
-
Save mboersma/da23ab40c860552b8dab to your computer and use it in GitHub Desktop.
Part of docopt_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestDocopt(t *testing.T) { | |
doc := `Usage: prog [-v] A | |
Options: -v Be verbose.` | |
if v, err := Parse(doc, []string{"arg"}, true, "", false, false); reflect.DeepEqual(v, map[string]interface{}{"-v": false, "A": "arg"}) != true { | |
t.Error(err) | |
} | |
if v, err := Parse(doc, []string{"-v", "arg"}, true, "", false, false); reflect.DeepEqual(v, map[string]interface{}{"-v": true, "A": "arg"}) != true { | |
t.Error(err) | |
} | |
doc = `Usage: prog [-vqr] [FILE] | |
prog INPUT OUTPUT | |
prog --help | |
Options: | |
-v print status messages | |
-q report only file names | |
-r show all occurrences of the same error | |
--help | |
` | |
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 { | |
t.Error(err) | |
} | |
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 { | |
t.Error(err) | |
} | |
_, err := Parse(doc, []string{"-v", "input.py", "output.py"}, true, "", false, false) // does not match | |
if _, ok := err.(*UserError); !ok { | |
t.Error(err) | |
} | |
_, err = Parse(doc, []string{"--fake"}, true, "", false, false) | |
if _, ok := err.(*UserError); !ok { | |
t.Error(err) | |
} | |
_, output, err := parseOutput(doc, []string{"--hel"}, true, "", false) | |
if err != nil || len(output) == 0 { | |
t.Error(err) | |
} | |
doc = ` | |
Registers a new user with a Deis controller. | |
Usage: deis auth:register <controller> [options] | |
Arguments: | |
<controller> | |
fully-qualified controller URI, e.g. 'http://deis.local3.deisapp.com/'' | |
Options: | |
--username=<username> | |
provide a username for the new account. | |
--password=<password> | |
provide a password for the new account. | |
--email=<email> | |
provide an email address. | |
--ssl-verify=false | |
disables SSL certificate verification for API requests | |
` | |
if _, err := Parse(doc, []string{}, true, "", false, false); err != nil { | |
t.Error(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment