summaryrefslogtreecommitdiffhomepage
path: root/tests/custom/03_stdlib
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-03-16 20:25:24 +0100
committerJo-Philipp Wich <jo@mein.io>2022-03-20 23:10:00 +0100
commit668c5c02e56b922aeb7b8870057622b6940413d2 (patch)
tree3928e1436d01b78d7bf1b3861e30e11b5e7b324c /tests/custom/03_stdlib
parent807060a5d2d40113d9d78bf9e3866efb3de4c442 (diff)
lib: add argument position support (`%m$`) to `sprintf()` and `printf()`
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests/custom/03_stdlib')
-rw-r--r--tests/custom/03_stdlib/27_sprintf21
-rw-r--r--tests/custom/03_stdlib/28_printf17
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 --