aboutsummaryrefslogtreecommitdiffhomepage
path: root/testdata/slice.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2018-10-18 15:02:53 +0200
committerAyke van Laethem <[email protected]>2018-10-18 15:02:53 +0200
commitf9edf7cc5ce075361172c23cf4b6301a863a24ce (patch)
tree9a988b69c17c7f7ab705991077d996bfde43ef77 /testdata/slice.go
parent72390c21cb40777c3b621eac82d790da3716b228 (diff)
downloadtinygo-f9edf7cc5ce075361172c23cf4b6301a863a24ce.tar.gz
tinygo-f9edf7cc5ce075361172c23cf4b6301a863a24ce.zip
test: add slice tests
Diffstat (limited to 'testdata/slice.go')
-rw-r--r--testdata/slice.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/testdata/slice.go b/testdata/slice.go
new file mode 100644
index 000000000..215c213e1
--- /dev/null
+++ b/testdata/slice.go
@@ -0,0 +1,29 @@
+package main
+
+func main() {
+ l := 5
+ foo := []int{1, 2, 4, 5}
+ bar := make([]int, l-2, l)
+ printslice("foo", foo)
+ printslice("bar", bar)
+ printslice("foo[1:2]", foo[1:2])
+ println("sum foo:", sum(foo))
+ println("copy foo -> bar:", copy(bar, foo))
+ printslice("bar", bar)
+}
+
+func printslice(name string, s []int) {
+ print(name, ": len=", len(s), " cap=", cap(s), " data:")
+ for _, n := range s {
+ print(" ", n)
+ }
+ println()
+}
+
+func sum(l []int) int {
+ sum := 0
+ for _, n := range l {
+ sum += n
+ }
+ return sum
+}