mirror of
https://github.com/golang/go
synced 2025-04-20 01:10:30 +00:00
.github
api
doc
lib
misc
src
test
abi
alias3.dir
arenas
asmhdr.dir
chan
closure3.dir
closure5.dir
codegen
ddd2.dir
dwarf
fixedbugs
import2.dir
import4.dir
interface
intrinsic.dir
ken
array.go
chan.go
chan1.go
complit.go
convert.go
cplx0.go
cplx0.out
cplx1.go
cplx2.go
cplx3.go
cplx4.go
cplx5.go
divconst.go
divmod.go
embed.go
for.go
interbasic.go
interfun.go
intervar.go
label.go
litfun.go
mfunc.go
modconst.go
ptrfun.go
ptrvar.go
range.go
rob1.go
rob2.go
robfor.go
robfunc.go
shift.go
simparray.go
simpbool.go
simpconv.go
simpfun.go
simpswitch.go
simpvar.go
slicearray.go
sliceslice.go
string.go
string.out
strvar.go
linkname.dir
linknameasm.dir
method4.dir
retjmp.dir
runtime
stress
syntax
typeparam
uintptrescapes.dir
235.go
64bit.go
README.md
alg.go
alias.go
alias1.go
alias2.go
alias3.go
align.go
append.go
append1.go
args.go
armimm.go
asmhdr.go
assign.go
assign1.go
atomicload.go
bigalg.go
bigmap.go
blank.go
blank1.go
bom.go
bombad.go
bounds.go
cannotassign.go
chancap.go
chanlinear.go
char_lit.go
char_lit1.go
checkbce.go
clear.go
clearfat.go
closedchan.go
closure.go
closure1.go
closure2.go
closure3.go
closure4.go
closure5.go
closure6.go
closure7.go
cmp.go
cmp6.go
cmplx.go
cmplxdivide.c
cmplxdivide.go
cmplxdivide1.go
complit.go
complit1.go
compos.go
const.go
const1.go
const2.go
const3.go
const4.go
const5.go
const6.go
const7.go
const8.go
convT2X.go
convert.go
convert1.go
convert2.go
convert3.go
convert4.go
convinline.go
convlit.go
convlit1.go
copy.go
copy1.go
crlf.go
ddd.go
ddd1.go
ddd2.go
decl.go
declbad.go
defer.go
defererrcheck.go
deferfin.go
defernil.go
deferprint.go
deferprint.out
devirt.go
directive.go
directive2.go
divide.go
divmod.go
embedfunc.go
embedvers.go
empty.go
env.go
eof.go
eof1.go
escape.go
escape2.go
escape2n.go
escape3.go
escape4.go
escape5.go
escape_array.go
escape_calls.go
escape_closure.go
escape_field.go
escape_goto.go
escape_hash_maphash.go
escape_iface.go
escape_indir.go
escape_level.go
escape_map.go
escape_mutations.go
escape_param.go
escape_reflect.go
escape_runtime_atomic.go
escape_selfassign.go
escape_slice.go
escape_struct_param1.go
escape_struct_param2.go
escape_struct_return.go
escape_sync_atomic.go
escape_unsafe.go
fibo.go
finprofiled.go
float_lit.go
float_lit2.go
float_lit3.go
floatcmp.go
for.go
func.go
func1.go
func2.go
func3.go
func4.go
func5.go
func6.go
func7.go
func8.go
funcdup.go
funcdup2.go
fuse.go
gc.go
gc1.go
gc2.go
gcgort.go
gcstring.go
goprint.go
goprint.out
goto.go
heapsampling.go
helloworld.go
helloworld.out
if.go
import.go
import1.go
import2.go
import4.go
import5.go
import6.go
index.go
index0.go
index1.go
index2.go
indirect.go
indirect1.go
init.go
init1.go
initcomma.go
initexp.go
initialize.go
initializerr.go
initloop.go
inline.go
inline_big.go
inline_caller.go
inline_callers.go
inline_endian.go
inline_literal.go
inline_math_bits_rotate.go
inline_sync.go
inline_variadic.go
int_lit.go
intcvt.go
intrinsic.go
intrinsic_atomic.go
iota.go
label.go
label1.go
linkmain.go
linkmain_run.go
linkname.go
linkname3.go
linknameasm.go
linkobj.go
linkx.go
linkx_run.go
literal.go
literal2.go
live.go
live1.go
live2.go
live_regabi.go
live_uintptrkeepalive.go
loopbce.go
mainsig.go
makechan.go
makemap.go
makenew.go
makeslice.go
mallocfin.go
map.go
map1.go
mapclear.go
maplinear.go
maymorestack.go
mergemul.go
method.go
method1.go
method2.go
method3.go
method4.go
method5.go
method6.go
method7.go
named.go
named1.go
newinline.go
nil.go
nilcheck.go
nilptr.go
nilptr2.go
nilptr3.go
nilptr4.go
nilptr5.go
nilptr5_aix.go
nilptr5_wasm.go
nilptr_aix.go
noinit.go
nosplit.go
nowritebarrier.go
nul1.go
opt_branchlikely.go
parentype.go
peano.go
phiopt.go
print.go
print.out
printbig.go
printbig.out
prove.go
prove_constant_folding.go
prove_invert_loop_with_unused_iterators.go
range.go
range2.go
range3.go
range4.go
rangegen.go
recover.go
recover1.go
recover2.go
recover3.go
recover4.go
recover5.go
reflectmethod1.go
reflectmethod2.go
reflectmethod3.go
reflectmethod4.go
reflectmethod5.go
reflectmethod6.go
reflectmethod7.go
reflectmethod8.go
rename.go
rename1.go
reorder.go
reorder2.go
retjmp.go
return.go
rotate.go
rotate0.go
rotate1.go
rotate2.go
rotate3.go
rune.go
runtime.go
shift1.go
shift2.go
shift3.go
sieve.go
sigchld.go
sigchld.out
simassign.go
sizeof.go
slice3.go
slice3err.go
slicecap.go
sliceopt.go
solitaire.go
stack.go
stackobj.go
stackobj2.go
stackobj3.go
strcopy.go
strength.go
string_lit.go
stringrange.go
struct0.go
switch.go
switch2.go
switch3.go
switch4.go
switch5.go
switch6.go
switch7.go
tighten.go
tinyfin.go
torture.go
turing.go
typecheck.go
typecheckloop.go
typeswitch.go
typeswitch1.go
typeswitch2.go
typeswitch2b.go
typeswitch3.go
uintptrescapes.go
uintptrescapes2.go
uintptrescapes3.go
uintptrkeepalive.go
undef.go
unsafe_slice_data.go
unsafe_string.go
unsafe_string_data.go
unsafebuiltins.go
used.go
utf.go
varerr.go
varinit.go
winbatch.go
writebarrier.go
zerodivide.go
zerosize.go
.gitattributes
.gitignore
CONTRIBUTING.md
LICENSE
PATENTS
README.md
SECURITY.md
VERSION
codereview.cfg
go.env
173 lines
4.3 KiB
Go
173 lines
4.3 KiB
Go
// run
|
|
|
|
// 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.
|
|
|
|
// Test composite literals.
|
|
|
|
package main
|
|
|
|
type M map[int]int
|
|
type S struct{ a,b,c int };
|
|
type SS struct{ aa,bb,cc S };
|
|
type SA struct{ a,b,c [3]int };
|
|
type SC struct{ a,b,c []int };
|
|
type SM struct{ a,b,c M };
|
|
|
|
func
|
|
main() {
|
|
test("s.a", s.a);
|
|
test("s.b", s.b);
|
|
test("s.c", s.c);
|
|
|
|
test("ss.aa.a", ss.aa.a);
|
|
test("ss.aa.b", ss.aa.b);
|
|
test("ss.aa.c", ss.aa.c);
|
|
|
|
test("ss.bb.a", ss.bb.a);
|
|
test("ss.bb.b", ss.bb.b);
|
|
test("ss.bb.c", ss.bb.c);
|
|
|
|
test("ss.cc.a", ss.cc.a);
|
|
test("ss.cc.b", ss.cc.b);
|
|
test("ss.cc.c", ss.cc.c);
|
|
|
|
for i:=0; i<3; i++ {
|
|
test("a[i]", a[i]);
|
|
test("c[i]", c[i]);
|
|
test("m[i]", m[i]);
|
|
|
|
test("as[i].a", as[i].a);
|
|
test("as[i].b", as[i].b);
|
|
test("as[i].c", as[i].c);
|
|
|
|
test("cs[i].a", cs[i].a);
|
|
test("cs[i].b", cs[i].b);
|
|
test("cs[i].c", cs[i].c);
|
|
|
|
test("ms[i].a", ms[i].a);
|
|
test("ms[i].b", ms[i].b);
|
|
test("ms[i].c", ms[i].c);
|
|
|
|
test("sa.a[i]", sa.a[i]);
|
|
test("sa.b[i]", sa.b[i]);
|
|
test("sa.c[i]", sa.c[i]);
|
|
|
|
test("sc.a[i]", sc.a[i]);
|
|
test("sc.b[i]", sc.b[i]);
|
|
test("sc.c[i]", sc.c[i]);
|
|
|
|
test("sm.a[i]", sm.a[i]);
|
|
test("sm.b[i]", sm.b[i]);
|
|
test("sm.c[i]", sm.c[i]);
|
|
|
|
for j:=0; j<3; j++ {
|
|
test("aa[i][j]", aa[i][j]);
|
|
test("ac[i][j]", ac[i][j]);
|
|
test("am[i][j]", am[i][j]);
|
|
test("ca[i][j]", ca[i][j]);
|
|
test("cc[i][j]", cc[i][j]);
|
|
test("cm[i][j]", cm[i][j]);
|
|
test("ma[i][j]", ma[i][j]);
|
|
test("mc[i][j]", mc[i][j]);
|
|
test("mm[i][j]", mm[i][j]);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
var ref = 0;
|
|
|
|
func
|
|
test(xs string, x int) {
|
|
|
|
if ref >= len(answers) {
|
|
println(xs, x);
|
|
return;
|
|
}
|
|
|
|
if x != answers[ref] {
|
|
println(xs, "is", x, "should be", answers[ref])
|
|
}
|
|
ref++;
|
|
}
|
|
|
|
|
|
var a = [3]int{1001, 1002, 1003}
|
|
var s = S{1101, 1102, 1103}
|
|
var c = []int{1201, 1202, 1203}
|
|
var m = M{0:1301, 1:1302, 2:1303}
|
|
|
|
var aa = [3][3]int{[3]int{2001,2002,2003}, [3]int{2004,2005,2006}, [3]int{2007,2008,2009}}
|
|
var as = [3]S{S{2101,2102,2103},S{2104,2105,2106},S{2107,2108,2109}}
|
|
var ac = [3][]int{[]int{2201,2202,2203}, []int{2204,2205,2206}, []int{2207,2208,2209}}
|
|
var am = [3]M{M{0:2301,1:2302,2:2303}, M{0:2304,1:2305,2:2306}, M{0:2307,1:2308,2:2309}}
|
|
|
|
var sa = SA{[3]int{3001,3002,3003},[3]int{3004,3005,3006},[3]int{3007,3008,3009}}
|
|
var ss = SS{S{3101,3102,3103},S{3104,3105,3106},S{3107,3108,3109}}
|
|
var sc = SC{[]int{3201,3202,3203},[]int{3204,3205,3206},[]int{3207,3208,3209}}
|
|
var sm = SM{M{0:3301,1:3302,2:3303}, M{0:3304,1:3305,2:3306}, M{0:3307,1:3308,2:3309}}
|
|
|
|
var ca = [][3]int{[3]int{4001,4002,4003}, [3]int{4004,4005,4006}, [3]int{4007,4008,4009}}
|
|
var cs = []S{S{4101,4102,4103},S{4104,4105,4106},S{4107,4108,4109}}
|
|
var cc = [][]int{[]int{4201,4202,4203}, []int{4204,4205,4206}, []int{4207,4208,4209}}
|
|
var cm = []M{M{0:4301,1:4302,2:4303}, M{0:4304,1:4305,2:4306}, M{0:4307,1:4308,2:4309}}
|
|
|
|
var ma = map[int][3]int{0:[3]int{5001,5002,5003}, 1:[3]int{5004,5005,5006}, 2:[3]int{5007,5008,5009}}
|
|
var ms = map[int]S{0:S{5101,5102,5103},1:S{5104,5105,5106},2:S{5107,5108,5109}}
|
|
var mc = map[int][]int{0:[]int{5201,5202,5203}, 1:[]int{5204,5205,5206}, 2:[]int{5207,5208,5209}}
|
|
var mm = map[int]M{0:M{0:5301,1:5302,2:5303}, 1:M{0:5304,1:5305,2:5306}, 2:M{0:5307,1:5308,2:5309}}
|
|
|
|
var answers = [...]int {
|
|
// s
|
|
1101, 1102, 1103,
|
|
|
|
// ss
|
|
3101, 3102, 3103,
|
|
3104, 3105, 3106,
|
|
3107, 3108, 3109,
|
|
|
|
// [0]
|
|
1001, 1201, 1301,
|
|
2101, 2102, 2103,
|
|
4101, 4102, 4103,
|
|
5101, 5102, 5103,
|
|
3001, 3004, 3007,
|
|
3201, 3204, 3207,
|
|
3301, 3304, 3307,
|
|
|
|
// [0][j]
|
|
2001, 2201, 2301, 4001, 4201, 4301, 5001, 5201, 5301,
|
|
2002, 2202, 2302, 4002, 4202, 4302, 5002, 5202, 5302,
|
|
2003, 2203, 2303, 4003, 4203, 4303, 5003, 5203, 5303,
|
|
|
|
// [1]
|
|
1002, 1202, 1302,
|
|
2104, 2105, 2106,
|
|
4104, 4105, 4106,
|
|
5104, 5105, 5106,
|
|
3002, 3005, 3008,
|
|
3202, 3205, 3208,
|
|
3302, 3305, 3308,
|
|
|
|
// [1][j]
|
|
2004, 2204, 2304, 4004, 4204, 4304, 5004, 5204, 5304,
|
|
2005, 2205, 2305, 4005, 4205, 4305, 5005, 5205, 5305,
|
|
2006, 2206, 2306, 4006, 4206, 4306, 5006, 5206, 5306,
|
|
|
|
// [2]
|
|
1003, 1203, 1303,
|
|
2107, 2108, 2109,
|
|
4107, 4108, 4109,
|
|
5107, 5108, 5109,
|
|
3003, 3006, 3009,
|
|
3203, 3206, 3209,
|
|
3303, 3306, 3309,
|
|
|
|
// [2][j]
|
|
2007, 2207, 2307, 4007, 4207, 4307, 5007, 5207, 5307,
|
|
2008, 2208, 2308, 4008, 4208, 4308, 5008, 5208, 5308,
|
|
2009, 2209, 2309, 4009, 4209, 4309, 5009, 5209, 5309,
|
|
}
|