v / vlib / json / tests / json_encode_with_mut_test.v
42 lines · 36 sloc · 519 bytes · 8ebbacecd60366ac4ba68aa35f9b0e7a0e56ff61
Raw
1module main
2
3import json
4
5pub enum PlatformType {
6 unknown
7 osx
8 ubuntu
9 alpine
10}
11
12pub enum CPUType {
13 unknown
14 intel
15 arm
16 intel32
17 arm32
18}
19
20@[heap]
21pub struct Node {
22pub:
23 name string = 'mymachine'
24pub mut:
25 platform PlatformType
26 cputype CPUType
27 done map[string]string
28 environment map[string]string
29}
30
31pub fn (mut node Node) save() ! {
32 data := json.encode(node)
33 dump(data)
34}
35
36fn test_encode_with_mut_struct() {
37 mut n := Node{
38 platform: .osx
39 cputype: .unknown
40 }
41 n.save() or { panic(err) }
42}
43