From 7edad5cefa0f065aa83dffd2d7830aeaf9f38662 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sat, 29 Jan 2022 23:31:16 +0100 Subject: tests: add functional tests for builtin functions Signed-off-by: Jo-Philipp Wich --- tests/custom/03_stdlib/41_sleep | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/custom/03_stdlib/41_sleep (limited to 'tests/custom/03_stdlib/41_sleep') 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 -- -- cgit v1.2.3