Left: | ||
Right: |
OLD | NEW |
---|---|
1 // Copyright 2013 Canonical Ltd. | 1 // Copyright 2013 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package checkers_test | 4 package checkers_test |
5 | 5 |
6 import ( | 6 import ( |
7 "errors" | 7 "errors" |
8 . "launchpad.net/gocheck" | 8 . "launchpad.net/gocheck" |
9 . "launchpad.net/juju-core/testing/checkers" | 9 . "launchpad.net/juju-core/testing/checkers" |
10 "os" | 10 "os" |
(...skipping 22 matching lines...) Expand all Loading... | |
33 | 33 |
34 func (s *BoolSuite) TestIsFalse(c *C) { | 34 func (s *BoolSuite) TestIsFalse(c *C) { |
35 c.Assert(false, IsFalse) | 35 c.Assert(false, IsFalse) |
36 c.Assert(true, Not(IsFalse)) | 36 c.Assert(true, Not(IsFalse)) |
37 } | 37 } |
38 | 38 |
39 func is42(i int) bool { | 39 func is42(i int) bool { |
40 return i == 42 | 40 return i == 42 |
41 } | 41 } |
42 | 42 |
43 var satisfiesTests = []struct { | |
44 f interface{} | |
45 arg interface{} | |
46 result bool | |
47 msg string | |
48 }{{ | |
49 f: is42, | |
50 arg: 42, | |
51 result: true, | |
52 }, { | |
53 f: is42, | |
54 arg: 41, | |
dimitern
2013/07/22 17:07:58
I'd prefer explicit result: false here and in othe
rog
2013/07/22 17:29:44
Done.
| |
55 }, { | |
56 f: is42, | |
57 arg: "", | |
58 msg: "wrong argument type string for func(int) bool", | |
59 }, { | |
60 f: os.IsNotExist, | |
61 arg: errors.New("foo"), | |
62 }, { | |
63 f: os.IsNotExist, | |
64 arg: os.ErrNotExist, | |
65 result: true, | |
66 }, { | |
67 f: os.IsNotExist, | |
68 }, { | |
69 f: func(chan int) bool { return true }, | |
dimitern
2013/07/22 17:07:58
Likewise, arg: nil here and below.
rog
2013/07/22 17:29:44
Done.
| |
70 result: true, | |
71 }, { | |
72 f: func(func()) bool { return true }, | |
73 result: true, | |
74 }, { | |
75 f: func(interface{}) bool { return true }, | |
76 result: true, | |
77 }, { | |
78 f: func(map[string]bool) bool { return true }, | |
79 result: true, | |
80 }, { | |
81 f: func(*int) bool { return true }, | |
82 result: true, | |
83 }, { | |
84 f: func([]string) bool { return true }, | |
85 result: true, | |
86 }} | |
87 | |
43 func (s *BoolSuite) TestSatisfies(c *C) { | 88 func (s *BoolSuite) TestSatisfies(c *C) { |
44 » result, msg := Satisfies.Check([]interface{}{42, is42}, nil) | 89 » for i, test := range satisfiesTests { |
45 » c.Assert(result, Equals, true) | 90 » » c.Logf("test %d. %T %T", i, test.f, test.arg) |
46 » c.Assert(msg, Equals, "") | 91 » » result, msg := Satisfies.Check([]interface{}{test.arg, test.f}, nil) |
47 | 92 » » c.Check(result, Equals, test.result) |
48 » result, msg = Satisfies.Check([]interface{}{41, is42}, nil) | 93 » » c.Check(msg, Equals, test.msg) |
49 » c.Assert(result, Equals, false) | 94 » } |
50 » c.Assert(msg, Equals, "") | |
51 | |
52 » result, msg = Satisfies.Check([]interface{}{"", is42}, nil) | |
53 » c.Assert(result, Equals, false) | |
54 » c.Assert(msg, Equals, "expected func(string) bool, got func(int) bool") | |
55 | |
56 » result, msg = Satisfies.Check([]interface{}{"", is42}, nil) | |
57 » c.Assert(result, Equals, false) | |
58 » c.Assert(msg, Equals, "expected func(string) bool, got func(int) bool") | |
59 | |
60 » result, msg = Satisfies.Check([]interface{}{errors.New("foo"), os.IsNotE xist}, nil) | |
61 » c.Assert(result, Equals, false) | |
62 » c.Assert(msg, Equals, "") | |
63 | |
64 » result, msg = Satisfies.Check([]interface{}{os.ErrNotExist, os.IsNotExis t}, nil) | |
65 » c.Assert(result, Equals, true) | |
66 » c.Assert(msg, Equals, "") | |
67 } | 95 } |
OLD | NEW |