File: bool.go

package info (click to toggle)
golang-github-vdemeester-shakers 0.0~git20160210.0.24d7f1d-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 192 kB
  • ctags: 158
  • sloc: sh: 159; makefile: 25
file content (46 lines) | stat: -rw-r--r-- 882 bytes parent folder | download | duplicates (3)
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
package shakers

import (
	"github.com/go-check/check"
)

// True checker verifies the obtained value is true
//
//    c.Assert(myBool, True)
//
var True check.Checker = &boolChecker{
	&check.CheckerInfo{
		Name:   "True",
		Params: []string{"obtained"},
	},
	true,
}

// False checker verifies the obtained value is false
//
//    c.Assert(myBool, False)
//
var False check.Checker = &boolChecker{
	&check.CheckerInfo{
		Name:   "False",
		Params: []string{"obtained"},
	},
	false,
}

type boolChecker struct {
	*check.CheckerInfo
	expected bool
}

func (checker *boolChecker) Check(params []interface{}, names []string) (bool, string) {
	return is(checker.expected, params[0])
}

func is(expected bool, obtained interface{}) (bool, string) {
	obtainedBool, ok := obtained.(bool)
	if !ok {
		return false, "obtained value must be a bool."
	}
	return obtainedBool == expected, ""
}