2012-02-16 21:50:37 -07:00
|
|
|
// run
|
2008-06-06 15:27:34 -06:00
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
2009-12-10 13:53:23 -07:00
|
|
|
type Iputs interface {
|
2012-01-18 17:12:24 -07:00
|
|
|
puts (s string) string;
|
2008-06-06 15:27:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------
|
|
|
|
|
2009-12-10 13:53:23 -07:00
|
|
|
type Print struct {
|
2008-06-06 15:27:34 -06:00
|
|
|
whoami int;
|
|
|
|
put Iputs;
|
|
|
|
}
|
|
|
|
|
2012-01-18 17:12:24 -07:00
|
|
|
func (p *Print) dop() string {
|
|
|
|
r := " print " + string(p.whoami + '0')
|
|
|
|
return r + p.put.puts("abc");
|
2008-06-06 15:27:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------
|
|
|
|
|
2009-12-10 13:53:23 -07:00
|
|
|
type Bio struct {
|
2008-06-06 15:27:34 -06:00
|
|
|
whoami int;
|
|
|
|
put Iputs;
|
|
|
|
}
|
|
|
|
|
2012-01-18 17:12:24 -07:00
|
|
|
func (b *Bio) puts(s string) string {
|
|
|
|
r := " bio " + string(b.whoami + '0')
|
|
|
|
return r + b.put.puts(s);
|
2008-06-06 15:27:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------
|
|
|
|
|
2009-12-10 13:53:23 -07:00
|
|
|
type File struct {
|
2008-06-06 15:27:34 -06:00
|
|
|
whoami int;
|
|
|
|
put Iputs;
|
|
|
|
}
|
|
|
|
|
2012-01-18 17:12:24 -07:00
|
|
|
func (f *File) puts(s string) string {
|
|
|
|
return " file " + string(f.whoami + '0') + " -- " + s
|
2008-06-06 15:27:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func
|
2009-12-10 13:53:23 -07:00
|
|
|
main() {
|
2009-01-06 16:19:02 -07:00
|
|
|
p := new(Print);
|
|
|
|
b := new(Bio);
|
|
|
|
f := new(File);
|
2008-06-06 15:27:34 -06:00
|
|
|
|
|
|
|
p.whoami = 1;
|
|
|
|
p.put = b;
|
|
|
|
|
|
|
|
b.whoami = 2;
|
|
|
|
b.put = f;
|
|
|
|
|
|
|
|
f.whoami = 3;
|
|
|
|
|
2012-01-18 17:12:24 -07:00
|
|
|
r := p.dop();
|
|
|
|
expected := " print 1 bio 2 file 3 -- abc"
|
|
|
|
if r != expected {
|
|
|
|
panic(r + " != " + expected)
|
|
|
|
}
|
2008-06-06 15:27:34 -06:00
|
|
|
}
|