MCPcopy
hub / github.com/tinygo-org/tinygo / main

Function main

testdata/slice.go:16–169  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14}
15
16func main() {
17 l := 5
18 foo := []int{1, 2, 4, 5}
19 bar := make([]int, l-2, l)
20 println("foo is nil?", foo == nil, nil == foo)
21 printslice("foo", foo)
22 printslice("bar", bar)
23 printslice("foo[1:2]", foo[1:2])
24 println("sum foo:", sum(foo))
25
26 // creating a slice of uncommon base type
27 assert(len(make([]struct{}, makeInt(4))) == 4)
28
29 // creating a slice with uncommon len, cap types
30 assert(len(make([]int, makeInt(2), makeInt(3))) == 2)
31 assert(len(make([]int, makeInt8(2), makeInt8(3))) == 2)
32 assert(len(make([]int, makeInt16(2), makeInt16(3))) == 2)
33 assert(len(make([]int, makeInt32(2), makeInt32(3))) == 2)
34 assert(len(make([]int, makeInt64(2), makeInt64(3))) == 2)
35 assert(len(make([]int, makeUint(2), makeUint(3))) == 2)
36 assert(len(make([]int, makeUint8(2), makeUint8(3))) == 2)
37 assert(len(make([]int, makeUint16(2), makeUint16(3))) == 2)
38 assert(len(make([]int, makeUint32(2), makeUint32(3))) == 2)
39 assert(len(make([]int, makeUint64(2), makeUint64(3))) == 2)
40 assert(len(make([]int, makeUintptr(2), makeUintptr(3))) == 2)
41 assert(len(make([]int, makeMyUint8(2), makeMyUint8(3))) == 2)
42
43 // indexing into a slice with uncommon index types
44 assert(foo[int(2)] == 4)
45 assert(foo[int8(2)] == 4)
46 assert(foo[int16(2)] == 4)
47 assert(foo[int32(2)] == 4)
48 assert(foo[int64(2)] == 4)
49 assert(foo[uint(2)] == 4)
50 assert(foo[uint8(2)] == 4)
51 assert(foo[uint16(2)] == 4)
52 assert(foo[uint32(2)] == 4)
53 assert(foo[uint64(2)] == 4)
54 assert(foo[uintptr(2)] == 4)
55
56 // slicing with uncommon low, high types
57 assert(len(foo[int(1):int(3)]) == 2)
58 assert(len(foo[int8(1):int8(3)]) == 2)
59 assert(len(foo[int16(1):int16(3)]) == 2)
60 assert(len(foo[int32(1):int32(3)]) == 2)
61 assert(len(foo[int64(1):int64(3)]) == 2)
62 assert(len(foo[uint(1):uint(3)]) == 2)
63 assert(len(foo[uint8(1):uint8(3)]) == 2)
64 assert(len(foo[uint16(1):uint16(3)]) == 2)
65 assert(len(foo[uint32(1):uint32(3)]) == 2)
66 assert(len(foo[uint64(1):uint64(3)]) == 2)
67 assert(len(foo[uintptr(1):uintptr(3)]) == 2)
68
69 // slicing an array with uncommon low, high types
70 arr := [4]int{1, 2, 4, 5}
71 assert(len(arr[int(1):int(3)]) == 2)
72 assert(len(arr[int8(1):int8(3)]) == 2)
73 assert(len(arr[int16(1):int16(3)]) == 2)

Callers

nothing calls this directly

Calls 15

makeInt8Function · 0.85
makeInt16Function · 0.85
makeInt32Function · 0.85
makeInt64Function · 0.85
makeUintFunction · 0.85
makeUint8Function · 0.85
makeUint16Function · 0.85
makeUint32Function · 0.85
makeUint64Function · 0.85
makeUintptrFunction · 0.85
makeMyUint8Function · 0.85
printFunction · 0.85

Tested by

no test coverage detected