9 // AssertionTesterInterface defines an interface to be used for testing assertion methods
10 type AssertionTesterInterface interface {
14 // AssertionTesterConformingObject is an object that conforms to the AssertionTesterInterface interface
15 type AssertionTesterConformingObject struct {
18 func (a *AssertionTesterConformingObject) TestMethod() {
21 // AssertionTesterNonConformingObject is an object that does not conform to the AssertionTesterInterface interface
22 type AssertionTesterNonConformingObject struct {
29 func (t *MockT) FailNow() {
33 func (t *MockT) Errorf(format string, args ...interface{}) {
37 func TestImplements(t *testing.T) {
39 Implements(t, (*AssertionTesterInterface)(nil), new(AssertionTesterConformingObject))
42 Implements(mockT, (*AssertionTesterInterface)(nil), new(AssertionTesterNonConformingObject))
44 t.Error("Check should fail")
48 func TestIsType(t *testing.T) {
50 IsType(t, new(AssertionTesterConformingObject), new(AssertionTesterConformingObject))
53 IsType(mockT, new(AssertionTesterConformingObject), new(AssertionTesterNonConformingObject))
55 t.Error("Check should fail")
59 func TestEqual(t *testing.T) {
66 t.Error("Check should fail")
71 func TestNotEqual(t *testing.T) {
77 t.Error("Check should fail")
81 func TestExactly(t *testing.T) {
92 t.Error("Check should fail")
96 func TestNotNil(t *testing.T) {
98 NotNil(t, new(AssertionTesterConformingObject))
103 t.Error("Check should fail")
107 func TestNil(t *testing.T) {
112 Nil(mockT, new(AssertionTesterConformingObject))
114 t.Error("Check should fail")
118 func TestTrue(t *testing.T) {
125 t.Error("Check should fail")
129 func TestFalse(t *testing.T) {
136 t.Error("Check should fail")
140 func TestContains(t *testing.T) {
142 Contains(t, "Hello World", "Hello")
145 Contains(mockT, "Hello World", "Salut")
147 t.Error("Check should fail")
151 func TestNotContains(t *testing.T) {
153 NotContains(t, "Hello World", "Hello!")
156 NotContains(mockT, "Hello World", "Hello")
158 t.Error("Check should fail")
162 func TestPanics(t *testing.T) {
169 Panics(mockT, func() {})
171 t.Error("Check should fail")
175 func TestNotPanics(t *testing.T) {
177 NotPanics(t, func() {})
180 NotPanics(mockT, func() {
184 t.Error("Check should fail")
188 func TestNoError(t *testing.T) {
193 NoError(mockT, errors.New("some error"))
195 t.Error("Check should fail")
199 func TestError(t *testing.T) {
201 Error(t, errors.New("some error"))
206 t.Error("Check should fail")
210 func TestEqualError(t *testing.T) {
212 EqualError(t, errors.New("some error"), "some error")
215 EqualError(mockT, errors.New("some error"), "Not some error")
217 t.Error("Check should fail")
221 func TestEmpty(t *testing.T) {
228 t.Error("Check should fail")
232 func TestNotEmpty(t *testing.T) {
239 t.Error("Check should fail")
243 func TestWithinDuration(t *testing.T) {
246 b := a.Add(10 * time.Second)
248 WithinDuration(t, a, b, 15*time.Second)
251 WithinDuration(mockT, a, b, 5*time.Second)
253 t.Error("Check should fail")
257 func TestInDelta(t *testing.T) {
259 InDelta(t, 1.001, 1, 0.01)
262 InDelta(mockT, 1, 2, 0.5)
264 t.Error("Check should fail")
268 func TestZero(t *testing.T) {
275 t.Error("Check should fail")
279 func TestNotZero(t *testing.T) {
286 t.Error("Check should fail")
290 func TestJSONEq_EqualSONString(t *testing.T) {
292 JSONEq(mockT, `{"hello": "world", "foo": "bar"}`, `{"hello": "world", "foo": "bar"}`)
294 t.Error("Check should pass")
298 func TestJSONEq_EquivalentButNotEqual(t *testing.T) {
300 JSONEq(mockT, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
302 t.Error("Check should pass")
306 func TestJSONEq_HashOfArraysAndHashes(t *testing.T) {
308 JSONEq(mockT, "{\r\n\t\"numeric\": 1.5,\r\n\t\"array\": [{\"foo\": \"bar\"}, 1, \"string\", [\"nested\", \"array\", 5.5]],\r\n\t\"hash\": {\"nested\": \"hash\", \"nested_slice\": [\"this\", \"is\", \"nested\"]},\r\n\t\"string\": \"foo\"\r\n}",
309 "{\r\n\t\"numeric\": 1.5,\r\n\t\"hash\": {\"nested\": \"hash\", \"nested_slice\": [\"this\", \"is\", \"nested\"]},\r\n\t\"string\": \"foo\",\r\n\t\"array\": [{\"foo\": \"bar\"}, 1, \"string\", [\"nested\", \"array\", 5.5]]\r\n}")
311 t.Error("Check should pass")
315 func TestJSONEq_Array(t *testing.T) {
317 JSONEq(mockT, `["foo", {"hello": "world", "nested": "hash"}]`, `["foo", {"nested": "hash", "hello": "world"}]`)
319 t.Error("Check should pass")
323 func TestJSONEq_HashAndArrayNotEquivalent(t *testing.T) {
325 JSONEq(mockT, `["foo", {"hello": "world", "nested": "hash"}]`, `{"foo": "bar", {"nested": "hash", "hello": "world"}}`)
327 t.Error("Check should fail")
331 func TestJSONEq_HashesNotEquivalent(t *testing.T) {
333 JSONEq(mockT, `{"foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
335 t.Error("Check should fail")
339 func TestJSONEq_ActualIsNotJSON(t *testing.T) {
341 JSONEq(mockT, `{"foo": "bar"}`, "Not JSON")
343 t.Error("Check should fail")
347 func TestJSONEq_ExpectedIsNotJSON(t *testing.T) {
349 JSONEq(mockT, "Not JSON", `{"foo": "bar", "hello": "world"}`)
351 t.Error("Check should fail")
355 func TestJSONEq_ExpectedAndActualNotJSON(t *testing.T) {
357 JSONEq(mockT, "Not JSON", "Not JSON")
359 t.Error("Check should fail")
363 func TestJSONEq_ArraysOfDifferentOrder(t *testing.T) {
365 JSONEq(mockT, `["foo", {"hello": "world", "nested": "hash"}]`, `[{ "hello": "world", "nested": "hash"}, "foo"]`)
367 t.Error("Check should fail")