1
// Copyright 2013 Canonical Ltd.
2
// Licensed under the LGPLv3, see LICENCE file for details.
9
gc "launchpad.net/gocheck"
11
jc "github.com/juju/testing/checkers"
14
func Test(t *testing.T) { gc.TestingT(t) }
16
type CheckerSuite struct{}
18
var _ = gc.Suite(&CheckerSuite{})
20
func (s *CheckerSuite) TestHasPrefix(c *gc.C) {
21
c.Assert("foo bar", jc.HasPrefix, "foo")
22
c.Assert("foo bar", gc.Not(jc.HasPrefix), "omg")
25
func (s *CheckerSuite) TestHasSuffix(c *gc.C) {
26
c.Assert("foo bar", jc.HasSuffix, "bar")
27
c.Assert("foo bar", gc.Not(jc.HasSuffix), "omg")
30
func (s *CheckerSuite) TestContains(c *gc.C) {
31
c.Assert("foo bar baz", jc.Contains, "foo")
32
c.Assert("foo bar baz", jc.Contains, "bar")
33
c.Assert("foo bar baz", jc.Contains, "baz")
34
c.Assert("foo bar baz", gc.Not(jc.Contains), "omg")
37
func (s *CheckerSuite) TestSameContents(c *gc.C) {
38
//// positive cases ////
42
[]int{1, 2, 3}, jc.SameContents,
47
[]int{}, jc.SameContents,
52
[]int{1}, jc.SameContents,
57
[]int{1, 2, 3}, jc.SameContents,
60
// multiple copies of same
62
[]int{1, 1, 2}, jc.SameContents,
72
[]test{{"a", 1}, {"b", 2}}, jc.SameContents,
73
[]test{{"b", 2}, {"a", 1}})
75
//// negative cases ////
79
[]int{1, 3, 2, 5}, gc.Not(jc.SameContents),
82
// different size slices
84
[]int{1, 2, 3}, gc.Not(jc.SameContents),
87
// different counts of same items
89
[]int{1, 1, 2}, gc.Not(jc.SameContents),
93
// note: for these tests, we can't use gc.Not, since Not passes the error value through
94
// and checks with a non-empty error always count as failed
95
// Oddly, there doesn't seem to actually be a way to check for an error from a Checker.
98
res, err := jc.SameContents.Check([]interface{}{
102
c.Check(res, jc.IsFalse)
103
c.Check(err, gc.Not(gc.Equals), "")
105
// obtained not a slice
106
res, err = jc.SameContents.Check([]interface{}{
110
c.Check(res, jc.IsFalse)
111
c.Check(err, gc.Not(gc.Equals), "")
113
// expected not a slice
114
res, err = jc.SameContents.Check([]interface{}{
118
c.Check(res, jc.IsFalse)
119
c.Check(err, gc.Not(gc.Equals), "")