Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Jan 10, 2025
1 parent 2661513 commit 658c9e9
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 4 deletions.
4 changes: 2 additions & 2 deletions test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import Typecheck qualified

slowTests :: IO TestTree
slowTests =
sequentialTestGroup
testGroup
"Juvix slow tests"
AllFinish
-- AllFinish
<$> sequence
[ return Runtime.allTests,
return Reg.allTests,
Expand Down
7 changes: 6 additions & 1 deletion test/Tree/Eval/Positive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -249,5 +249,10 @@ tests =
"Test042: Uncurried function type unification"
$(mkRelDir ".")
$(mkRelFile "test042.jvt")
$(mkRelFile "out/test042.out")
$(mkRelFile "out/test042.out"),
PosTest
"Test043: Unary closure calls"
$(mkRelDir ".")
$(mkRelFile "test043.jvt")
$(mkRelFile "out/test043.out")
]
2 changes: 2 additions & 0 deletions test/Tree/Transformation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Tree.Transformation where
import Base
import Tree.Transformation.Apply qualified as Apply
import Tree.Transformation.CheckNoAnoma qualified as CheckNoAnoma
import Tree.Transformation.ConvertUnaryCalls qualified as ConvertUnaryCalls
import Tree.Transformation.IdentityTrans qualified as IdentityTrans
import Tree.Transformation.Reachability qualified as Reachability

Expand All @@ -12,6 +13,7 @@ allTests =
"JuvixTree transformations"
[ IdentityTrans.allTests,
Apply.allTests,
ConvertUnaryCalls.allTests,
Reachability.allTests,
CheckNoAnoma.allTests
]
3 changes: 2 additions & 1 deletion test/Tree/Transformation/Apply.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ allTests =
[ "Test007: Higher-order functions",
"Test022: Self-application",
"Test025: Dynamic closure extension",
"Test032: Church numerals"
"Test032: Church numerals",
"Test043: Unary closure calls"
]
Eval.tests
)
Expand Down
33 changes: 33 additions & 0 deletions test/Tree/Transformation/ConvertUnaryCalls.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Tree.Transformation.ConvertUnaryCalls (allTests) where

import Base
import Juvix.Compiler.Tree.Transformation
import Tree.Eval.Positive qualified as Eval
import Tree.Transformation.Base

allTests :: TestTree
allTests =
testGroup
"ConvertUnaryCalls"
( map liftTest $
Eval.filterTests
[ "Test007: Higher-order functions",
"Test022: Self-application",
"Test025: Dynamic closure extension",
"Test032: Church numerals",
"Test043: Unary closure calls"
]
Eval.tests
)

pipe :: [TransformationId]
pipe = [ConvertUnaryCalls]

liftTest :: Eval.PosTest -> TestTree
liftTest _testEval =
fromTest
Test
{ _testTransformations = pipe,
_testAssertion = const (return ()),
_testEval
}
1 change: 1 addition & 0 deletions tests/Tree/positive/out/test043.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11
41 changes: 41 additions & 0 deletions tests/Tree/positive/test043.jvt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

type List {
nil : List;
cons : (*, List) -> List;
}

function lambda_add(integer) : integer;
function lambda_add2(integer, integer) : integer;
function mapnat(integer -> integer, List) : List;
function main() : List;

function lambda_add(_X' : integer) : integer {
add(1, _X')
}

function lambda_add2(_X : integer, _Y : integer) : integer {
add(_X, _Y)
}

function mapnat(f : integer -> integer, _X : List) : List {
case[List](_X) {
nil: alloc[nil]()
cons: save {
alloc[cons](ccall(f, tmp[0].cons[0]), call[mapnat](f, tmp[0].cons[1]))
}
}
}

function mysum(f : (integer, integer) -> integer, _X : List) : integer {
case[List](_X) {
nil: 0
cons: save {
ccall(f, tmp[0].cons[0], call[mysum](f, tmp[0].cons[1]))
}
}
}

function main() : integer {
call[mysum](calloc[lambda_add2](), call[mapnat](calloc[lambda_add](), alloc[cons](1, alloc[cons](3, alloc[cons](4, alloc[nil]())))))
-- result: 11
}

0 comments on commit 658c9e9

Please sign in to comment.