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.
14 func use(b bool) { global = b }
16 func stringptr(s string) uintptr { return *(*uintptr)(unsafe.Pointer(&s)) }
18 func isfalse(b bool) {
20 // stack will explain where
21 panic("wanted false, got true")
27 // stack will explain where
28 panic("wanted true, got false")
38 var c string = "hello"
39 var d string = "hel" // try to get different pointer
41 if stringptr(c) == stringptr(d) {
42 panic("compiler too smart -- got same string")
45 var e = make(chan int)
47 var ia interface{} = a
48 var ib interface{} = b
49 var ic interface{} = c
50 var id interface{} = d
51 var ie interface{} = e
53 // these comparisons are okay because
54 // string compare is okay and the others
55 // are comparisons where the types differ.
72 // these are not okay, because there is no comparison on slices or maps.
106 // 6g used to let this go through as true.
109 var ig interface{} = g
110 var ih interface{} = h
114 // map of interface should use == on interface values,
116 var m = make(map[interface{}]int)
120 println("m[c] = ", m[c])
124 // non-interface comparisons
127 c1 := (<-chan int)(c)
128 c2 := (chan<- int)(c)
155 // named types vs not
207 var m = make(map[struct {
223 var m1 = make(map[struct {
242 var ix, iy, iz interface{} = x, y, z
287 // structs with _ fields
298 var ix interface{} = x
308 var x = [2]string{"1", "hi"}
309 var y = [2]string{"2", "bye"}
310 var z = [2]string{"1", "hi"}
326 var m = make(map[[2]string]int)
337 var ix, iy, iz interface{} = x, y, z
390 var ia interface{} = a
396 var ib interface{} = b
402 var ia interface{} = a
403 var m = make(map[interface{}]int)
409 var ib interface{} = b
410 var m = make(map[interface{}]int)
414 func shouldPanic(f func()) {
416 if recover() == nil {
417 panic("function should panic")