When ContainsKey(nil) is used, nil is automatically converted to a
typed nil on the fly to avoid confusion (if the map key type allows
it of course.) So all following Cmp calls are equivalent
(except the (*byte)(nil) one):
t:=&testing.T{}ok:=td.Cmp(t,map[string]int{"foo":11,"bar":22,"zip":33},td.ContainsKey("foo"))fmt.Println(`map contains key "foo":`,ok)ok=td.Cmp(t,map[int]bool{12:true,24:false,42:true,51:false},td.ContainsKey(td.Between(40,50)))fmt.Println("map contains at least a key in [40 .. 50]:",ok)ok=td.Cmp(t,map[string]int{"FOO":11,"bar":22,"zip":33},td.ContainsKey(td.Smuggle(strings.ToLower,"foo")))fmt.Println(`map contains key "foo" without taking case into account:`,ok)// Output:// map contains key "foo": true// map contains at least a key in [40 .. 50]: true// map contains key "foo" without taking case into account: true
args… are optional and allow to name the test. This name is
used in case of failure to qualify the test. If len(args) > 1 and
the first item of args is a string and contains a ‘%’ rune then
fmt.Fprintf is used to compose the name, else args are passed to
fmt.Fprint. Do not forget it is the name of the test, not the
reason of a potential failure.
t:=&testing.T{}ok:=td.CmpContainsKey(t,map[string]int{"foo":11,"bar":22,"zip":33},"foo")fmt.Println(`map contains key "foo":`,ok)ok=td.CmpContainsKey(t,map[int]bool{12:true,24:false,42:true,51:false},td.Between(40,50))fmt.Println("map contains at least a key in [40 .. 50]:",ok)ok=td.CmpContainsKey(t,map[string]int{"FOO":11,"bar":22,"zip":33},td.Smuggle(strings.ToLower,"foo"))fmt.Println(`map contains key "foo" without taking case into account:`,ok)// Output:// map contains key "foo": true// map contains at least a key in [40 .. 50]: true// map contains key "foo" without taking case into account: true
Returns true if the test is OK, false if it fails.
args… are optional and allow to name the test. This name is
used in case of failure to qualify the test. If len(args) > 1 and
the first item of args is a string and contains a ‘%’ rune then
fmt.Fprintf is used to compose the name, else args are passed to
fmt.Fprint. Do not forget it is the name of the test, not the
reason of a potential failure.
t:=td.NewT(&testing.T{})ok:=t.ContainsKey(map[string]int{"foo":11,"bar":22,"zip":33},"foo")fmt.Println(`map contains key "foo":`,ok)ok=t.ContainsKey(map[int]bool{12:true,24:false,42:true,51:false},td.Between(40,50))fmt.Println("map contains at least a key in [40 .. 50]:",ok)ok=t.ContainsKey(map[string]int{"FOO":11,"bar":22,"zip":33},td.Smuggle(strings.ToLower,"foo"))fmt.Println(`map contains key "foo" without taking case into account:`,ok)// Output:// map contains key "foo": true// map contains at least a key in [40 .. 50]: true// map contains key "foo" without taking case into account: true