fix: fix leading % format in fmt (#1380)

This commit is contained in:
Veit Heller 2022-01-24 13:05:27 +01:00 committed by GitHub
parent 027d8b3278
commit bd653ad6e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -14,7 +14,7 @@
(if (= \% (String.char-at s (inc idx))) ; this is an escaped %
`(ref
(String.append
"%"
%(String.slice s 0 (inc idx))
%(fmt-internal (String.slice s (+ idx 2) len) args)))
(if (= 0 (length args)) ; we need to insert something, but have nothing
(macro-error

View File

@ -34,6 +34,10 @@
"10 % 12.0 yay"
&(fmt "%d %% %.1f %s" 10 12.0 "yay")
"fmt macro works")
(assert-equal test
"hi % 12.0"
&(fmt "hi %% %.1f" 12.0)
"fmt macro works with leading % (regression test)")
(assert-equal test
"1 [2 3] h"
&(let [x 1