3 // Copyright 2009 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // Test equality and inequality operations.
18 func use(b bool) { global = b }
20 func stringptr(s string) uintptr { return *(*uintptr)(unsafe.Pointer(&s)) }
22 func isfalse(b bool) {
24 // stack will explain where
25 panic("wanted false, got true")
31 // stack will explain where
32 panic("wanted true, got false")
46 var c string = "hello"
47 var d string = "hel" // try to get different pointer
50 // go.tools/ssa/interp can't handle unsafe.Pointer.
51 if os.Getenv("GOSSAINTERP") == "" {
52 if stringptr(c) == stringptr(d) {
53 panic("compiler too smart -- got same string")
57 var e = make(chan int)
59 var ia interface{} = a
60 var ib interface{} = b
61 var ic interface{} = c
62 var id interface{} = d
63 var ie interface{} = e
65 // these comparisons are okay because
66 // string compare is okay and the others
67 // are comparisons where the types differ.
84 // these are not okay, because there is no comparison on slices or maps.
118 // gc used to let this go through as true.
121 var ig interface{} = g
122 var ih interface{} = h
126 // map of interface should use == on interface values,
128 var m = make(map[interface{}]int)
132 println("m[c] = ", m[c])
136 // interface comparisons (issue 7207)
150 var e interface{} = X(0)
174 // non-interface comparisons
177 c1 := (<-chan int)(c)
178 c2 := (chan<- int)(c)
205 // named types vs not
257 var m = make(map[struct {
273 var m1 = make(map[struct {
292 var ix, iy, iz interface{} = x, y, z
337 // structs with _ fields
348 var ix interface{} = x
358 var x = [2]string{"1", "hi"}
359 var y = [2]string{"2", "bye"}
360 var z = [2]string{"1", "hi"}
376 var m = make(map[[2]string]int)
387 var ix, iy, iz interface{} = x, y, z
437 type T struct{ data [20]byte }
443 m := make(map[string][10]interface{})
445 istrue(m["x"] == m["y"])
457 var ia interface{} = a
463 var ib interface{} = b
469 var ia interface{} = a
470 var m = make(map[interface{}]int)
476 var ib interface{} = b
477 var m = make(map[interface{}]int)
481 func shouldPanic(f func()) {
483 if recover() == nil {
484 panic("function should panic")