summaryrefslogtreecommitdiffhomepage
path: root/tests/custom/03_stdlib
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-08-29 12:02:43 +0200
committerJo-Philipp Wich <jo@mein.io>2022-08-29 12:02:43 +0200
commit89452b20e5073feb28b294a707342ef144f4b5f0 (patch)
tree13b7a042cd7acb0dd0019b5ebab628bfcf5226d9 /tests/custom/03_stdlib
parentbcdd2cb33797412cce1f1014d265a71461676cff (diff)
lib: improve getenv() and split() implementations
- getenv(): Allow querying the entire environment by omiting variable name - split(): Properly handle null bytes in subject and separator strings Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests/custom/03_stdlib')
-rw-r--r--tests/custom/03_stdlib/05_getenv7
-rw-r--r--tests/custom/03_stdlib/18_split4
2 files changed, 9 insertions, 2 deletions
diff --git a/tests/custom/03_stdlib/05_getenv b/tests/custom/03_stdlib/05_getenv
index 350e952..064add0 100644
--- a/tests/custom/03_stdlib/05_getenv
+++ b/tests/custom/03_stdlib/05_getenv
@@ -2,6 +2,9 @@ The `getenv()` function returns the value of the given environment variable
or `null` if either the given variable does not exist or if the given name
argument is not a string.
+If the variable name argument is omitted, getenv() returns a dictionary
+containing all environment variables.
+
-- Testcase --
{%
printf("%.J\n", [
@@ -9,7 +12,7 @@ argument is not a string.
getenv("EMPTY_VARIABLE"),
getenv("THIS_LIKELY_DOES_NOT_EXIST"),
getenv(123),
- getenv(null)
+ type(getenv())
]);
%}
-- End --
@@ -25,6 +28,6 @@ EMPTY_VARIABLE=
"",
null,
null,
- null
+ "object"
]
-- End --
diff --git a/tests/custom/03_stdlib/18_split b/tests/custom/03_stdlib/18_split
index e31ce78..5ee35a2 100644
--- a/tests/custom/03_stdlib/18_split
+++ b/tests/custom/03_stdlib/18_split
@@ -40,6 +40,9 @@ argument is neither a string nor a regular expression.
// leading and trailing empty substrings are retained
split("|abc|def|", "|"),
split(",foo;bar:", /[,;:]/),
+
+ // subject and split strings handle embedded \0
+ split("foo=1\0bar=2\0baz=3", "\0"),
]), "\n");
%}
-- End --
@@ -58,6 +61,7 @@ argument is neither a string nor a regular expression.
[ "foo", "bar", "", "baz" ]
[ "", "abc", "def", "" ]
[ "", "foo", "bar", "" ]
+[ "foo=1", "bar=2", "baz=3" ]
-- End --