diff options
author | Ayke van Laethem <[email protected]> | 2018-10-19 14:40:19 +0200 |
---|---|---|
committer | Ayke van Laethem <[email protected]> | 2018-10-19 14:40:19 +0200 |
commit | 963ba16d7be23b336ba8c2de033cd35cbb40b5e0 (patch) | |
tree | f32339ccbbfe341f7f8a9f0a20576291340ce59a /testdata/slice.go | |
parent | b81aecf7533fb8234179bbeae98acce706325d02 (diff) | |
download | tinygo-963ba16d7be23b336ba8c2de033cd35cbb40b5e0.tar.gz tinygo-963ba16d7be23b336ba8c2de033cd35cbb40b5e0.zip |
compiler: add support for the append builtin
Diffstat (limited to 'testdata/slice.go')
-rw-r--r-- | testdata/slice.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/testdata/slice.go b/testdata/slice.go index 215c213e1..c5e4a3308 100644 --- a/testdata/slice.go +++ b/testdata/slice.go @@ -8,8 +8,32 @@ func main() { printslice("bar", bar) printslice("foo[1:2]", foo[1:2]) println("sum foo:", sum(foo)) + + // copy println("copy foo -> bar:", copy(bar, foo)) printslice("bar", bar) + + // append + var grow []int + printslice("grow", grow) + grow = append(grow, 42) + printslice("grow", grow) + grow = append(grow, -1, -2) + printslice("grow", grow) + grow = append(grow, foo...) + printslice("grow", grow) + grow = append(grow) + printslice("grow", grow) + grow = append(grow, grow...) + printslice("grow", grow) + + // append string to []bytes + bytes := append([]byte{1, 2, 3}, "foo"...) + print("bytes: len=", len(bytes), " cap=", cap(bytes), " data:") + for _, n := range bytes { + print(" ", n) + } + println() } func printslice(name string, s []int) { |