mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: fix string array initialization with interpolation
This commit is contained in:
parent
0115c5e76c
commit
50cd0ed785
@ -1166,7 +1166,7 @@ fn (mut p Parser) string_expr() ast.Expr {
|
||||
vals << p.tok.lit
|
||||
p.next()
|
||||
if p.tok.kind != .str_dollar {
|
||||
continue
|
||||
break
|
||||
}
|
||||
p.next()
|
||||
exprs << p.expr(0)
|
||||
|
@ -83,3 +83,22 @@ fn test_array_of_map_interpolation() {
|
||||
a << {'c': int(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
Block a user