The only restriction is keys must be string after evaluation. This fix various inconsistencies.pull/6289/head
parent
b1c8f765fa
commit
9b1a857473
6 changed files with 67 additions and 61 deletions
@ -1,17 +1,9 @@ |
|||||||
## Adding dictionary entry using string variable as key |
## Dictionary entry using string variable as key |
||||||
|
|
||||||
New dictionary entry can now be added using string variable as key, |
|
||||||
in addition to using string literal as key. |
|
||||||
|
|
||||||
|
Keys can now be any expression evaluating to a string value, not limited |
||||||
|
to string literals any more. |
||||||
```meson |
```meson |
||||||
dict = {} |
d = {'a' + 'b' : 42} |
||||||
|
k = 'cd' |
||||||
# A variable to be used as a key |
d += {k : 43} |
||||||
key = 'myKey' |
|
||||||
|
|
||||||
# Add new entry using the variable |
|
||||||
dict += {key : 'myValue'} |
|
||||||
|
|
||||||
# Test that the stored value is correct |
|
||||||
assert(dict[key] == 'myValue', 'Incorrect value retrieved from dictionary') |
|
||||||
``` |
``` |
||||||
|
@ -1,21 +0,0 @@ |
|||||||
project('add dictionary entry using string variable as key', meson_version: '>=0.52') |
|
||||||
|
|
||||||
dict1 = {} |
|
||||||
|
|
||||||
# A variable to be used as a key |
|
||||||
testkey1 = 'myKey1' |
|
||||||
testkey2 = 'myKey2' |
|
||||||
|
|
||||||
# Add new entry using the variable |
|
||||||
dict1 += {testkey1 : 'myValue'} |
|
||||||
dict1 += {testkey2 : 42} |
|
||||||
|
|
||||||
# Test that the stored values are correct |
|
||||||
assert(dict1[testkey1] == 'myValue', |
|
||||||
'Incorrect string value retrieved from dictionary - variable key') |
|
||||||
assert(dict1['myKey1'] == 'myValue', |
|
||||||
'Incorrect string value retrieved from dictionary - literal key') |
|
||||||
assert(dict1[testkey2] == 42, |
|
||||||
'Incorrect int value retrieved from dictionary - variable key') |
|
||||||
assert(dict1['myKey2'] == 42, |
|
||||||
'Incorrect int value retrieved from dictionary - literal key') |
|
Loading…
Reference in new issue