diff options
author | Araq <rumpf_a@web.de> | 2011-09-26 07:45:33 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2011-09-26 07:45:33 +0200 |
commit | 7c34357856f0922fb265d81f1d215008b2dd8c14 (patch) | |
tree | 63bf05691c6f5c0f6da96ef03116b5895d016cda /tests/accept | |
parent | 14968fba46a0c1128f38859b339c7384f9f96cd4 (diff) | |
download | Nim-7c34357856f0922fb265d81f1d215008b2dd8c14.tar.gz |
bugfix: $ escaping in interpolatedFragments
Diffstat (limited to 'tests/accept')
-rw-r--r-- | tests/accept/run/tstringinterp.nim | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/tests/accept/run/tstringinterp.nim b/tests/accept/run/tstringinterp.nim index 0d402edc3..e1a55c94b 100644 --- a/tests/accept/run/tstringinterp.nim +++ b/tests/accept/run/tstringinterp.nim @@ -1,6 +1,6 @@ discard """ file: "tstringinterp.nim" - output: "Hello Alice, 64 | Hello Bob, 10" + output: "Hello Alice, 64 | Hello Bob, 10$" """ import macros, parseutils, strutils @@ -12,10 +12,10 @@ proc concat(strings: openarray[string]): string = template ProcessInterpolations(e: expr) = var s = e[1].strVal for f in interpolatedFragments(s): - if f.kind == ikStr: - addString(f.value) - else: - addExpr(newCall("$", parseExpr(f.value))) + case f.kind + of ikStr: addString(f.value) + of ikDollar: addDollar() + of ikVar, ikExpr: addExpr(newCall("$", parseExpr(f.value))) macro formatStyleInterpolation(e: expr): expr = var @@ -30,6 +30,9 @@ macro formatStyleInterpolation(e: expr): expr = arrayNode.add(e) formatString.add("$" & $(idx)) inc idx + + proc addDollar() = + formatString.add("$$") ProcessInterpolations(e) @@ -43,6 +46,7 @@ macro concatStyleInterpolation(e: expr): expr = proc addString(s: string) = args.add(newStrLitNode(s)) proc addExpr(e: expr) = args.add(e) + proc addDollar() = args.add(newStrLitNode"$") ProcessInterpolations(e) @@ -62,7 +66,7 @@ var var s1 = concatStyleInterpolation"Hello ${alice}, ${sum(a, b, c)}" - s2 = formatStyleInterpolation"Hello ${bob}, ${sum(alice.len, bob.len, 2)}" + s2 = formatStyleInterpolation"Hello ${bob}, ${sum(alice.len, bob.len, 2)}$$" write(stdout, s1 & " | " & s2) |