Debian Codegraph @

test/ken/intervar.go

raw
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
9 package main
10
11 type Iputs interface {
12 puts (s string) string;
13 }
14
15 // ---------
16
17 type Print struct {
18 whoami int;
19 put Iputs;
20 }
21
22 func (p *Print) dop() string {
23 r := " print " + string(p.whoami + '0')
24 return r + p.put.puts("abc");
25 }
26
27 // ---------
28
29 type Bio struct {
30 whoami int;
31 put Iputs;
32 }
33
34 func (b *Bio) puts(s string) string {
35 r := " bio " + string(b.whoami + '0')
36 return r + b.put.puts(s);
37 }
38
39 // ---------
40
41 type File struct {
42 whoami int;
43 put Iputs;
44 }
45
46 func (f *File) puts(s string) string {
47 return " file " + string(f.whoami + '0') + " -- " + s
48 }
49
50 func
51 main() {
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 }