mirror of
https://github.com/golang/go
synced 2024-11-18 16:14:46 -07:00
1f6463f823
import ( "vector" -> "container/vector" "ast" -> "go/ast" "sha1" -> "hash/sha1" etc. ) and update Makefiles. Because I did the conversion semi-automatically, I sorted all the import blocks as a post-processing. Some files have therefore changed that didn't strictly need to. Rename local packages to lower case. The upper/lower distinction doesn't work on OS X and complicates the "single-package directories with the same package name as directory name" heuristic used by gobuild and godoc to create the correlation between source and binary locations. Now that we have a plan to avoid globally unique names, the upper/lower is unnecessary. The renamings will cause trouble for a few users, but so will the change in import paths. This way, the two maintenance fixes are rolled into one inconvenience. R=r OCL=27573 CL=27575
123 lines
2.0 KiB
Go
123 lines
2.0 KiB
Go
// $G $D/$F.go && $L $F.$A && ./$A.out
|
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt";
|
|
"os";
|
|
)
|
|
|
|
type T struct {
|
|
a float64;
|
|
b int64;
|
|
c string;
|
|
d byte;
|
|
}
|
|
|
|
var a = []int{ 1, 2, 3 }
|
|
var NIL []int;
|
|
|
|
func arraycmptest() {
|
|
a1 := a;
|
|
if NIL != nil {
|
|
println("fail1:", NIL, "!= nil");
|
|
}
|
|
if nil != NIL {
|
|
println("fail2: nil !=", NIL);
|
|
}
|
|
if a == nil || nil == a {
|
|
println("fail3:", a, "== nil");
|
|
}
|
|
}
|
|
|
|
func SameArray(a, b []int) bool {
|
|
if len(a) != len(b) || cap(a) != cap(b) {
|
|
return false;
|
|
}
|
|
if len(a) > 0 && &a[0] != &b[0] {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
var t = T{1.5, 123, "hello", 255}
|
|
var mt = make(map[int]T)
|
|
var ma = make(map[int][]int)
|
|
|
|
func maptest() {
|
|
mt[0] = t;
|
|
t1 := mt[0];
|
|
if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d {
|
|
println("fail: map val struct", t1.a, t1.b, t1.c, t1.d);
|
|
}
|
|
|
|
ma[1] = a;
|
|
a1 := ma[1];
|
|
if !SameArray(a, a1) {
|
|
println("fail: map val array", a, a1);
|
|
}
|
|
}
|
|
|
|
var ct = make(chan T)
|
|
var ca = make(chan []int)
|
|
|
|
func send() {
|
|
ct <- t;
|
|
ca <- a;
|
|
}
|
|
|
|
func chantest() {
|
|
go send();
|
|
|
|
t1 := <-ct;
|
|
if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d {
|
|
println("fail: map val struct", t1.a, t1.b, t1.c, t1.d);
|
|
}
|
|
|
|
a1 := <-ca;
|
|
if !SameArray(a, a1) {
|
|
println("fail: map val array", a, a1);
|
|
}
|
|
}
|
|
|
|
type E struct { }
|
|
var e E
|
|
|
|
func interfacetest() {
|
|
var i interface{};
|
|
|
|
i = a;
|
|
a1 := i.([]int);
|
|
if !SameArray(a, a1) {
|
|
println("interface <-> []int", a, a1);
|
|
}
|
|
pa := new([]int);
|
|
*pa = a;
|
|
i = pa;
|
|
a1 = *i.(*[]int);
|
|
if !SameArray(a, a1) {
|
|
println("interface <-> *[]int", a, a1);
|
|
}
|
|
|
|
i = t;
|
|
t1 := i.(T);
|
|
if t1.a != t.a || t1.b != t.b || t1.c != t.c || t1.d != t.d {
|
|
println("interface <-> struct", t1.a, t1.b, t1.c, t1.d);
|
|
}
|
|
|
|
i = e;
|
|
e1 := i.(E);
|
|
// nothing to check; just verify it doesn't crash
|
|
}
|
|
|
|
func main() {
|
|
arraycmptest();
|
|
maptest();
|
|
chantest();
|
|
interfacetest();
|
|
}
|