v2 / vlib / maps / maps_clone_test.v
36 lines · 29 sloc · 860 bytes · 136bdfe93f8830457651f88d4e423e39bc110485
Raw
1import maps
2
3fn test_main() {
4 // mmm map declaration as mutable
5 mut mmm := map[string]map[string]int{}
6
7 // adding values to the map mmm
8 mmm['greet'] = {
9 'hello': 0
10 }
11 mmm['place'] = {
12 'world': 1
13 }
14 mmm['color']['orange'] = 2
15
16 // printing the map mmm
17 assert mmm.str() == "{'greet': {'hello': 0}, 'place': {'world': 1}, 'color': {'orange': 2}}"
18
19 // mmm2 map declaration as const
20 mmm2 := {
21 'name': {
22 'Diego': 3
23 }
24 }
25
26 // printing the map mmm2
27 assert mmm2.str() == "{'name': {'Diego': 3}}"
28
29 // Using the maps module functions
30 // use of maps.merge is commented but its behavior is the same as merge_in_place
31 // mmm = maps.merge(mmm, mmm2)
32 maps.merge_in_place(mut mmm, mmm2)
33
34 // printing again mmm to the standard output
35 assert mmm.str() == "{'greet': {'hello': 0}, 'place': {'world': 1}, 'color': {'orange': 2}, 'name': {'Diego': 3}}"
36}
37