-
Notifications
You must be signed in to change notification settings - Fork 1
/
hamcrest_util_test.go
102 lines (96 loc) · 1.84 KB
/
hamcrest_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
96
97
98
99
100
101
102
package assert
import (
"testing"
)
func TestBuildError(t *testing.T) {
{
err := buildError("expected type '%s' but got '%s'", "", "foo", "bar")
if err == nil {
t.Fatal("err is nil")
}
if err.Error() != "expected type 'foo' but got 'bar'" {
t.Fatal("errormessage is incorrect")
}
}
{
err := buildError("expected type '%s' but got '%s'", "message", "foo", "bar")
if err == nil {
t.Fatal("err is nil")
}
if err.Error() != "message, expected type 'foo' but got 'bar'" {
t.Fatal("errormessage is incorrect")
}
}
}
func TestIsByteArray(t *testing.T) {
{
err := AssertThat(isByteArray(nil), Is(false))
if err != nil {
t.Fatal(err)
}
}
{
err := AssertThat(isByteArray([]string{"a", "b"}), Is(false))
if err != nil {
t.Fatal(err)
}
}
{
err := AssertThat(isByteArray([]byte("hello")), Is(true))
if err != nil {
t.Fatal(err)
}
}
}
func TestLessTypeNotEqualAlwaysReturnFalse(t *testing.T) {
if less(int32(1), int64(2)) {
t.Fatal("invalid")
}
}
func TestLessNotSupportTypePanics(t *testing.T) {
defer func() {
if r := recover(); r != nil {
} else {
t.Fatal("panic should be called")
}
}()
less("1", "1")
}
func TestLess(t *testing.T) {
if less(int(1), int(1)) {
t.Fatal("invalid")
}
if less(int8(1), int8(1)) {
t.Fatal("invalid")
}
if less(int16(1), int16(1)) {
t.Fatal("invalid")
}
if less(int32(1), int32(1)) {
t.Fatal("invalid")
}
if less(int64(1), int64(1)) {
t.Fatal("invalid")
}
if less(uint(1), uint(1)) {
t.Fatal("invalid")
}
if less(uint8(1), uint8(1)) {
t.Fatal("invalid")
}
if less(uint16(1), uint16(1)) {
t.Fatal("invalid")
}
if less(uint32(1), uint32(1)) {
t.Fatal("invalid")
}
if less(uint64(1), uint64(1)) {
t.Fatal("invalid")
}
if less(float32(1), float32(1)) {
t.Fatal("invalid")
}
if less(float64(1), float64(1)) {
t.Fatal("invalid")
}
}