From 74119689619c24f5871056d13d07d56f69ad5f60 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 30 Mar 2010 10:34:57 -0700 Subject: 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 http://codereview.appspot.com/850041 --- test/interface/convert.go | 116 ++++++++++++++++++++++++--------------------- test/interface/receiver.go | 3 +- 2 files changed, 64 insertions(+), 55 deletions(-) (limited to 'test/interface') diff --git a/test/interface/convert.go b/test/interface/convert.go index bc219c72f..7f429f703 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 59f3986d7..f74cecb2c 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++ } -- cgit v1.2.3