summaryrefslogtreecommitdiffhomepage
path: root/tests/custom/03_stdlib/03_exists
diff options
context:
space:
mode:
Diffstat (limited to 'tests/custom/03_stdlib/03_exists')
-rw-r--r--tests/custom/03_stdlib/03_exists38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/custom/03_stdlib/03_exists b/tests/custom/03_stdlib/03_exists
new file mode 100644
index 0000000..3d71aa7
--- /dev/null
+++ b/tests/custom/03_stdlib/03_exists
@@ -0,0 +1,38 @@
+The `exists()` function checks the existence of the given key within the
+given object. If the object contains the given key, `true` is returned,
+otherwise `false`.
+
+If the object argument is not an object, `false` is returned as well.
+
+The key argument is converted to a string in case it is not one already.
+
+-- Testcase --
+{%
+ let obj = {
+ "foo": true,
+ "bar": false,
+ "false": null,
+ "123": "a number"
+ };
+
+ printf("%.J\n", [
+ exists(true, "test"),
+ exists(obj, "doesnotexists"),
+ exists(obj, "foo"),
+ exists(obj, "bar"),
+ exists(obj, !true),
+ exists(obj, 123)
+ ]);
+%}
+-- End --
+
+-- Expect stdout --
+[
+ false,
+ false,
+ true,
+ true,
+ true,
+ true
+]
+-- End --