-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmatchers_test.go
90 lines (78 loc) · 2.34 KB
/
matchers_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
package matchers
import (
"testing"
)
func TestEqualTo(t *testing.T) {
m := EqualTo{true}
if !m.Match(true) {
t.Error("true is not true")
}
if m.Match(false) {
t.Error("true is false")
}
}
func TestAssertThat(t *testing.T) {
f := new(testing.T)
AssertThat(Protect{f}, true, EqualTo{true})
if f.Failed() {
t.Error("true is not true")
}
AssertThat(Protect{f}, true, EqualTo{false})
if !f.Failed() {
t.Error("true is false")
}
}
func TestIs(t *testing.T) {
AssertThat(t, true, Is{true})
AssertThat(t, true, Is{EqualTo{true}})
AssertThat(t, Expect{true, Is{false}}, Fails{})
}
func TestNot(t *testing.T) {
AssertThat(t, true, Not{false})
AssertThat(t, Expect{true, Not{true}}, Fails{})
}
func TestAllOf(t *testing.T) {
AssertThat(t, true, AllOf{Is{true}, Not{false}})
AssertThat(t, Expect{true, AllOf{Is{false}, Not{true}}}, Fails{})
AssertThat(t, Expect{true, AllOf{Is{true}, Not{true}}}, Fails{})
AssertThat(t, Expect{true, AllOf{Is{false}, Not{true}}}, Fails{})
}
func TestAnyOf(t *testing.T) {
AssertThat(t, true, AnyOf{Is{true}, Not{true}})
AssertThat(t, true, AnyOf{Is{false}, Not{false}})
AssertThat(t, true, AnyOf{Is{true}, Not{false}})
AssertThat(t, Expect{true, AnyOf{Is{false}, Not{true}}}, Fails{})
}
func TestElementsAre(t *testing.T) {
AssertThat(t, []int{1, 2, 3, 4, 5}, ElementsAre{5, 1, 4, 2, 3})
AssertThat(t, Expect{[]int{1, 2}, ElementsAre{1, 2, 2}}, Fails{})
AssertThat(t, Expect{[]int{1, 2}, ElementsAre{1, 3}}, Fails{})
AssertThat(t, Expect{1, ElementsAre{1, 3}}, Fails{})
v := []interface{}{}
a, b := 1, ""
v = append(v, a)
v = append(v, b)
AssertThat(t, v, ElementsAre{TypeOf{1}, TypeOf{""}})
}
func TestContains(t *testing.T) {
AssertThat(t, []int{1, 2, 3, 4, 5}, Contains{5, 1})
AssertThat(t, Expect{[]int{1, 2}, Contains{1, 3}}, Fails{})
AssertThat(t, Expect{[]int{1, 2}, Contains{3}}, Fails{})
AssertThat(t, []int{1, 2}, Contains{})
AssertThat(t, Expect{1, Contains{}}, Fails{})
v := []interface{}{}
a, b := 1, ""
v = append(v, a)
v = append(v, b)
AssertThat(t, v, Contains{TypeOf{1}})
}
func TestTypeOf(t *testing.T) {
AssertThat(t, "zzzzz", TypeOf{string("")})
AssertThat(t, Expect{1, TypeOf{string("")}}, Fails{})
}
func TestFails(t *testing.T) {
AssertThat(t, Expect{Expect{true, Is{true}}, Fails{}}, Fails{})
}
func TestFailsPanic(t *testing.T) {
AssertThat(t, Expect{true, Fails{}}, Fails{})
}