Skip to content

Commit 9b53b4b

Browse files
committed
Add tests for string interpolation
1 parent fea338c commit 9b53b4b

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Test.hx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ class Test extends TestCase {
9696
assertScript("var a:Array<Dynamic>=[1,2,4]; a[2]", 4, null, true);
9797
assertScript("/**/0", 0);
9898
assertScript("x=1;x*=-2", -2);
99+
assertScript("'$$'", "$");
100+
assertScript("'$x'", 10, { x:10 });
101+
assertScript("'${x + 5}'", 15, { x:10 });
102+
assertScript("'h$s'", "hscript", { s:"script" });
103+
assertScript("'${function(x) {return x * x;}(3)}'", 9);
99104
}
100105

101106
function testMap():Void {

hscript/Parser.hx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ class Parser {
414414
if (precedingSub != "")
415415
exprs.push(mk(EConst(CString(precedingSub))));
416416

417-
while (depth >= 0) {
417+
while (i < s.length) {
418418
char = s.charAt(++i);
419419
if (char == '{')
420420
depth++;
@@ -445,7 +445,7 @@ class Parser {
445445
exprs.push(mk(EIdent(ident)));
446446
s = s.substr(i);
447447
}
448-
dollarIndex = s.indexOf('$');
448+
dollarIndex = s.indexOf('$', i);
449449
}
450450

451451
if (exprs.length == 0)

0 commit comments

Comments
 (0)