]> Sergey Matveev's repositories - path-extractor.git/blobdiff - pe_test.go
Shouldn't match + nor ^
[path-extractor.git] / pe_test.go
index 2ef95b285870f1d42b9dda338da17f079fc0f9a3..28f87f7afb3ddfb231e751b018861b1234057654 100644 (file)
-package main
+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[0])
+               t.Errorf("Doesnt match files", output)
        }
 
-       output = getAllMatches("hello .gitignore")
+       output = GetAllMatches("I have a cat.", MatchOptions{})
+       if len(output) != 0 {
+               t.Errorf("Matches sentence", output)
+       }
+
+       output = GetAllMatches("s/+//", MatchOptions{})
+       if len(output) != 0 {
+               t.Errorf("Doesn't match substitute", output)
+       }
+
+       output = GetAllMatches("s/^//", MatchOptions{})
+       if len(output) != 0 {
+               t.Errorf("Doesn't match substitute", output)
+       }
+
+       output = GetAllMatches("/usr/bin/env\\", MatchOptions{})
+       if len(output) != 1 {
+               t.Errorf("Doesn't match escaped", output)
+       }
+       if output[0] != "/usr/bin/env" {
+               t.Errorf("Doesn't match escaped exactly", output)
+       }
+
+       output = GetAllMatches("!#/usr/bin/env", MatchOptions{})
+       if len(output) != 1 {
+               t.Errorf("Doesn't match shebang", output)
+       }
+       if output[0] != "/usr/bin/env" {
+               t.Errorf("Doesn't match shebang exactly", output)
+       }
+
+       output = GetAllMatches("hello .gitignore", MatchOptions{})
        if output[0] != ".gitignore" {
-               t.Errorf("Doesnt match hidden files", output[0])
+               t.Errorf("Doesnt match hidden files", output)
+       }
+
+       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[0])
+               t.Errorf("Matches email adresses", output)
        }
 
-       output = getAllMatches("v1.2")
+       output = GetAllMatches(" logo@2x.png ", MatchOptions{})
+       if len(output) == 0 {
+               t.Errorf("Doesn't match retina asset", output)
+       }
+
+       output = GetAllMatches("and/or", MatchOptions{})
+       if len(output) != 0 {
+               t.Errorf("Matches and/or adresses", output)
+       }
+
+       output = GetAllMatches("v1.2", MatchOptions{})
        if len(output) != 0 {
-               t.Errorf("Matches version number", 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[0])
+               t.Errorf("Matches function call", output)
        }
 
-       output = getAllMatches("~/www")
+       output = GetAllMatches("fs.read(arg)", MatchOptions{})
+       if len(output) != 0 {
+               t.Errorf("Matches function call", output)
+       }
+
+       output = GetAllMatches("~/www", MatchOptions{})
        if len(output) == 0 || output[0] != "~/www" {
-               t.Errorf("Doesnt match home", output[0])
+               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[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[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[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[0])
+               t.Errorf("Doesnt match multi", output)
+       }
+
+       output = GetAllMatches("user.test.js", MatchOptions{})
+       if len(output) != 1 {
+               t.Errorf("Doesnt match multiple extensions", output)
+       }
+
+       output = GetAllMatches("(user.js)", MatchOptions{})
+       if len(output) != 1 {
+               t.Errorf("Doesnt match surrounded by parens", output)
+       }
+       if output[0] != "user.js" {
+               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[0])
+               t.Errorf("Doesnt match dir", output)
        }
 
-       output = getAllMatches("//")
+       output = GetAllMatches("//", MatchOptions{})
        if len(output) != 0 {
-               t.Errorf("Comment matches", 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)
        }
 }