Debian Codegraph @

checkers2_test.go

raw symbols SCIP
1 package check_test
2
3 import (
4 "time"
5
6 "github.com/pingcap/check"
7 )
8
9 func testHasKey(c *check.C, expectedResult bool, expectedErr string, params ...interface{}) {
10 actualResult, actualErr := check.HasKey.Check(params, nil)
11 if actualResult != expectedResult || actualErr != expectedErr {
12 c.Fatalf(
13 "Check returned (%#v, %#v) rather than (%#v, %#v)",
14 actualResult, actualErr, expectedResult, expectedErr)
15 }
16 }
17
18 func (s *CheckersS) TestHasKey(c *check.C) {
19 testHasKey(c, true, "", map[string]int{"foo": 1}, "foo")
20 testHasKey(c, false, "", map[string]int{"foo": 1}, "bar")
21 testHasKey(c, true, "", map[int][]byte{10: nil}, 10)
22
23 testHasKey(c, false, "First argument to HasKey must be a map", nil, "bar")
24 testHasKey(
25 c, false, "Second argument must be assignable to the map key type",
26 map[string]int{"foo": 1}, 10)
27 }
28
29 func (s *CheckersS) TestCompare(c *check.C) {
30 c.Assert(10, check.Less, 11)
31 c.Assert(10, check.LessEqual, 10)
32 c.Assert(10, check.Greater, 9)
33 c.Assert(10, check.GreaterEqual, 10)
34 c.Assert(10, check.Not(check.LessEqual), 9)
35 c.Assert(10, check.Not(check.Less), 9)
36 c.Assert("ABC", check.Less, "ABCD")
37 c.Assert([]byte("ABC"), check.Less, []byte("ABCD"))
38 c.Assert(3.14, check.Less, 3.145)
39 c.Assert(time.Duration(1), check.Greater, time.Duration(0))
40 c.Assert(time.Now(), check.Less, time.Now().Add(10*time.Second))
41 }
42
43 func (s *CheckersS) TestBytes(c *check.C) {
44 c.Assert([]byte{0x00}, check.BytesEquals, []byte{0x00})
45 c.Assert([]byte{0x00}, check.Not(check.BytesEquals), []byte{0x01})
46 }