1// run 2 3// Copyright 2009 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// Test interface assignment. 8 9package main 10 11type Iputs interface { 12 puts (s string) string; 13} 14 15// --------- 16 17type Print struct { 18 whoami int; 19 put Iputs; 20} 21 22func (p *Print) dop() string { 23 r := " print " + string(p.whoami + '0') 24 return r + p.put.puts("abc"); 25} 26 27// --------- 28 29type Bio struct { 30 whoami int; 31 put Iputs; 32} 33 34func (b *Bio) puts(s string) string { 35 r := " bio " + string(b.whoami + '0') 36 return r + b.put.puts(s); 37} 38 39// --------- 40 41type File struct { 42 whoami int; 43 put Iputs; 44} 45 46func (f *File) puts(s string) string { 47 return " file " + string(f.whoami + '0') + " -- " + s 48} 49 50func 51main() { 52 p := new(Print); 53 b := new(Bio); 54 f := new(File); 55 56 p.whoami = 1; 57 p.put = b; 58 59 b.whoami = 2; 60 b.put = f; 61 62 f.whoami = 3; 63 64 r := p.dop(); 65 expected := " print 1 bio 2 file 3 -- abc" 66 if r != expected { 67 panic(r + " != " + expected) 68 } 69} 70