1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: allow integer and rune keys for map literal (#7756)

This commit is contained in:
Nick Treleaven
2021-01-01 16:23:32 +00:00
committed by GitHub
parent 24b18f05c4
commit 9243e06dba
10 changed files with 78 additions and 20 deletions

View File

@@ -485,6 +485,8 @@ fn test_int_keys() {
m[5] += 24
m[5]++
assert m[5] == 25
m2 := {3:9 4:16 5:25}
assert m2.len == 3
mc := m.clone()
assert mc.len == 3
mut all := []int{}
@@ -506,6 +508,21 @@ fn test_voidptr_keys() {
assert m.len == 2
}
fn test_rune_keys() {
mut m := {`!`:2 `%`:3}
assert typeof(m).name == 'map[rune]int'
assert m[`!`] == 2
m[`@`] = 7
assert m.len == 3
mut a := []rune{}
for k, v in m {
a << k
a << rune(v) + `0`
}
assert a == [`!`, `2`, `%`, `3`, `@`, `7`]
}
fn test_eq() {
a := {
'a': 1