-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutil_test.go
68 lines (60 loc) · 1.44 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
package gofast
import "testing"
import "reflect"
import "strings"
import "runtime/debug"
func TestBytes2Str(t *testing.T) {
if bytes2str(nil) != "" {
t.Errorf("fail bytes2str(nil)")
}
ref := "hello world"
if s := bytes2str(str2bytes(ref)); s != ref {
t.Errorf("expected %v, got %v", ref, s)
}
}
func TestStr2Bytes(t *testing.T) {
if str2bytes("") != nil {
t.Errorf(`fail str2bytes("")`)
}
}
func TestHasString(t *testing.T) {
if hasString("hello", []string{"hello", "world"}) == false {
t.Errorf("expected %v, got %v", false, true)
}
if hasString("whoami", []string{"hello", "world"}) == true {
t.Errorf("expected %v, got %v", true, false)
}
}
func TestCsv2strings(t *testing.T) {
testcases := [][2]interface{}{
{"a ,, b,c", []string{"a", "b", "c"}},
{" , a", []string{"a"}},
{" a, ", []string{"a"}},
{" , ", []string{}},
{"", []string{}},
}
for _, tcase := range testcases {
in, ref := tcase[0].(string), tcase[1].([]string)
if rv := csv2strings(in, []string{}); !reflect.DeepEqual(ref, rv) {
t.Errorf("expected %v, got %v", ref, rv)
}
}
}
func TestStackTrace(t *testing.T) {
s := getStackTrace(0, debug.Stack())
if !strings.Contains(s, "debug.Stack") {
t.Errorf("stack-trace %v", s)
}
}
func BenchmarkBytes2Str(b *testing.B) {
bs := []byte("hello world")
for i := 0; i < b.N; i++ {
bytes2str(bs)
}
}
func BenchmarkStr2Bytes(b *testing.B) {
s := "hello world"
for i := 0; i < b.N; i++ {
str2bytes(s)
}
}