summaryrefslogtreecommitdiffhomepage
path: root/tests/custom/03_stdlib/24_trim
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-01-29 23:31:16 +0100
committerJo-Philipp Wich <jo@mein.io>2022-02-03 17:22:43 +0100
commit7edad5cefa0f065aa83dffd2d7830aeaf9f38662 (patch)
tree86b727f434302ffb28cb59278243517f9765e170 /tests/custom/03_stdlib/24_trim
parentd5003fde57eab19588da7bfdbaefe93d47435eb6 (diff)
tests: add functional tests for builtin functions
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests/custom/03_stdlib/24_trim')
-rw-r--r--tests/custom/03_stdlib/24_trim46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/custom/03_stdlib/24_trim b/tests/custom/03_stdlib/24_trim
new file mode 100644
index 0000000..263fd18
--- /dev/null
+++ b/tests/custom/03_stdlib/24_trim
@@ -0,0 +1,46 @@
+The `trim()` function removes specific leading and trailing characters from
+a given input string. If the characters to trim are unspecified, the space, tab,
+carriage return and newline characters will be used by default.
+
+Returns a copy of the input string with the specified leading and trailing
+characters removed.
+
+Returns `null` if the given input argment is not a valid string value.
+
+-- Testcase --
+{%
+ printf("%.J\n", [
+ // not specifying trim characters will trim whitespace
+ trim(" Hello World! \r\n"),
+
+ // if trim characters are specified, only those are removed
+ trim("|* Foo Bar +|", "+*|"),
+
+ // trim does not affect characters in the middle of the string
+ trim(" Foo Bar "),
+ trim("|Foo|Bar|", "|")
+ ]);
+%}
+-- End --
+
+-- Expect stdout --
+[
+ "Hello World!",
+ " Foo Bar ",
+ "Foo Bar",
+ "Foo|Bar"
+]
+-- End --
+
+
+Supplying an invalid string will yield `null`.
+
+-- Testcase --
+{%
+ printf("%.J\n", trim(true));
+%}
+-- End --
+
+-- Expect stdout --
+null
+-- End --