LEFT | RIGHT |
(no file at all) | |
1 // $G $F.go && $L $F.$A && ./$A.out | 1 // $G $F.go && $L $F.$A && ./$A.out |
2 | 2 |
3 // Copyright 2009 The Go Authors. All rights reserved. | 3 // Copyright 2009 The Go Authors. All rights reserved. |
4 // Use of this source code is governed by a BSD-style | 4 // Use of this source code is governed by a BSD-style |
5 // license that can be found in the LICENSE file. | 5 // license that can be found in the LICENSE file. |
6 | 6 |
7 package main | 7 package main |
8 | 8 |
9 type T struct { | 9 type T struct { |
10 i int | 10 i int |
(...skipping 13 matching lines...) Expand all Loading... |
24 } | 24 } |
25 | 25 |
26 func eq(a []*R) { | 26 func eq(a []*R) { |
27 for i := 0; i < len(a); i++ { | 27 for i := 0; i < len(a); i++ { |
28 if a[i].num != i { | 28 if a[i].num != i { |
29 panic("bad") | 29 panic("bad") |
30 } | 30 } |
31 } | 31 } |
32 } | 32 } |
33 | 33 |
| 34 func teq(t *T, n int) { |
| 35 for i := 0; i < n; i++ { |
| 36 if t == nil || t.i != i { |
| 37 panic("bad") |
| 38 } |
| 39 t = t.next |
| 40 } |
| 41 if t != nil { |
| 42 panic("bad") |
| 43 } |
| 44 } |
| 45 |
34 type P struct { | 46 type P struct { |
35 a, b int | 47 a, b int |
36 } | 48 } |
37 | 49 |
38 func NewP(a, b int) *P { | 50 func NewP(a, b int) *P { |
39 return &P{a, b} | 51 return &P{a, b} |
40 } | 52 } |
41 | 53 |
42 func main() { | 54 func main() { |
43 var t T | 55 var t T |
44 t = T{0, 7.2, "hi", &t} | 56 t = T{0, 7.2, "hi", &t} |
45 | 57 |
46 var tp *T | 58 var tp *T |
47 tp = &T{0, 7.2, "hi", &t} | 59 tp = &T{0, 7.2, "hi", &t} |
| 60 |
| 61 tl := &T{i: 0, next: {i: 1, next: {i: 2, next: {i: 3, next: {i: 4}}}}} |
| 62 teq(tl, 5) |
48 | 63 |
49 a1 := []int{1, 2, 3} | 64 a1 := []int{1, 2, 3} |
50 if len(a1) != 3 { | 65 if len(a1) != 3 { |
51 panic("a1") | 66 panic("a1") |
52 } | 67 } |
53 a2 := [10]int{1, 2, 3} | 68 a2 := [10]int{1, 2, 3} |
54 if len(a2) != 10 || cap(a2) != 10 { | 69 if len(a2) != 10 || cap(a2) != 10 { |
55 panic("a2") | 70 panic("a2") |
56 } | 71 } |
57 | 72 |
(...skipping 28 matching lines...) Expand all Loading... |
86 if s != "hello" { | 101 if s != "hello" { |
87 panic("s") | 102 panic("s") |
88 } | 103 } |
89 | 104 |
90 m := map[string]float64{"one": 1.0, "two": 2.0, "pi": 22. / 7.} | 105 m := map[string]float64{"one": 1.0, "two": 2.0, "pi": 22. / 7.} |
91 if len(m) != 3 { | 106 if len(m) != 3 { |
92 panic("m") | 107 panic("m") |
93 } | 108 } |
94 | 109 |
95 eq([]*R{itor(0), itor(1), itor(2), itor(3), itor(4), itor(5)}) | 110 eq([]*R{itor(0), itor(1), itor(2), itor(3), itor(4), itor(5)}) |
| 111 eq([]*R{{0}, {1}, {2}, {3}, {4}, {5}}) |
96 | 112 |
97 p1 := NewP(1, 2) | 113 p1 := NewP(1, 2) |
98 p2 := NewP(1, 2) | 114 p2 := NewP(1, 2) |
99 if p1 == p2 { | 115 if p1 == p2 { |
100 panic("NewP") | 116 panic("NewP") |
101 } | 117 } |
102 } | 118 } |
LEFT | RIGHT |