Skip to content

Commit

Permalink
Additional exception test;
Browse files Browse the repository at this point in the history
  • Loading branch information
JeneLitsch committed Feb 26, 2022
1 parent 0222ad9 commit b9813a8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
File renamed without changes.
28 changes: 21 additions & 7 deletions test/exception.ltn
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
namespace test {
function doesItThrow(fx, params) {
function does_it_throw(fx, params) {
std::invoke(fx, params);
return false;
}
except(e) {
return true;
}

function justThrow() { throw; }
function noThrow() { }
function just_throw() { throw; }
function no_throw() { }
function throw_42() { throw 42; }
function throw_hello() { throw "hello"; }

function get_exception(fx) {
std::invoke(fx);
}
except(e) { return e; }

function exception() {
var throws = lambda(a,b) {
Expand All @@ -22,15 +29,22 @@ namespace test {
return 42;
};

var cases = [
[[ &justThrow(), [] ], true],
[[ &noThrow(), [] ], false],
var cases1 = [
[[ &just_throw(), [] ], true],
[[ &no_throw(), [] ], false],
[[ &std::remove_back(_), [std::array()] ], true],
[[ &std::remove_back(_), [std::array(42)] ], false],
[[ throws, [1,2] ], true],
[[ catches, [1,2] ], false],
];

var cases2 = [
[[&throw_42()], 42],
[[&throw_hello()], "hello"],
];
return test_all_cases("Exception", &doesItThrow(_,_), cases);

return
test_all_cases("Exception", &does_it_throw(_,_), cases1) +
test_all_cases("Exception", &get_exception(_), cases2);
}
}
2 changes: 1 addition & 1 deletion test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ binFile="test/$test.bin.ltn"
test/bool.ltn\
test/compare.ltn\
test/captures.ltn\
test/conditionals.ltn\
test/conditional.ltn\
test/exception.ltn\
test/loops.ltn\
test/main.ltn\
Expand Down

0 comments on commit b9813a8

Please sign in to comment.