]> Cypherpunks.ru repositories - gostls13.git/blob - test/reorder2.go
test: use testlib (final 61)
[gostls13.git] / test / reorder2.go
1 // run
2
3 // Copyright 2010 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.
6
7 // derived from fixedbugs/bug294.go
8
9 package main
10
11 var log string
12
13 type TT int
14
15 func (t TT) a(s string) TT {
16         log += "a(" + s + ")"
17         return t
18 }
19
20 func (TT) b(s string) string {
21         log += "b(" + s + ")"
22         return s
23 }
24
25 type F func(s string) F
26
27 func a(s string) F {
28         log += "a(" + s + ")"
29         return F(a)
30 }
31
32 func b(s string) string {
33         log += "b(" + s + ")"
34         return s
35 }
36
37 type I interface {
38         a(s string) I
39         b(s string) string
40 }
41
42 type T1 int
43
44 func (t T1) a(s string) I {
45         log += "a(" + s + ")"
46         return t
47 }
48
49 func (T1) b(s string) string {
50         log += "b(" + s + ")"
51         return s
52 }
53
54 // f(g(), h()) where g is not inlinable but h is will have the same problem.
55 // As will x := g() + h() (same conditions).
56 // And g() <- h().
57 func f(x, y string) {
58         log += "f(" + x + ", " + y + ")"
59 }
60
61 func ff(x, y string) {
62         for false {
63         } // prevent inl
64         log += "ff(" + x + ", " + y + ")"
65 }
66
67 func h(x string) string {
68         log += "h(" + x + ")"
69         return x
70 }
71
72 func g(x string) string {
73         for false {
74         } // prevent inl
75         log += "g(" + x + ")"
76         return x
77 }
78
79 func main() {
80         err := 0
81         var t TT
82         if a("1")("2")("3"); log != "a(1)a(2)a(3)" {
83                 println("expecting a(1)a(2)a(3) , got ", log)
84                 err++
85         }
86         log = ""
87
88         if t.a("1").a(t.b("2")); log != "a(1)b(2)a(2)" {
89                 println("expecting a(1)b(2)a(2), got ", log)
90                 err++
91         }
92         log = ""
93         if a("3")(b("4"))(b("5")); log != "a(3)b(4)a(4)b(5)a(5)" {
94                 println("expecting a(3)b(4)a(4)b(5)a(5), got ", log)
95                 err++
96         }
97         log = ""
98         var i I = T1(0)
99         if i.a("6").a(i.b("7")).a(i.b("8")).a(i.b("9")); log != "a(6)b(7)a(7)b(8)a(8)b(9)a(9)" {
100                 println("expecting a(6)ba(7)ba(8)ba(9), got", log)
101                 err++
102         }
103         log = ""
104
105         if s := t.a("1").b("3"); log != "a(1)b(3)" || s != "3" {
106                 println("expecting a(1)b(3) and 3, got ", log, " and ", s)
107                 err++
108         }
109         log = ""
110
111         if s := t.a("1").a(t.b("2")).b("3") + t.a("4").b("5"); log != "a(1)b(2)a(2)b(3)a(4)b(5)" || s != "35" {
112                 println("expecting a(1)b(2)a(2)b(3)a(4)b(5) and 35, got ", log, " and ", s)
113                 err++
114         }
115         log = ""
116
117         if s := t.a("4").b("5") + t.a("1").a(t.b("2")).b("3"); log != "a(4)b(5)a(1)b(2)a(2)b(3)" || s != "53" {
118                 println("expecting a(4)b(5)a(1)b(2)a(2)b(3) and 35, got ", log, " and ", s)
119                 err++
120         }
121         log = ""
122
123         if ff(g("1"), g("2")); log != "g(1)g(2)ff(1, 2)" {
124                 println("expecting g(1)g(2)ff..., got ", log)
125                 err++
126         }
127         log = ""
128
129         if ff(g("1"), h("2")); log != "g(1)h(2)ff(1, 2)" {
130                 println("expecting g(1)h(2)ff..., got ", log)
131                 err++
132         }
133         log = ""
134
135         if ff(h("1"), g("2")); log != "h(1)g(2)ff(1, 2)" {
136                 println("expecting h(1)g(2)ff..., got ", log)
137                 err++
138         }
139         log = ""
140
141         if ff(h("1"), h("2")); log != "h(1)h(2)ff(1, 2)" {
142                 println("expecting h(1)h(2)ff..., got ", log)
143                 err++
144         }
145         log = ""
146
147         if s := g("1") + g("2"); log != "g(1)g(2)" || s != "12" {
148                 println("expecting g1g2 and 12, got ", log, " and ", s)
149                 err++
150         }
151         log = ""
152
153         if s := g("1") + h("2"); log != "g(1)h(2)" || s != "12" {
154                 println("expecting g1h2 and 12, got ", log, " and ", s)
155                 err++
156         }
157         log = ""
158
159         if s := h("1") + g("2"); log != "h(1)g(2)" || s != "12" {
160                 println("expecting h1g2 and 12, got ", log, " and ", s)
161                 err++
162         }
163         log = ""
164
165         if s := h("1") + h("2"); log != "h(1)h(2)" || s != "12" {
166                 println("expecting h1h2 and 12, got ", log, " and ", s)
167                 err++
168         }
169         log = ""
170
171         if err > 0 {
172                 panic("fail")
173         }
174 }