Carp/test/format.carp
Veit Heller 8c1999d656
feat: add fstr (#1142)
* feat: add fstr

* test: add fstr test

* fix: memory error in test

* fix: fix backslash parser

* feat: add octal escape literals
2021-01-26 06:18:16 +01:00

48 lines
1.4 KiB
Plaintext

(load "Test.carp")
(use Test)
(deftest test
(assert-equal test
"c"
&(format "%c" \c)
"format works on chars")
(assert-equal test
"1"
&(format "%d" true)
"format works on bools")
(assert-equal test
"10"
&(format "%d" 10)
"format works on ints")
(assert-equal test
"10"
&(format "%ld" 10)
"format works on longs")
(assert-equal test
"10.0"
&(format "%.1f" 10.0f)
"format works on floats")
(assert-equal test
"10.050"
&(format "%2.3f" 10.05)
"format works on doubles")
(assert-equal test
"outside string: inside string :outside string"
&(format "outside string: %s :outside string" "inside string")
"format works on strings")
(assert-equal test
"10 % 12.0 yay"
&(fmt "%d %% %.1f %s" 10 12.0 "yay")
"fmt macro works")
(assert-equal test
"1 [2 3] h"
&(let [x 1
y [2 3]
z "hi"]
(fstr "{x} {&y} {(head z)}"))
"fstr works")
(assert-equal test
"{}"
&(fstr "{{}")
"fstr escaping works"))