parser: fix string array initialization with interpolation
parent
0115c5e76c
commit
50cd0ed785
|
@ -1166,7 +1166,7 @@ fn (mut p Parser) string_expr() ast.Expr {
|
||||||
vals << p.tok.lit
|
vals << p.tok.lit
|
||||||
p.next()
|
p.next()
|
||||||
if p.tok.kind != .str_dollar {
|
if p.tok.kind != .str_dollar {
|
||||||
continue
|
break
|
||||||
}
|
}
|
||||||
p.next()
|
p.next()
|
||||||
exprs << p.expr(0)
|
exprs << p.expr(0)
|
||||||
|
|
|
@ -83,3 +83,22 @@ fn test_array_of_map_interpolation() {
|
||||||
a << {'c': int(3), 'd': 4}
|
a << {'c': int(3), 'd': 4}
|
||||||
assert '$a' == "[{'a': 1, 'b': 2}, {'c': 3, 'd': 4}]"
|
assert '$a' == "[{'a': 1, 'b': 2}, {'c': 3, 'd': 4}]"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_array_initialization_with_interpolation() {
|
||||||
|
sysroot := '/usr'
|
||||||
|
a := [
|
||||||
|
'abcd'
|
||||||
|
'$sysroot/xyz'
|
||||||
|
'u$sysroot/vw'
|
||||||
|
'/rr$sysroot'
|
||||||
|
'lmno'
|
||||||
|
]
|
||||||
|
assert '$a' == "['abcd', '/usr/xyz', 'u/usr/vw', '/rr/usr', 'lmno']"
|
||||||
|
b := [
|
||||||
|
'a${sysroot:5}/r'
|
||||||
|
'ert'
|
||||||
|
]
|
||||||
|
assert '$b' == "['a /usr/r', 'ert']"
|
||||||
|
c := ['xy', 'r$sysroot', '$sysroot/t', '>$sysroot<']
|
||||||
|
assert '$c' == "['xy', 'r/usr', '/usr/t', '>/usr<']"
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue