| 1 | struct Test { |
| 2 | a bool |
| 3 | b int |
| 4 | y string |
| 5 | } |
| 6 | |
| 7 | fn test_interpolation_map_to_string() { |
| 8 | mut a := map[string]string{} |
| 9 | a['1'] = 'one' |
| 10 | a['2'] = 'two' |
| 11 | a['3'] = 'three' |
| 12 | assert '${a}' == "{'1': 'one', '2': 'two', '3': 'three'}" |
| 13 | |
| 14 | mut b := map[string]int{} |
| 15 | b['1'] = 1 |
| 16 | b['2'] = 2 |
| 17 | b['3'] = 3 |
| 18 | assert '${b}' == "{'1': 1, '2': 2, '3': 3}" |
| 19 | |
| 20 | mut c := map[string]bool{} |
| 21 | c['1'] = true |
| 22 | c['2'] = false |
| 23 | assert '${c}' == "{'1': true, '2': false}" |
| 24 | |
| 25 | d := { |
| 26 | 'f1': 1.1 |
| 27 | 'f2': 2.2 |
| 28 | 'f3': 3.3 |
| 29 | 'f4': 4.4 |
| 30 | } |
| 31 | println('d: ${d}') |
| 32 | assert '${d}' == "{'f1': 1.1, 'f2': 2.2, 'f3': 3.3, 'f4': 4.4}" |
| 33 | |
| 34 | mut e := map[string]Test{} |
| 35 | e['1'] = Test{true, 0, 'abc'} |
| 36 | e['2'] = Test{true, 1, 'def'} |
| 37 | e['3'] = Test{false, 2, 'ghi'} |
| 38 | s := '${e}' |
| 39 | assert s.contains("{'1': Test{") |
| 40 | assert s.contains('a: true') |
| 41 | assert s.contains("y: 'abc'") |
| 42 | assert s.contains("}, '2': Test{") |
| 43 | assert s.contains("y: 'def'") |
| 44 | |
| 45 | f := { |
| 46 | 'hello': [1, 2, 3]! |
| 47 | } |
| 48 | assert '${f}' == "{'hello': [1, 2, 3]}" |
| 49 | } |
| 50 | |
| 51 | fn test_interpolation_map_to_string_with_delete() { |
| 52 | mut m1 := map[string]int{} |
| 53 | m1['one'] = 1 |
| 54 | m1['two'] = 2 |
| 55 | m1.delete('two') |
| 56 | println(m1) |
| 57 | assert '${m1}' == "{'one': 1}" |
| 58 | |
| 59 | mut m2 := map[string]int{} |
| 60 | m2['one'] = 1 |
| 61 | m2['two'] = 2 |
| 62 | m2.delete('one') |
| 63 | println(m2) |
| 64 | assert '${m2}' == "{'two': 2}" |
| 65 | } |
| 66 | |