summaryrefslogtreecommitdiffhomepage
path: root/tests/custom/03_stdlib/41_sleep
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/41_sleep
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/41_sleep')
-rw-r--r--tests/custom/03_stdlib/41_sleep46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/custom/03_stdlib/41_sleep b/tests/custom/03_stdlib/41_sleep
new file mode 100644
index 0000000..bca6f0d
--- /dev/null
+++ b/tests/custom/03_stdlib/41_sleep
@@ -0,0 +1,46 @@
+The `sleep()` function pauses program execution for the given amount of
+milliseconds.
+
+Returns `true` if the program slept.
+
+Returns `false` when the given time value was not convertible to an integer,
+negative or zero.
+
+-- Testcase --
+{%
+ let t1 = time();
+
+ sleep(1000);
+
+ let t2 = time();
+
+ printf("Slept for %d second(s).\n", t2 - t1);
+%}
+-- End --
+
+-- Expect stdout --
+Slept for 1 second(s).
+-- End --
+
+
+Passing an invalid value yields `false`.
+
+-- Testcase --
+{%
+ printf("%.J\n", [
+ sleep("inval"),
+ sleep([]),
+ sleep(-1),
+ sleep(0)
+ ]);
+%}
+-- End --
+
+-- Expect stdout --
+[
+ false,
+ false,
+ false,
+ false
+]
+-- End --