Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz authored and janmasrovira committed Sep 8, 2024
1 parent 410b2a7 commit 649be19
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Juvix/Compiler/Internal/Language.hs
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ instance HasLoc CaseBranch where
getLoc c = getLoc (c ^. caseBranchPattern) <> getLoc (c ^. caseBranchRhs)

instance HasLoc Case where
getLoc c = getLoc (c ^. caseExpression) <> getLocSpan (c ^. caseBranches)
getLoc c = getLocSpan (c ^. caseBranches)

instance HasLoc Expression where
getLoc = \case
Expand Down
6 changes: 5 additions & 1 deletion test/Compilation/Negative.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,9 @@ tests =
NegTest
"Test006: Ill scoped term (This is a bug. It should be positive)"
$(mkRelDir ".")
$(mkRelFile "test006.juvix")
$(mkRelFile "test006.juvix"),
NegTest
"Test007: Pattern matching coverage with side conditions"
$(mkRelDir ".")
$(mkRelFile "test007.juvix")
]
10 changes: 10 additions & 0 deletions tests/Compilation/negative/test007.juvix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module test007;

import Stdlib.Prelude open;

f (x : List Nat) : Nat :=
case x of
| nil := 0
| x :: _ if true := x;

main : Nat := f (1 :: 2 :: nil);
5 changes: 5 additions & 0 deletions tests/Compilation/positive/out/test035.out
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@
13536
1
0
1
0
4
9
0
15 changes: 14 additions & 1 deletion tests/Compilation/positive/test035.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ h : Nat -> Nat
| (suc (suc (suc (suc n)))) := n
| _ := 0;

hh (x : Nat) : Nat :=
case x of
| zero := 1
| (suc n) if h n == 0 := n
| (suc zero) := 17
| (suc (suc (suc (suc (suc (suc zero)))))) := 9
| _ := 0;

printListNatLn : List Nat → IO
| nil := printStringLn "nil"
| (x :: xs) :=
Expand All @@ -54,4 +62,9 @@ main : IO :=
>>> printNatLn (f (gen 18))
>>> printNatLn (f (gen 20))
>>> printNatLn (h 5)
>>> printNatLn (h 3);
>>> printNatLn (h 3)
>>> printNatLn (hh 0)
>>> printNatLn (hh 1)
>>> printNatLn (hh 5)
>>> printNatLn (hh 6)
>>> printNatLn (hh 7);

0 comments on commit 649be19

Please sign in to comment.