v2 / vlib / v / slow_tests / inout / dump_expression.vv
59 lines · 51 sloc · 833 bytes · 4e68a8602547320b98492cf311bf2e7de7cf915f
Raw
1import os
2
3fn dump_of_int() {
4 x := dump(1) + 1
5 assert x == 2
6}
7
8fn dump_of_string() {
9 x := dump('a') + 'b'
10 assert x == 'ab'
11}
12
13struct Point {
14mut:
15 x int
16 y int
17 z int
18}
19
20struct Aa {
21 cmd &os.Command
22}
23
24fn dump_of_struct() {
25 p := Point{1, 2, 3}
26 mut p_mut := Point{1, 2, 3}
27 p_ptr := &Point{1, 2, 3}
28 c := &os.Command{}
29 a := Aa{
30 cmd: c
31 }
32
33 dump(a)
34 mut x1 := dump(p)
35 mut x2 := dump(p_mut)
36 mut x3 := dump(p_ptr)
37 x1.x += 100
38 x2.x += 100
39 x3.x += 100
40 assert x1 == Point{101, 2, 3}
41 assert x2 == Point{101, 2, 3}
42 assert x3 == Point{101, 2, 3}
43}
44
45fn dump_of_callexpr() {
46 vfile := @FILE
47 dump(os.file_name(vfile))
48 mut f := os.open_file(@FILE, 'r') or { return }
49 mut buf := []u8{len: 10}
50 dump(f.read(mut buf) or { -999 })
51 f.close()
52}
53
54fn main() {
55 dump_of_int()
56 dump_of_string()
57 dump_of_struct()
58 dump_of_callexpr()
59}
60