Skip to content

Commit

Permalink
add fix for uppercase testing
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kbatten committed Aug 30, 2013
1 parent 09700dc commit 31e3220
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
17 changes: 11 additions & 6 deletions docopt.go
Expand Up @@ -1203,11 +1203,16 @@ func stringPartition(s, sep string) (string, string, string) {
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
}
27 changes: 27 additions & 0 deletions docopt_test.go
Expand Up @@ -1424,6 +1424,33 @@ func TestFileTestcases(t *testing.T) {
}
}

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
Expand Down
9 changes: 9 additions & 0 deletions 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": []}

0 comments on commit 31e3220

Please sign in to comment.