github.com/sc0rp1us/gb@v0.4.1-0.20160319180011-4ba8cf1baa5a/importer/pkg_test.go (about) 1 package importer 2 3 import ( 4 "errors" 5 "reflect" 6 "runtime" 7 "testing" 8 ) 9 10 func TestGoodOSArch(t *testing.T) { 11 var ( 12 thisOS = runtime.GOOS 13 thisArch = runtime.GOARCH 14 otherOS = func() string { 15 if thisOS != "darwin" { 16 return "darwin" 17 } 18 return "linux" 19 }() 20 otherArch = func() string { 21 if thisArch != "amd64" { 22 return "amd64" 23 } 24 return "386" 25 }() 26 ) 27 tests := []struct { 28 name string 29 result bool 30 }{ 31 {"file.go", true}, 32 {"file.c", true}, 33 {"file_foo.go", true}, 34 {"file_" + thisArch + ".go", true}, 35 {"file_" + otherArch + ".go", false}, 36 {"file_" + thisOS + ".go", true}, 37 {"file_" + otherOS + ".go", false}, 38 {"file_" + thisOS + "_" + thisArch + ".go", true}, 39 {"file_" + otherOS + "_" + thisArch + ".go", false}, 40 {"file_" + thisOS + "_" + otherArch + ".go", false}, 41 {"file_" + otherOS + "_" + otherArch + ".go", false}, 42 {"file_foo_" + thisArch + ".go", true}, 43 {"file_foo_" + otherArch + ".go", false}, 44 {"file_" + thisOS + ".c", true}, 45 {"file_" + otherOS + ".c", false}, 46 } 47 48 for _, test := range tests { 49 if goodOSArchFile(thisOS, thisArch, test.name, make(map[string]bool)) != test.result { 50 t.Fatalf("goodOSArchFile(%q) != %v", test.name, test.result) 51 } 52 } 53 } 54 55 func TestSplitQuoted(t *testing.T) { 56 tests := []struct { 57 str string 58 want []string 59 err error 60 }{{ 61 str: `a b:"c d" 'e''f' "g\""`, want: []string{"a", "b:c d", "ef", `g"`}, 62 }, { 63 str: `a b:"c d`, err: errors.New("unclosed quote"), 64 }, { 65 str: `a \`, err: errors.New("unfinished escaping"), 66 }} 67 68 for _, tt := range tests { 69 got, err := splitQuoted(tt.str) 70 if !reflect.DeepEqual(err, tt.err) { 71 t.Errorf("splitQuoted(%q): got err %v, want err %v", tt.str, err, tt.err) 72 continue 73 } 74 if err == nil && !reflect.DeepEqual(got, tt.want) { 75 t.Errorf("splitQuoted(%q): got %v, want %v", tt.str, got, tt.want) 76 } 77 } 78 }