forked from revel/revel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_test.go
95 lines (83 loc) · 2.72 KB
/
util_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright (c) 2012-2016 The Revel Framework Authors, All rights reserved.
// Revel Framework source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.
package revel
import (
"path/filepath"
"reflect"
"testing"
)
func TestContentTypeByFilename(t *testing.T) {
testCases := map[string]string{
"xyz.jpg": "image/jpeg",
"helloworld.c": "text/x-c; charset=utf-8",
"helloworld.": "application/octet-stream",
"helloworld": "application/octet-stream",
"hello.world.c": "text/x-c; charset=utf-8",
}
srcPath, _ := findSrcPaths(RevelImportPath)
ConfPaths = []string{filepath.Join(
srcPath,
filepath.FromSlash(RevelImportPath),
"conf"),
}
LoadMimeConfig()
for filename, expected := range testCases {
actual := ContentTypeByFilename(filename)
if actual != expected {
t.Errorf("%s: %s, Expected %s", filename, actual, expected)
}
}
}
func TestEqual(t *testing.T) {
type testStruct struct{}
type testStruct2 struct{}
i, i2 := 8, 9
s, s2 := "@朕µ\n\tüöäß", "@朕µ\n\tüöäss"
slice, slice2 := []int{1, 2, 3, 4, 5}, []int{1, 2, 3, 4, 5}
slice3, slice4 := []int{5, 4, 3, 2, 1}, []int{5, 4, 3, 2, 1}
tm := map[string][]interface{}{
"slices": {slice, slice2},
"slices2": {slice3, slice4},
"types": {new(testStruct), new(testStruct)},
"types2": {new(testStruct2), new(testStruct2)},
"ints": {int(i), int8(i), int16(i), int32(i), int64(i)},
"ints2": {int(i2), int8(i2), int16(i2), int32(i2), int64(i2)},
"uints": {uint(i), uint8(i), uint16(i), uint32(i), uint64(i)},
"uints2": {uint(i2), uint8(i2), uint16(i2), uint32(i2), uint64(i2)},
"floats": {float32(i), float64(i)},
"floats2": {float32(i2), float64(i2)},
"strings": {[]byte(s), s},
"strings2": {[]byte(s2), s2},
}
testRow := func(row, row2 string, expected bool) {
for _, a := range tm[row] {
for _, b := range tm[row2] {
ok := Equal(a, b)
if ok != expected {
ak := reflect.TypeOf(a).Kind()
bk := reflect.TypeOf(b).Kind()
t.Errorf("eq(%s=%v,%s=%v) want %t got %t", ak, a, bk, b, expected, ok)
}
}
}
}
testRow("slices", "slices", true)
testRow("slices", "slices2", false)
testRow("slices2", "slices", false)
testRow("types", "types", true)
testRow("types2", "types", false)
testRow("types", "types2", false)
testRow("ints", "ints", true)
testRow("ints", "ints2", false)
testRow("ints2", "ints", false)
testRow("uints", "uints", true)
testRow("uints2", "uints", false)
testRow("uints", "uints2", false)
testRow("floats", "floats", true)
testRow("floats2", "floats", false)
testRow("floats", "floats2", false)
testRow("strings", "strings", true)
testRow("strings2", "strings", false)
testRow("strings", "strings2", false)
}