v2 / vlib / v / tests / concurrency / shared_array_slice_test.v
27 lines · 26 sloc · 520 bytes · bed28d1e8bbe063d3d985c273fe35c8e83a070d3
Raw
1struct Foo {
2pub mut:
3 buf shared []u8 = []u8{len: 20, init: 6}
4 buf2 shared [20]u8
5}
6
7fn test_main() {
8 mut foo := Foo{
9 buf2: [20]u8{init: 5}
10 }
11 rlock foo.buf {
12 if foo.buf.len > 0 {
13 x := 10
14 println('first ${x} bytes: ' + foo.buf[..x].str())
15 sliced := foo.buf[..x]
16 assert sliced == [u8(6), 6, 6, 6, 6, 6, 6, 6, 6, 6]
17 } else {
18 println('no data')
19 assert false
20 }
21 }
22 rlock foo.buf2 {
23 x := 4
24 println('first ${x} bytes: ' + foo.buf2[..x].str())
25 assert foo.buf2[..x] == [u8(5), 5, 5, 5]
26 }
27}
28