-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from jow-/stdlib-tests
- Loading branch information
Showing
55 changed files
with
4,263 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
The `chr()` function converts each given numeric value into a character | ||
and returns the resulting string, e.g. passing 97, 98 and 99 will yield | ||
the string `abc`. | ||
|
||
Negative numeric values and values which cannot be converted to integers | ||
are treated as `0`, values larger than `255` are capped to `255`. | ||
|
||
The resulting string will have the same length as the amount of arguments | ||
passed to the `chr()` function. | ||
|
||
-- Testcase -- | ||
{% | ||
printf("%.J\n", [ | ||
chr(), | ||
chr(97, 98, 99), | ||
chr(-1, false, null, [], {}, "0x41", 66.5, 1000) | ||
]); | ||
%} | ||
-- End -- | ||
|
||
-- Expect stdout -- | ||
[ | ||
"", | ||
"abc", | ||
"\u0000\u0000\u0000\u0000\u0000AB\u00ff" | ||
] | ||
-- End -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
The `die()` function triggers a user defined runtime exception when invoked, | ||
using the given value as exception message. | ||
|
||
The given message value is converted to a string internally if it is not a | ||
string already. If no message argument is given or if the message argument | ||
is `null`, the default message is `Died`. | ||
|
||
The function does not return. | ||
|
||
-- Testcase -- | ||
{% | ||
print("Before invoking die()\n"); | ||
|
||
die("An exception!"); | ||
|
||
print("After invoking die()\n"); | ||
%} | ||
-- End -- | ||
|
||
-- Expect stdout -- | ||
Before invoking die() | ||
-- End -- | ||
|
||
-- Expect stderr -- | ||
An exception! | ||
In line 4, byte 21: | ||
|
||
` die("An exception!");` | ||
Near here -------------^ | ||
|
||
|
||
-- End -- | ||
|
||
|
||
-- Testcase -- | ||
{% | ||
die(); | ||
%} | ||
-- End -- | ||
|
||
-- Expect stderr -- | ||
Died | ||
In line 2, byte 6: | ||
|
||
` die();` | ||
^-- Near here | ||
|
||
|
||
-- End -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
The `exit()` function terminates the running program with the given exit | ||
code or 0 in case no argument is given or if the argument cannot be | ||
converted to an integer. | ||
|
||
The function does not return. | ||
|
||
-- Testcase -- | ||
{% | ||
print("Before invoking exit()\n"); | ||
|
||
exit(); | ||
|
||
print("After invoking exit()\n"); | ||
%} | ||
-- End -- | ||
|
||
-- Expect stdout -- | ||
Before invoking exit() | ||
-- End -- | ||
|
||
-- Expect exitcode -- | ||
0 | ||
-- End -- | ||
|
||
|
||
Passing a code argument overrides the default "0" value. | ||
|
||
-- Testcase -- | ||
{% | ||
exit(123) | ||
%} | ||
-- End -- | ||
|
||
-- Expect exitcode -- | ||
123 | ||
-- End -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
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. | ||
|
||
-- Testcase -- | ||
{% | ||
printf("%.J\n", [ | ||
getenv("TEST_VARIABLE"), | ||
getenv("EMPTY_VARIABLE"), | ||
getenv("THIS_LIKELY_DOES_NOT_EXIST"), | ||
getenv(123), | ||
getenv(null) | ||
]); | ||
%} | ||
-- End -- | ||
|
||
-- Vars -- | ||
TEST_VARIABLE=Test Value | ||
EMPTY_VARIABLE= | ||
-- End -- | ||
|
||
-- Expect stdout -- | ||
[ | ||
"Test Value", | ||
"", | ||
null, | ||
null, | ||
null | ||
] | ||
-- End -- |
Oops, something went wrong.