{"eq .Ptr .NilPtr", "false", true},
{"eq .NilPtr .NilPtr", "true", true},
{"eq .Iface1 .Iface1", "true", true},
- {"eq .Iface1 .Iface2", "false", true},
- {"eq .Iface2 .Iface2", "true", true},
+ {"eq .Iface1 .NilIface", "false", true},
+ {"eq .NilIface .NilIface", "true", true},
+ {"eq .NilIface .Iface1", "false", true},
+ {"eq .NilIface 0", "false", true},
+ {"eq 0 .NilIface", "false", true},
// Errors
{"eq `xy` 1", "", false}, // Different types.
{"eq 2 2.0", "", false}, // Different types.
func TestComparison(t *testing.T) {
b := new(bytes.Buffer)
var cmpStruct = struct {
- Uthree, Ufour uint
- NegOne, Three int
- Ptr, NilPtr *int
- Map map[int]int
- V1, V2 V
- Iface1, Iface2 fmt.Stringer
+ Uthree, Ufour uint
+ NegOne, Three int
+ Ptr, NilPtr *int
+ Map map[int]int
+ V1, V2 V
+ Iface1, NilIface fmt.Stringer
}{
Uthree: 3,
Ufour: 4,
case k1 == uintKind && k2 == intKind:
truth = arg.Int() >= 0 && arg1.Uint() == uint64(arg.Int())
default:
- return false, errBadComparison
+ if arg1 != zero && arg != zero {
+ return false, errBadComparison
+ }
}
} else {
switch k1 {
case uintKind:
truth = arg1.Uint() == arg.Uint()
default:
- if arg == zero {
+ if arg == zero || arg1 == zero {
truth = arg1 == arg
} else {
if t2 := arg.Type(); !t2.Comparable() {