From 10f0b99e4b320a2beb819c7dc40423041b039f31 Mon Sep 17 00:00:00 2001 From: Edgar HIPP Date: Sun, 30 Aug 2015 17:07:01 +0200 Subject: [PATCH] First try for linenumbers --- extractor.go | 14 +++++++++++-- path-extractor/pe.go | 2 +- pe_test.go | 49 +++++++++++++++++++++++++++----------------- 3 files changed, 43 insertions(+), 22 deletions(-) diff --git a/extractor.go b/extractor.go index ac819dc..2a3b2cd 100644 --- a/extractor.go +++ b/extractor.go @@ -1,6 +1,11 @@ package pathextractor import "regexp" +import "fmt" + +type MatchOptions struct { + format string +} func pathExtractor(input string) [][][]byte { surroundRegex := "[^][ \\t:'\"]*" @@ -25,10 +30,11 @@ func postProcess(input string) string { return input } -func GetAllMatches(input string) []string { +func GetAllMatches(input string, options MatchOptions) []string { matches := [][][]byte{} result := []string{} s := string("") + // print(input) matches = pathExtractor(input) for _, match := range matches { s = string(match[1]) @@ -38,7 +44,11 @@ func GetAllMatches(input string) []string { if isGitPath(s) { s = replaceGitPath(s) } - result = append(result, postProcess(s)) + s = postProcess(s) + if options.format == "ackmate" { + s = fmt.Sprint(s, ":45") + } + result = append(result, s) } return result } diff --git a/path-extractor/pe.go b/path-extractor/pe.go index d95d456..6bb4fa3 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()) + matches := pathextractor.GetAllMatches(scanner.Text(), pathextractor.MatchOptions{}) for _, match := range matches { fmt.Println(match) } diff --git a/pe_test.go b/pe_test.go index 6038afe..f560e37 100644 --- a/pe_test.go +++ b/pe_test.go @@ -2,83 +2,83 @@ package pathextractor import "testing" -func TestGitIgnore(t *testing.T) { - output := GetAllMatches("?? alt/generateStore.php") +func TestEverything(t *testing.T) { + output := GetAllMatches("?? alt/generateStore.php", MatchOptions{}) if output[0] != "alt/generateStore.php" { t.Errorf("Doesnt match files", output) } - output = GetAllMatches("I have a cat.") + output = GetAllMatches("I have a cat.", MatchOptions{}) if len(output) != 0 { t.Errorf("Matches sentence", output) } - output = GetAllMatches("hello .gitignore") + output = GetAllMatches("hello .gitignore", MatchOptions{}) if output[0] != ".gitignore" { t.Errorf("Doesnt match hidden files", output) } - output = GetAllMatches(" this.user ") + output = GetAllMatches(" this.user ", MatchOptions{}) if len(output) != 0 { t.Errorf("Matches this.user", output) } - output = GetAllMatches(" mail@mail.com ") + output = GetAllMatches(" mail@mail.com ", MatchOptions{}) if len(output) != 0 { t.Errorf("Matches email adresses", output) } - output = GetAllMatches(" logo@2x.png ") + output = GetAllMatches(" logo@2x.png ", MatchOptions{}) if len(output) == 0 { t.Errorf("Doesn't match retina asset", output) } - output = GetAllMatches("and/or") + output = GetAllMatches("and/or", MatchOptions{}) if len(output) != 0 { t.Errorf("Matches and/or adresses", output) } - output = GetAllMatches("v1.2") + output = GetAllMatches("v1.2", MatchOptions{}) if len(output) != 0 { t.Errorf("Matches version number", output) } - output = GetAllMatches("obj.slice()") + output = GetAllMatches("obj.slice()", MatchOptions{}) if len(output) != 0 { t.Errorf("Matches function call", output) } - output = GetAllMatches("~/www") + output = GetAllMatches("~/www", MatchOptions{}) if len(output) == 0 || output[0] != "~/www" { t.Errorf("Doesnt match home", output) } - output = GetAllMatches("origin/master") + output = GetAllMatches("origin/master", MatchOptions{}) if len(output) != 0 { t.Errorf("Matches remote name", output) } - output = GetAllMatches("john doe (dead on 28/04/2014)") + output = GetAllMatches("john doe (dead on 28/04/2014)", MatchOptions{}) if len(output) != 0 { t.Errorf("Matches date", output) } - output = GetAllMatches("john doe ,dead on 28/04/2014") + output = GetAllMatches("john doe ,dead on 28/04/2014", MatchOptions{}) if len(output) != 0 { t.Errorf("Matches date", output) } - output = GetAllMatches(".gitignore , ~/www") + output = GetAllMatches(".gitignore , ~/www", MatchOptions{}) if len(output) != 2 { t.Errorf("Doesnt match multi", output) } - output = GetAllMatches("user.test.js") + output = GetAllMatches("user.test.js", MatchOptions{}) if len(output) != 1 { t.Errorf("Doesnt match multiple extensions", output) } - output = GetAllMatches("(user.js)") + output = GetAllMatches("(user.js)", MatchOptions{}) if len(output) != 1 { t.Errorf("Doesnt match surrounded by parens", output) } @@ -86,13 +86,24 @@ func TestGitIgnore(t *testing.T) { t.Errorf("matches surrounded by parens badly", output) } - output = GetAllMatches("var/") + output = GetAllMatches("var/", MatchOptions{}) if len(output) != 1 { t.Errorf("Doesnt match dir", output) } - output = GetAllMatches("//") + output = GetAllMatches("//", MatchOptions{}) if len(output) != 0 { t.Errorf("Comment matches", output) } + + output = GetAllMatches("test.js:45", MatchOptions{format: "ackmate"}) + if len(output) != 1 { + t.Errorf("Ackmate doesnt match", output) + } + if output[0] == "test.js" { + t.Errorf("Ackmate should not forget number", output) + } + if output[0] != "test.js:45" { + t.Errorf("Ackmate should output right line number", output) + } } -- 2.44.0