From 6d1dd1099ee890f91afcb553e6dcdef8a65f0d0d Mon Sep 17 00:00:00 2001 From: Edgar HIPP Date: Sat, 16 Jan 2016 07:36:57 +0100 Subject: [PATCH] Convert option to string --- extractor.go | 3 +- path-extractor/pe.go | 2 +- pe_test.go | 68 ++++++++++++++++++++++---------------------- 3 files changed, 37 insertions(+), 36 deletions(-) diff --git a/extractor.go b/extractor.go index c19b7d5..e05ad4b 100644 --- a/extractor.go +++ b/extractor.go @@ -29,7 +29,8 @@ func postProcess(input string) string { 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 6bb4fa3..5b5d8d3 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 3f24886..1829767 100644 --- a/pe_test.go +++ b/pe_test.go @@ -3,42 +3,42 @@ package pathextractor 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 @@ func TestEverything(t *testing.T) { 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 @@ func TestEverything(t *testing.T) { 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 @@ func TestEverything(t *testing.T) { 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 @@ func TestEverything(t *testing.T) { 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 @@ func TestEverything(t *testing.T) { 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) } -- 2.44.0