extractor.go | 3 ++- path-extractor/pe.go | 2 +- pe_test.go | 68 +++++++++++++++++++++++++++--------------------------- diff --git a/extractor.go b/extractor.go index c19b7d5cae73c091b2f8e4599b17cd98461cd7aa..e05ad4b93b50730c149315f98b68ec5655ba9fa7 100644 --- a/extractor.go +++ b/extractor.go @@ -29,7 +29,8 @@ input = stripParens(input) return input } -func GetAllMatches(input string, options MatchOptions) []string { +func GetAllMatches(input string, format string) []string { + options := MatchOptions{format: format} result := []string{} candidatePath := string("") restOfLine := string("") diff --git a/path-extractor/pe.go b/path-extractor/pe.go index 6bb4fa3e253d48a372ef753352ddfee0655354dd..5b5d8d35b7d0d1ce67c7561f7da00b998bca3a98 100644 --- a/path-extractor/pe.go +++ b/path-extractor/pe.go @@ -12,7 +12,7 @@ func main() { stdin := os.Stdin if scanner := bufio.NewScanner(stdin); scanner != nil { for scanner.Scan() { - matches := pathextractor.GetAllMatches(scanner.Text(), pathextractor.MatchOptions{}) + matches := pathextractor.GetAllMatches(scanner.Text(), "ackmate") for _, match := range matches { fmt.Println(match) } diff --git a/pe_test.go b/pe_test.go index 3f24886f209bf927c03132b674ad2ff36ec369c7..18297677e2aca6a578eacfcc967ae18fcc148add 100644 --- a/pe_test.go +++ b/pe_test.go @@ -3,42 +3,42 @@ import "testing" func TestEverything(t *testing.T) { - output := GetAllMatches("?? alt/generateStore.php", MatchOptions{}) + output := GetAllMatches("?? alt/generateStore.php", "") if output[0] != "alt/generateStore.php" { t.Errorf("Doesnt match files", output) } - output = GetAllMatches("I have a cat.", MatchOptions{}) + output = GetAllMatches("I have a cat.", "") if len(output) != 0 { t.Errorf("Matches sentence", output) } - output = GetAllMatches("'/usr/bin", MatchOptions{}) + output = GetAllMatches("'/usr/bin", "") if output[0] != "/usr/bin" { t.Errorf("Doesn't match statement correctly", output) } - output = GetAllMatches("/usr_b/bin", MatchOptions{}) + output = GetAllMatches("/usr_b/bin", "") if output[0] != "/usr_b/bin" { t.Errorf("Doesn't match statement correctly", output) } - output = GetAllMatches("\"/usr/bin", MatchOptions{}) + output = GetAllMatches("\"/usr/bin", "") if output[0] != "/usr/bin" { t.Errorf("Doesn't match statement correctly", output) } - output = GetAllMatches("`/usr/bin", MatchOptions{}) + output = GetAllMatches("`/usr/bin", "") if output[0] != "/usr/bin" { t.Errorf("Doesn't match statement correctly", output) } - output = GetAllMatches("€/usr/bin", MatchOptions{}) + output = GetAllMatches("€/usr/bin", "") if output[0] != "/usr/bin" { t.Errorf("Doesn't match statement correctly", output) } - output = GetAllMatches("prefix=/usr/bin", MatchOptions{}) + output = GetAllMatches("prefix=/usr/bin", "") if len(output) != 1 { t.Errorf("Should match =/usr/bin", output) } @@ -46,22 +46,22 @@ if output[0] != "/usr/bin" { t.Errorf("Doesn't match statement correctly", output) } - output = GetAllMatches("/var//log", MatchOptions{}) + output = GetAllMatches("/var//log", "") if len(output) != 0 { t.Errorf("Matches double //", output) } - output = GetAllMatches("s/+//", MatchOptions{}) + output = GetAllMatches("s/+//", "") if len(output) != 0 { t.Errorf("Doesn't match substitute", output) } - output = GetAllMatches("s/^//", MatchOptions{}) + output = GetAllMatches("s/^//", "") if len(output) != 0 { t.Errorf("Doesn't match substitute", output) } - output = GetAllMatches("/usr/bin/env\\", MatchOptions{}) + output = GetAllMatches("/usr/bin/env\\", "") if len(output) != 1 { t.Errorf("Doesn't match escaped", output) } @@ -69,7 +69,7 @@ if output[0] != "/usr/bin/env" { t.Errorf("Doesn't match escaped exactly", output) } - output = GetAllMatches("!#/usr/bin/env", MatchOptions{}) + output = GetAllMatches("!#/usr/bin/env", "") if len(output) != 1 { t.Errorf("Doesn't match shebang", output) } @@ -77,87 +77,87 @@ if output[0] != "/usr/bin/env" { t.Errorf("Doesn't match shebang exactly", output) } - output = GetAllMatches("hello .gitignore", MatchOptions{}) + output = GetAllMatches("hello .gitignore", "") if output[0] != ".gitignore" { t.Errorf("Doesnt match hidden files", output) } - output = GetAllMatches(" this.user ", MatchOptions{}) + output = GetAllMatches(" this.user ", "") if len(output) != 0 { t.Errorf("Matches this.user", output) } - output = GetAllMatches("To https://test@test.org/88/ls.git", MatchOptions{}) + output = GetAllMatches("To https://test@test.org/88/ls.git", "") if len(output) != 0 { t.Errorf("Matches email adresses", output) } - output = GetAllMatches(" mail@mail.com ", MatchOptions{}) + output = GetAllMatches(" mail@mail.com ", "") if len(output) != 0 { t.Errorf("Matches email adresses", output) } - output = GetAllMatches(" logo@2x.png ", MatchOptions{}) + output = GetAllMatches(" logo@2x.png ", "") if len(output) == 0 { t.Errorf("Doesn't match retina asset", output) } - output = GetAllMatches("and/or", MatchOptions{}) + output = GetAllMatches("and/or", "") if len(output) != 0 { t.Errorf("Matches and/or adresses", output) } - output = GetAllMatches("v1.2", MatchOptions{}) + output = GetAllMatches("v1.2", "") if len(output) != 0 { t.Errorf("Matches version number", output) } - output = GetAllMatches("~/v1.2/js", MatchOptions{}) + output = GetAllMatches("~/v1.2/js", "") if len(output) != 1 { t.Errorf("Should match path with version inside", output) } - output = GetAllMatches("obj.slice()", MatchOptions{}) + output = GetAllMatches("obj.slice()", "") if len(output) != 0 { t.Errorf("Matches function call", output) } - output = GetAllMatches("fs.read(arg)", MatchOptions{}) + output = GetAllMatches("fs.read(arg)", "") if len(output) != 0 { t.Errorf("Matches function call", output) } - output = GetAllMatches("~/www", MatchOptions{}) + output = GetAllMatches("~/www", "") if len(output) == 0 || output[0] != "~/www" { t.Errorf("Doesnt match home", output) } - output = GetAllMatches("origin/master", MatchOptions{}) + output = GetAllMatches("origin/master", "") if len(output) != 0 { t.Errorf("Matches remote name", output) } - output = GetAllMatches("john doe (dead on 28/04/2014)", MatchOptions{}) + output = GetAllMatches("john doe (dead on 28/04/2014)", "") if len(output) != 0 { t.Errorf("Matches date", output) } - output = GetAllMatches("john doe ,dead on 28/04/2014", MatchOptions{}) + output = GetAllMatches("john doe ,dead on 28/04/2014", "") if len(output) != 0 { t.Errorf("Matches date", output) } - output = GetAllMatches(".gitignore , ~/www", MatchOptions{}) + output = GetAllMatches(".gitignore , ~/www", "") if len(output) != 2 { t.Errorf("Doesnt match multi", output) } - output = GetAllMatches("user.test.js", MatchOptions{}) + output = GetAllMatches("user.test.js", "") if len(output) != 1 { t.Errorf("Doesnt match multiple extensions", output) } - output = GetAllMatches("(user.js)", MatchOptions{}) + output = GetAllMatches("(user.js)", "") if len(output) != 1 { t.Errorf("Doesnt match surrounded by parens", output) } @@ -165,17 +165,17 @@ if output[0] != "user.js" { t.Errorf("matches surrounded by parens badly", output) } - output = GetAllMatches("var/", MatchOptions{}) + output = GetAllMatches("var/", "") if len(output) != 1 { t.Errorf("Doesnt match dir", output) } - output = GetAllMatches("//", MatchOptions{}) + output = GetAllMatches("//", "") if len(output) != 0 { t.Errorf("Comment matches", output) } - output = GetAllMatches("test.js:45", MatchOptions{format: "ackmate"}) + output = GetAllMatches("test.js:45", "ackmate") if len(output) != 1 { t.Errorf("Ackmate doesnt match", output) } @@ -187,7 +187,7 @@ if output[0] != "test.js:45" { t.Errorf("Ackmate should output right line number", output) } - output = GetAllMatches("test.js:45:12", MatchOptions{format: "ackmate"}) + output = GetAllMatches("test.js:45:12", "ackmate") if len(output) != 1 { t.Errorf("Ackmate doesnt match", output) }