add fix for uppercase testing
previously it would only match a string that was only uppercase characters.
this fix allows a string to have non-uppercasable characters as long as
there is at least one uppercase character
a simple testcase has also been added
diff --git a/docopt.go b/docopt.go
index 77c52ab..2932a38 100644
--- a/docopt.go
+++ b/docopt.go
@@ -1203,11 +1203,16 @@
return split[0], sep, split[1]
}
+// returns true if all cased characters in the string are uppercase
+// and there are there is at least one cased charcter
func isStringUppercase(s string) bool {
- for _, c := range s {
- if !unicode.IsUpper(c) {
- return false
- }
- }
- return true
+ if strings.ToUpper(s) != s {
+ return false
+ }
+ for _, c := range []rune(s) {
+ if unicode.IsUpper(c) {
+ return true
+ }
+ }
+ return false
}
diff --git a/docopt_test.go b/docopt_test.go
index 5f21d07..848ee02 100644
--- a/docopt_test.go
+++ b/docopt_test.go
@@ -1424,6 +1424,33 @@
}
}
+func TestFileTestcasesGo(t *testing.T) {
+ filename := "test_golang.docopt"
+ file, err := os.Open(filename)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer file.Close()
+
+ for c := range parseTest(file) {
+ if c.err != nil {
+ t.Fatal(err)
+ break
+ }
+ result, _, err := Parse(c.doc, c.argv, true, "", false)
+ if _, ok := err.(*UserError); c.userError && !ok {
+ // expected a user-error
+ t.Error("testcase:", c.id, "result:", result)
+ } else if _, ok := err.(*UserError); !c.userError && ok {
+ // unexpected user-error
+ t.Error("testcase:", c.id, "error:", err, "result:", result)
+ } else if reflect.DeepEqual(c.expect, result) != true {
+ t.Error("testcase:", c.id, "result:", result)
+ }
+ }
+}
+
+
type testcase struct {
id int
doc string
diff --git a/test_golang.docopt b/test_golang.docopt
new file mode 100644
index 0000000..323fd67
--- /dev/null
+++ b/test_golang.docopt
@@ -0,0 +1,9 @@
+r"""usage: prog [NAME_-2]..."""
+$ prog 10 20
+{"NAME_-2": ["10", "20"]}
+
+$ prog 10
+{"NAME_-2": ["10"]}
+
+$ prog
+{"NAME_-2": []}