github.com/gsquire/gb@v0.4.4-0.20161112235727-3982dc872064/gb_test.go (about) 1 package gb 2 3 import "testing" 4 5 func TestStripext(t *testing.T) { 6 tests := []struct { 7 path, want string 8 }{ 9 {"a.txt", "a"}, 10 {"a.a.txt", "a.a"}, 11 {"Makefile", "Makefile"}, 12 {"", ""}, 13 {"/", "/"}, 14 } 15 16 for _, tt := range tests { 17 got := stripext(tt.path) 18 if got != tt.want { 19 t.Errorf("stripext(%q): want: %v, got: %v", tt.path, tt.want, got) 20 } 21 } 22 } 23 24 func TestRelImportPath(t *testing.T) { 25 tests := []struct { 26 root, path, want string 27 }{ 28 {"/project/src", "a", "a"}, 29 // { "/project/src", "./a", "a"}, // TODO(dfc) this is relative 30 // { "/project/src", "a/../b", "a"}, // TODO(dfc) so is this 31 } 32 33 for _, tt := range tests { 34 35 got, _ := relImportPath(tt.root, tt.path) 36 if got != tt.want { 37 t.Errorf("relImportPath(%q, %q): want: %v, got: %v", tt.root, tt.path, tt.want, got) 38 } 39 } 40 } 41 42 func TestIsRel(t *testing.T) { 43 tests := []struct { 44 path string 45 want bool 46 }{ 47 {".", true}, 48 {"..", false}, // TODO(dfc) this is relative 49 {"a/../b", false}, // TODO(dfc) this too 50 } 51 52 for _, tt := range tests { 53 got := isRel(tt.path) 54 if got != tt.want { 55 t.Errorf("isRel(%q): want: %v, got: %v", tt.want, got) 56 } 57 } 58 }