gopkg.in/tools/godep.v65@v65.0.0-20160509212847-4d9a4c3d91e3/match_test.go (about) 1 package main 2 3 import "testing" 4 5 func TestMatchPattern(t *testing.T) { 6 // Test cases from $GOROOT/src/cmd/go/match_test.go. 7 cases := []struct { 8 pat string 9 path string 10 want bool 11 }{ 12 {"...", "foo", true}, 13 {"net", "net", true}, 14 {"net", "net/http", false}, 15 {"net/http", "net", false}, 16 {"net/http", "net/http", true}, 17 {"net...", "netchan", true}, 18 {"net...", "net", true}, 19 {"net...", "net/http", true}, 20 {"net...", "not/http", false}, 21 {"net/...", "netchan", false}, 22 {"net/...", "net", true}, 23 {"net/...", "net/http", true}, 24 {"net/...", "not/http", false}, 25 } 26 for _, test := range cases { 27 ok := matchPattern(test.pat)(test.path) 28 if ok != test.want { 29 t.Errorf("matchPackages(%q)(%q) = %v want %v", test.pat, test.path, ok, test.want) 30 } 31 } 32 } 33 34 func TestSubPath(t *testing.T) { 35 cases := []struct { 36 sub string 37 dir string 38 want bool 39 }{ 40 //Basic 41 {`/Users/emuller/go/src/github.com/tools/godep`, `/Users/emuller/go`, true}, 42 //Case insensitive filesystem used in dir 43 {`/Users/emuller/go/src/github.com/tools/godep`, `/Users/Emuller/go`, true}, 44 {`/Users/emuller/go/Src/github.com/tools/godep`, `/Users/Emuller/go`, true}, 45 //spaces 46 {`/Users/e muller/go/Src/github.com/tools/godep`, `/Users/E muller/go`, true}, 47 // () 48 {`/Users/e muller/(Personal)/go/Src/github.com/tools/godep`, `/Users/E muller/(Personal)/go`, true}, 49 //Not even close, but same length 50 {`/foo`, `/bar`, false}, 51 // Same, so not sub path (same path) 52 {`/foo`, `/foo`, false}, 53 // Windows with different cases 54 {`c:\foo\bar`, `C:\foo`, true}, 55 } 56 57 for _, test := range cases { 58 ok := subPath(test.sub, test.dir) 59 if ok != test.want { 60 t.Errorf("subdir(%s,%s) = %v want %v", test.sub, test.dir, ok, test.want) 61 } 62 } 63 } 64 65 func TestIsSameOrNewer(t *testing.T) { 66 cases := []struct { 67 base string 68 check string 69 want bool 70 }{ 71 {`go1.6`, `go1.6`, true}, 72 {`go1.5`, `go1.6`, true}, 73 {`go1.7`, `go1.6`, false}, 74 } 75 76 for _, test := range cases { 77 ok := isSameOrNewer(test.base, test.check) 78 if ok != test.want { 79 t.Errorf("isSameOrNewer(%s,%s) = %v want %v", test.base, test.check, ok, test.want) 80 } 81 } 82 }