1 // Copyright (c) 2012-2016 The Revel Framework Authors, All rights reserved.
2 // Revel Framework source code and usage is governed by a MIT style
3 // license that can be found in the LICENSE file.
13 func TestContentTypeByFilename(t *testing.T) {
14 testCases := map[string]string{
15 "xyz.jpg": "image/jpeg",
16 "helloworld.c": "text/x-c; charset=utf-8",
17 "helloworld.": "application/octet-stream",
18 "helloworld": "application/octet-stream",
19 "hello.world.c": "text/x-c; charset=utf-8",
21 srcPath, _ := findSrcPaths(RevelImportPath)
22 ConfPaths = []string{filepath.Join(
24 filepath.FromSlash(RevelImportPath),
28 for filename, expected := range testCases {
29 actual := ContentTypeByFilename(filename)
30 if actual != expected {
31 t.Errorf("%s: %s, Expected %s", filename, actual, expected)
36 func TestEqual(t *testing.T) {
37 type testStruct struct{}
38 type testStruct2 struct{}
40 s, s2 := "@朕µ\n\tüöäß", "@朕µ\n\tüöäss"
41 slice, slice2 := []int{1, 2, 3, 4, 5}, []int{1, 2, 3, 4, 5}
42 slice3, slice4 := []int{5, 4, 3, 2, 1}, []int{5, 4, 3, 2, 1}
44 tm := map[string][]interface{}{
45 "slices": {slice, slice2},
46 "slices2": {slice3, slice4},
47 "types": {new(testStruct), new(testStruct)},
48 "types2": {new(testStruct2), new(testStruct2)},
49 "ints": {int(i), int8(i), int16(i), int32(i), int64(i)},
50 "ints2": {int(i2), int8(i2), int16(i2), int32(i2), int64(i2)},
51 "uints": {uint(i), uint8(i), uint16(i), uint32(i), uint64(i)},
52 "uints2": {uint(i2), uint8(i2), uint16(i2), uint32(i2), uint64(i2)},
53 "floats": {float32(i), float64(i)},
54 "floats2": {float32(i2), float64(i2)},
55 "strings": {[]byte(s), s},
56 "strings2": {[]byte(s2), s2},
59 testRow := func(row, row2 string, expected bool) {
60 for _, a := range tm[row] {
61 for _, b := range tm[row2] {
64 ak := reflect.TypeOf(a).Kind()
65 bk := reflect.TypeOf(b).Kind()
66 t.Errorf("eq(%s=%v,%s=%v) want %t got %t", ak, a, bk, b, expected, ok)
72 testRow("slices", "slices", true)
73 testRow("slices", "slices2", false)
74 testRow("slices2", "slices", false)
76 testRow("types", "types", true)
77 testRow("types2", "types", false)
78 testRow("types", "types2", false)
80 testRow("ints", "ints", true)
81 testRow("ints", "ints2", false)
82 testRow("ints2", "ints", false)
84 testRow("uints", "uints", true)
85 testRow("uints2", "uints", false)
86 testRow("uints", "uints2", false)
88 testRow("floats", "floats", true)
89 testRow("floats2", "floats", false)
90 testRow("floats", "floats2", false)
92 testRow("strings", "strings", true)
93 testRow("strings2", "strings", false)
94 testRow("strings", "strings2", false)