-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JuvixTree negative evaluation tests (#2601)
* Adds negative tests for the JuvixTree evaluator * Depends on #2600 * Depends on #2599 * Depends on #2598 * Depends on #2597 * Depends on #2596 * Depends on #2595 * Depends on #2594 * Depends on #2590
- Loading branch information
Showing
12 changed files
with
165 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
module Tree.Eval where | ||
|
||
import Base | ||
import Tree.Eval.Negative qualified as N | ||
import Tree.Eval.Positive qualified as P | ||
|
||
allTests :: TestTree | ||
allTests = testGroup "JuvixTree evaluation" [P.allTests] | ||
allTests = testGroup "JuvixTree evaluation" [P.allTests, N.allTests] |
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,65 @@ | ||
module Tree.Eval.Negative where | ||
|
||
import Base | ||
import Tree.Eval.Base | ||
|
||
data NegTest = NegTest | ||
{ _name :: String, | ||
_relDir :: Path Rel Dir, | ||
_file :: Path Rel File | ||
} | ||
|
||
root :: Path Abs Dir | ||
root = relToProject $(mkRelDir "tests/Tree/negative") | ||
|
||
testDescr :: NegTest -> TestDescr | ||
testDescr NegTest {..} = | ||
let tRoot = root <//> _relDir | ||
file' = tRoot <//> _file | ||
in TestDescr | ||
{ _testName = _name, | ||
_testRoot = tRoot, | ||
_testAssertion = Steps $ treeEvalErrorAssertion file' | ||
} | ||
|
||
allTests :: TestTree | ||
allTests = | ||
testGroup | ||
"JuvixTree negative tests" | ||
(map (mkTest . testDescr) tests) | ||
|
||
tests :: [NegTest] | ||
tests = | ||
[ NegTest | ||
"Test001: Division by zero" | ||
$(mkRelDir ".") | ||
$(mkRelFile "test001.jvt"), | ||
NegTest | ||
"Test002: Arithmetic operations on non-numbers" | ||
$(mkRelDir ".") | ||
$(mkRelFile "test002.jvt"), | ||
NegTest | ||
"Test003: Case on non-data" | ||
$(mkRelDir ".") | ||
$(mkRelFile "test003.jvt"), | ||
NegTest | ||
"Test004: If on non-boolean" | ||
$(mkRelDir ".") | ||
$(mkRelFile "test004.jvt"), | ||
NegTest | ||
"Test005: No matching case branch" | ||
$(mkRelDir ".") | ||
$(mkRelFile "test005.jvt"), | ||
NegTest | ||
"Test006: Invalid closure call" | ||
$(mkRelDir ".") | ||
$(mkRelFile "test006.jvt"), | ||
NegTest | ||
"Test007: Call: wrong number of arguments" | ||
$(mkRelDir ".") | ||
$(mkRelFile "test007.jvt"), | ||
NegTest | ||
"Test008: Closure call: wrong number of arguments" | ||
$(mkRelDir ".") | ||
$(mkRelFile "test008.jvt") | ||
] |
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,9 @@ | ||
-- division by zero | ||
|
||
function f(x : integer) : integer { | ||
div(2, x) | ||
} | ||
|
||
function main() : * { | ||
call[f](0) | ||
} |
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,5 @@ | ||
-- arithmetic operations on non-numbers | ||
|
||
function main() : * { | ||
add(2, calloc[main]()) | ||
} |
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,13 @@ | ||
-- case on non-data | ||
|
||
type list { | ||
nil : list; | ||
cons : * -> list -> list; | ||
} | ||
|
||
function main() : * { | ||
case[list](3) { | ||
nil: 0 | ||
cons: 1 | ||
} | ||
} |
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,8 @@ | ||
-- if on non-boolean | ||
|
||
function main() : * { | ||
br(3) { | ||
true: 0 | ||
false: 1 | ||
} | ||
} |
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,12 @@ | ||
-- no matching case branch | ||
|
||
type list { | ||
nil : list; | ||
cons : * -> list -> list; | ||
} | ||
|
||
function main() : * { | ||
case[list](alloc[nil]()) { | ||
cons: 1 | ||
} | ||
} |
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,5 @@ | ||
-- invalid closure call | ||
|
||
function main() : * { | ||
call(2, 1) | ||
} |
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,9 @@ | ||
-- call: wrong number of arguments | ||
|
||
function f(x : *) : * { | ||
x | ||
} | ||
|
||
function main() : * { | ||
call[f](10, 11) | ||
} |
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,9 @@ | ||
-- closure call: wrong number of arguments | ||
|
||
function f(x : *) : * { | ||
x | ||
} | ||
|
||
function main() : * { | ||
call(calloc[f](), 10, 11) | ||
} |