Skip to content

Commit

Permalink
fix: fix leading % format in fmt (#1380)
Browse files Browse the repository at this point in the history
  • Loading branch information
hellerve committed Jan 24, 2022
1 parent 027d8b3 commit bd653ad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/Format.carp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/format.carp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bd653ad

Please sign in to comment.