aboutsummaryrefslogtreecommitdiff
path: root/test/interface
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2010-03-30 10:34:57 -0700
committerRuss Cox <rsc@golang.org>2010-03-30 10:34:57 -0700
commit00f9f0c0560ce35b9d006eacbeeacf897d19a2bf (patch)
treed56b07c89674ed7162eb30f924600574d0cf464b /test/interface
parent5d0ec6c076978846f7cbbf4bd2c0dc55d946b0f9 (diff)
downloadgo-00f9f0c0560ce35b9d006eacbeeacf897d19a2bf.tar.gz
go-00f9f0c0560ce35b9d006eacbeeacf897d19a2bf.zip
single argument panic
note that sortmain.go has been run through hg gofmt; only the formatting of the day initializers changed. i'm happy to revert that formatting if you'd prefer. stop on error in doc/progs/run R=r CC=golang-dev https://golang.org/cl/850041
Diffstat (limited to 'test/interface')
-rw-r--r--test/interface/convert.go116
-rw-r--r--test/interface/receiver.go3
2 files changed, 64 insertions, 55 deletions
diff --git a/test/interface/convert.go b/test/interface/convert.go
index bc219c72f5..7f429f7031 100644
--- a/test/interface/convert.go
+++ b/test/interface/convert.go
@@ -9,21 +9,28 @@
package main
-type Stringer interface { String() string }
-type StringLengther interface { String() string; Length() int }
-type Empty interface { }
+type Stringer interface {
+ String() string
+}
+type StringLengther interface {
+ String() string
+ Length() int
+}
+type Empty interface{}
type T string
+
func (t T) String() string {
- return string(t);
+ return string(t)
}
func (t T) Length() int {
- return len(t);
+ return len(t)
}
type U string
+
func (u U) String() string {
- return string(u);
+ return string(u)
}
var t = T("hello")
@@ -36,104 +43,105 @@ var ok bool
func hello(s string) {
if s != "hello" {
- panic("not hello: ", s);
+ println("not hello: ", s)
+ panic("fail")
}
}
func five(i int) {
if i != 5 {
- panic("not 5: ", i);
+ println("not 5: ", i)
+ panic("fail")
}
}
func true(ok bool) {
if !ok {
- panic("not true");
+ panic("not true")
}
}
func false(ok bool) {
if ok {
- panic("not false");
+ panic("not false")
}
}
func main() {
// T2I
- s = t;
- hello(s.String());
+ s = t
+ hello(s.String())
// I2T
- t = s.(T);
- hello(t.String());
+ t = s.(T)
+ hello(t.String())
// T2E
- e = t;
+ e = t
// E2T
- t = e.(T);
- hello(t.String());
+ t = e.(T)
+ hello(t.String())
// T2I again
- sl = t;
- hello(sl.String());
- five(sl.Length());
+ sl = t
+ hello(sl.String())
+ five(sl.Length())
// I2I static
- s = sl;
- hello(s.String());
+ s = sl
+ hello(s.String())
// I2I dynamic
- sl = s.(StringLengther);
- hello(sl.String());
- five(sl.Length());
+ sl = s.(StringLengther)
+ hello(sl.String())
+ five(sl.Length())
// I2E (and E2T)
- e = s;
- hello(e.(T).String());
+ e = s
+ hello(e.(T).String())
// E2I
- s = e.(Stringer);
- hello(s.String());
+ s = e.(Stringer)
+ hello(s.String())
// I2T2 true
- t, ok = s.(T);
- true(ok);
- hello(t.String());
+ t, ok = s.(T)
+ true(ok)
+ hello(t.String())
// I2T2 false
- _, ok = s.(U);
- false(ok);
+ _, ok = s.(U)
+ false(ok)
// I2I2 true
- sl, ok = s.(StringLengther);
- true(ok);
- hello(sl.String());
- five(sl.Length());
+ sl, ok = s.(StringLengther)
+ true(ok)
+ hello(sl.String())
+ five(sl.Length())
// I2I2 false (and T2I)
- s = u;
- sl, ok = s.(StringLengther);
- false(ok);
+ s = u
+ sl, ok = s.(StringLengther)
+ false(ok)
// E2T2 true
- t, ok = e.(T);
- true(ok);
- hello(t.String());
+ t, ok = e.(T)
+ true(ok)
+ hello(t.String())
// E2T2 false
- i, ok = e.(int);
- false(ok);
+ i, ok = e.(int)
+ false(ok)
// E2I2 true
- sl, ok = e.(StringLengther);
- true(ok);
- hello(sl.String());
- five(sl.Length());
+ sl, ok = e.(StringLengther)
+ true(ok)
+ hello(sl.String())
+ five(sl.Length())
// E2I2 false (and T2E)
- e = u;
- sl, ok = e.(StringLengther);
- false(ok);
+ e = u
+ sl, ok = e.(StringLengther)
+ false(ok)
}
-
diff --git a/test/interface/receiver.go b/test/interface/receiver.go
index 59f3986d7f..f74cecb2c8 100644
--- a/test/interface/receiver.go
+++ b/test/interface/receiver.go
@@ -22,7 +22,8 @@ func (t T) V() {
func (t *T) P() {
if *t != 42 {
- panic(t, *t)
+ println(t, *t)
+ panic("fail")
}
np++
}