MCPcopy Index your code
hub / github.com/tinygo-org/tinygo / main

Function main

testdata/interface.go:5–122  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3import "time"
4
5func main() {
6 thing := &Thing{"foo"}
7 println("thing:", thing.String())
8 thing.Print()
9 printItf(5)
10 printItf(byte('x'))
11 printItf("foo")
12 printItf(Foo(18))
13 printItf(*thing)
14 printItf(thing)
15 printItf(Stringer(thing))
16 printItf(struct{ n int }{})
17 printItf(struct {
18 n int `foo:"bar"`
19 }{})
20 printItf(Number(3))
21 array := Array([4]uint32{1, 7, 11, 13})
22 printItf(array)
23 printItf(ArrayStruct{3, array})
24 printItf(SmallPair{3, 5})
25 s := Stringer(thing)
26 println("Stringer.String():", s.String())
27 var itf interface{} = s
28 println("Stringer.(*Thing).String():", itf.(Stringer).String())
29 if s, ok := s.(interface{ String() string }); ok {
30 println("s has String() method:", s.String())
31 }
32
33 println("nested switch:", nestedSwitch('v', 3))
34
35 // Try putting a linked list in an interface:
36 // https://github.com/tinygo-org/tinygo/issues/309
37 itf = linkedList{}
38
39 // Test bugfix for assertion on named empty interface:
40 // https://github.com/tinygo-org/tinygo/issues/453
41 _, _ = itf.(Empty)
42
43 var v Byter = FooByte(3)
44 println("Byte(): ", v.Byte())
45
46 var n int
47 var f float32
48 var interfaceEqualTests = []struct {
49 equal bool
50 lhs interface{}
51 rhs interface{}
52 }{
53 {true, true, true},
54 {true, int(1), int(1)},
55 {true, int8(1), int8(1)},
56 {true, int16(1), int16(1)},
57 {true, int32(1), int32(1)},
58 {true, int64(1), int64(1)},
59 {true, uint(1), uint(1)},
60 {false, uint(1), uint(2)},
61 {true, uint8(1), uint8(1)},
62 {true, uint16(1), uint16(1)},

Callers

nothing calls this directly

Calls 15

StringMethod · 0.95
PrintMethod · 0.95
ByteMethod · 0.95
ArrayTypeAlias · 0.85
nestedSwitchFunction · 0.85
FooByteTypeAlias · 0.85
complexTypeAlias · 0.85
named1Function · 0.85
named2Function · 0.85
named3Function · 0.85
namedptr1Function · 0.85
namedptr2Function · 0.85

Tested by

no test coverage detected