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")
42 var c string = "hello"
43 var d string = "hel" // try to get different pointer
46 // go.tools/ssa/interp can't handle unsafe.Pointer.
47 if os.Getenv("GOSSAINTERP") == "" {
48 if stringptr(c) == stringptr(d) {
49 panic("compiler too smart -- got same string")
53 var e = make(chan int)
55 var ia interface{} = a
56 var ib interface{} = b
57 var ic interface{} = c
58 var id interface{} = d
59 var ie interface{} = e
61 // these comparisons are okay because
62 // string compare is okay and the others
63 // are comparisons where the types differ.
80 // these are not okay, because there is no comparison on slices or maps.
114 // 6g used to let this go through as true.
117 var ig interface{} = g
118 var ih interface{} = h
122 // map of interface should use == on interface values,
124 var m = make(map[interface{}]int)
128 println("m[c] = ", m[c])
132 // non-interface comparisons
135 c1 := (<-chan int)(c)
136 c2 := (chan<- int)(c)
163 // named types vs not
215 var m = make(map[struct {
231 var m1 = make(map[struct {
250 var ix, iy, iz interface{} = x, y, z
295 // structs with _ fields
306 var ix interface{} = x
316 var x = [2]string{"1", "hi"}
317 var y = [2]string{"2", "bye"}
318 var z = [2]string{"1", "hi"}
334 var m = make(map[[2]string]int)
345 var ix, iy, iz interface{} = x, y, z
398 var ia interface{} = a
404 var ib interface{} = b
410 var ia interface{} = a
411 var m = make(map[interface{}]int)
417 var ib interface{} = b
418 var m = make(map[interface{}]int)
422 func shouldPanic(f func()) {
424 if recover() == nil {
425 panic("function should panic")