From: Edgar HIPP Date: Sun, 30 Aug 2015 15:06:58 +0000 (+0200) Subject: Add tests for file surrounded by `()` X-Git-Url: http://www.git.stargrave.org/?p=path-extractor.git;a=commitdiff_plain;h=1a5d2ca40a560195479e3b5e1491331bff16f7d6 Add tests for file surrounded by `()` --- diff --git a/extractor.go b/extractor.go index d42bf0e..6a87ab4 100644 --- a/extractor.go +++ b/extractor.go @@ -3,8 +3,8 @@ package pathextractor import "regexp" func pathExtractor(input string) [][][]byte { - surroundRegex := "[^][ \\t:'\"]" - r := regexp.MustCompile("(" + surroundRegex + "*[\\./]" + surroundRegex + "*)") + surroundRegex := "[^][ \\t:'\"]*" + r := regexp.MustCompile("(" + surroundRegex + "[\\./]" + surroundRegex + ")") temp := [][][]byte{} temp = r.FindAllSubmatch([]byte(input), -1) return temp diff --git a/pe_test.go b/pe_test.go index 58c138f..844a0e5 100644 --- a/pe_test.go +++ b/pe_test.go @@ -73,6 +73,16 @@ func TestGitIgnore(t *testing.T) { t.Errorf("Doesnt match multi", output) } + output = GetAllMatches("user.test.js") + if len(output) != 1 { + t.Errorf("Doesnt match multiple extensions", output) + } + + output = GetAllMatches("(user.js)") + if len(output) != 1 { + t.Errorf("Doesnt match surrounded by parens", output) + } + output = GetAllMatches("var/") if len(output) != 1 { t.Errorf("Doesnt match dir", output) diff --git a/validators.go b/validators.go index b0501d6..adc8116 100644 --- a/validators.go +++ b/validators.go @@ -67,7 +67,7 @@ func endsWithInvalidString(input string) bool { } func containsInvalidString(input string) bool { - invalidStrings := []string{"(", ")", "and/or", "origin/", "{", "}", "<", ">", "$", "*", "this."} + invalidStrings := []string{"()", "and/or", "origin/", "{", "}", "<", ">", "$", "*", "this."} for _, s := range invalidStrings { if strings.Contains(input, s) { return true