diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-03-21 00:24:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-21 00:24:20 +0100 |
commit | 718dfbda7d58308054ec7c6d9340751e97811d5d (patch) | |
tree | f461f2dc89f5cea5ccbf4a6200b539dbe883eab6 /tests/custom/03_stdlib | |
parent | a88aca97633c2ec58987a76a5a8d910c37680e07 (diff) | |
parent | 668c5c02e56b922aeb7b8870057622b6940413d2 (diff) |
Merge pull request #53 from jow-/string-format-argpos-support
lib: add argument position support (`%m$`) to `sprintf()` and `printf()`
Diffstat (limited to 'tests/custom/03_stdlib')
-rw-r--r-- | tests/custom/03_stdlib/27_sprintf | 21 | ||||
-rw-r--r-- | tests/custom/03_stdlib/28_printf | 17 |
2 files changed, 38 insertions, 0 deletions
diff --git a/tests/custom/03_stdlib/27_sprintf b/tests/custom/03_stdlib/27_sprintf index 3edcd48..e1a3c5d 100644 --- a/tests/custom/03_stdlib/27_sprintf +++ b/tests/custom/03_stdlib/27_sprintf @@ -548,3 +548,24 @@ Supplying a non-string format value will yield an empty string result. -- Expect stdout -- "" -- End -- + + +Prefixing a format directive with `n$` will select the corresponding argument +with 1 referring to the first argument. Missing or out-of range arguments will +be treated as `null`. + +-- Testcase -- +{% + printf("%.J\n", [ + sprintf("%2$s", "foo", "bar", "baz"), + sprintf("%10$s", "foo", "bar", "baz") + ]); +%} +-- End -- + +-- Expect stdout -- +[ + "bar", + "(null)" +] +-- End -- diff --git a/tests/custom/03_stdlib/28_printf b/tests/custom/03_stdlib/28_printf index a2a6d27..b4556b3 100644 --- a/tests/custom/03_stdlib/28_printf +++ b/tests/custom/03_stdlib/28_printf @@ -524,3 +524,20 @@ Supplying a non-string format value will yield an empty string result. -- Expect stdout -- -- End -- + + +Prefixing a format directive with `n$` will select the corresponding argument +with 1 referring to the first argument. Missing or out-of range arguments will +be treated as `null`. + +-- Testcase -- +{% + printf("%2$s\n", "foo", "bar", "baz"); + printf("%10$s\n", "foo", "bar", "baz"); +%} +-- End -- + +-- Expect stdout -- +bar +(null) +-- End -- |