github.com/liuweiccy/glide@v0.12.3/util/normalizename_test.go (about) 1 package util 2 3 import ( 4 "testing" 5 ) 6 7 func TestNormalizeName(t *testing.T) { 8 packages := []struct { 9 input string 10 root string 11 extra string 12 }{ 13 { 14 input: "github.com/Masterminds/cookoo/web/io/foo", 15 root: "github.com/Masterminds/cookoo", 16 extra: "web/io/foo", 17 }, 18 { 19 input: `github.com\Masterminds\cookoo\web\io\foo`, 20 root: "github.com/Masterminds/cookoo", 21 extra: "web/io/foo", 22 }, 23 { 24 input: "golang.org/x/crypto/ssh", 25 root: "golang.org/x/crypto", 26 extra: "ssh", 27 }, 28 { 29 input: "incomplete/example", 30 root: "incomplete/example", 31 extra: "", 32 }, 33 { 34 input: "otherurl/example/root/sub", 35 root: "otherurl/example/root", 36 extra: "sub", 37 }, 38 { 39 input: "net", 40 root: "net", 41 extra: "", 42 }, 43 } 44 remotePackageCache["otherurl/example/root"] = "otherurl/example/root" 45 46 for _, test := range packages { 47 root, extra := NormalizeName(test.input) 48 if root != test.root { 49 t.Errorf("%s: Expected root '%s', got '%s'", test.input, test.root, root) 50 } 51 if extra != test.extra { 52 t.Errorf("%s: Expected extra '%s', got '%s'", test.input, test.extra, extra) 53 } 54 } 55 }