Gonna start unit testing to resolve issues

This commit is contained in:
2022-08-28 07:03:12 +01:00
parent 9c766ec61e
commit 5300e2ceec
13 changed files with 0 additions and 2 deletions

View File

@@ -0,0 +1,55 @@
//test function return
fn testFourtyTwo() {
return 42;
}
assert testFourtyTwo() == 42, "function returns failed";
//test function parameters
fn identity(x) {
return x;
}
assert identity("hello world") == "hello world", "identity function failed";
//test closures
fn make() {
var counter = 0;
fn count() {
return ++counter;
}
return count;
}
var tally = make();
assert tally() == 1 && tally() == 2, "Closures failed";
//test expressions as arguments
fn argFn() {
return 42;
}
fn outerFn(val) {
assert val == 42, "expression as argument failed";
}
outerFn(argFn());
//test extra parameters
fn extra(one, two, ...rest) {
assert rest == ["three", "four", "five", "six", "seven"], "rest parameters failed";
}
extra("one", "two", "three", "four", "five", "six", "seven");
print "All good";