-
Notifications
You must be signed in to change notification settings - Fork 0
/
expectations_string_test.go
80 lines (69 loc) · 2.6 KB
/
expectations_string_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
package expectations_test
import (
"testing"
"github.com/laliluna/expectations"
)
type StringTestCase struct {
Fn func(interface{}) *expectations.StringExpectation
ExpectedValue interface{}
Succeeds bool
}
func TestStringExpectations(t *testing.T) {
tMock := &TMock{}
et := expectations.NewT(tMock)
actualValue := "FooBoo"
expect := et.ExpectThatString(actualValue)
testCases := []StringTestCase{
StringTestCase{expect.Equals, actualValue, true},
StringTestCase{expect.Equals, "Something else", false},
StringTestCase{expect.Equals, nil, false},
StringTestCase{expect.EqualsIgnoringCase, "fooboo", true},
StringTestCase{expect.EqualsIgnoringCase, "Something else", false},
StringTestCase{expect.DoesNotEqual, "SomethingElse", true},
StringTestCase{expect.DoesNotEqual, "FooBoo", false},
StringTestCase{expect.DoesNotEqual, nil, true},
StringTestCase{expect.StartsWith, "Foo", true},
StringTestCase{expect.StartsWith, "Boo", false},
StringTestCase{expect.StartsWith, "foo", false},
StringTestCase{expect.EndsWith, "Boo", true},
StringTestCase{expect.EndsWith, "Foo", false},
StringTestCase{expect.EndsWith, "boo", false},
StringTestCase{expect.StartsWith, "Boo", false},
StringTestCase{expect.StartsWith, "foo", false},
}
for _, testCase := range testCases {
tMock.reset()
testCase.Fn(testCase.ExpectedValue)
if testCase.Succeeds == tMock.HasBeenCalled {
t.Errorf("Test failed: %v %v %v should be %v", actualValue, functionName(testCase.Fn), testCase.ExpectedValue, testCase.Succeeds)
}
expect.Reset()
}
}
type StringArrayTestCase struct {
Fn func(...string) *expectations.StringExpectation
ExpectedValue []string
Succeeds bool
}
func TestStringContainsExpectations(t *testing.T) {
tMock := &TMock{}
et := expectations.NewT(tMock)
actualValue := "FooBoo"
expect := et.ExpectThatString(actualValue)
testCases := []StringArrayTestCase{
StringArrayTestCase{expect.Contains, []string{"oo", "ooBo"}, true},
StringArrayTestCase{expect.Contains, []string{"oo", "x"}, false},
StringArrayTestCase{expect.Contains, []string{"x"}, false},
StringArrayTestCase{expect.DoesNotContain, []string{"ox", "obo"}, true},
StringArrayTestCase{expect.DoesNotContain, []string{"x", "oo"}, false},
StringArrayTestCase{expect.DoesNotContain, []string{"oo"}, false},
}
for _, testCase := range testCases {
tMock.reset()
testCase.Fn(testCase.ExpectedValue...)
if testCase.Succeeds == tMock.HasBeenCalled {
t.Errorf("Test failed: %v %v %v should be %v", actualValue, functionName(testCase.Fn), testCase.ExpectedValue, testCase.Succeeds)
}
expect.Reset()
}
}