Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira committed Nov 22, 2024
1 parent 42a3476 commit 094c6e9
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/Juvix/Compiler/Builtins/Ordering.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Juvix.Compiler.Builtins.Ordering where

-- import Juvix.Compiler.Internal.Builtins
import Juvix.Compiler.Internal.Extra
import Juvix.Prelude

Expand Down
8 changes: 4 additions & 4 deletions src/Juvix/Compiler/Internal/Translation/FromConcrete.hs
Original file line number Diff line number Diff line change
Expand Up @@ -632,11 +632,11 @@ compareConstructors loc bs cs = do
. runInputList cs
$ repeatOnInput go
Internal.mkLambda <$> case res of
Nothing -> pure <$> defaultClause
Nothing -> pure <$> emptyTypeClause
Just l -> return l
where
defaultClause :: Sem r Internal.LambdaClause
defaultClause = do
emptyTypeClause :: Sem r Internal.LambdaClause
emptyTypeClause = do
w1 <- Internal.genWildcard loc Explicit
w2 <- Internal.genWildcard loc Explicit
return
Expand All @@ -647,7 +647,7 @@ compareConstructors loc bs cs = do

go :: (Members '[NameIdGen, Output Internal.LambdaClause, Input ConstructorInfo] r') => ConstructorInfo -> Sem r' ()
go c = do
isLast <- isJust <$> peekInput @ConstructorInfo
isLast <- isEndOfInput @ConstructorInfo
let mkPat = Internal.genConstructorPattern loc Explicit c
(p1, v1) <- mkPat
(p2, v2) <- mkPat
Expand Down
8 changes: 7 additions & 1 deletion src/Juvix/Prelude/Effects/Input.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE AllowAmbiguousTypes #-}

module Juvix.Prelude.Effects.Input
( Input,
input,
Expand All @@ -6,6 +8,7 @@ module Juvix.Prelude.Effects.Input
peekInput,
runInputList,
repeatOnInput,
isEndOfInput,
)
where

Expand Down Expand Up @@ -44,7 +47,10 @@ peekInput = do
runInputList :: [i] -> Sem (Input i ': r) a -> Sem r a
runInputList = evalStaticRep . Input

repeatOnInput :: (i -> Sem (Input i ': r) a) -> Sem (Input i ': r) ()
isEndOfInput :: forall i r. (Members '[Input i] r) => Sem r Bool
isEndOfInput = isNothing <$> peekInput @i

repeatOnInput :: (Members '[Input i] r) => (i -> Sem r a) -> Sem r ()
repeatOnInput m = whenJustM input (m >=> const (repeatOnInput m))

inputJust :: (Members '[Input i] r) => Sem r i
Expand Down
7 changes: 6 additions & 1 deletion test/Compilation/Positive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -500,5 +500,10 @@ tests =
"Test085: Deriving Eq"
$(mkRelDir ".")
$(mkRelFile "test085.juvix")
$(mkRelFile "out/test085.out")
$(mkRelFile "out/test085.out"),
posTest
"Test086: Deriving Ord"
$(mkRelDir ".")
$(mkRelFile "test086.juvix")
$(mkRelFile "out/test086.out")
]
5 changes: 5 additions & 0 deletions tests/Compilation/positive/out/test086.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Equal
LessThan
GreaterThan
LessThan
GreaterThan
26 changes: 26 additions & 0 deletions tests/Compilation/positive/test086.juvix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- Deriving Ord
module test086;

import Stdlib.Data.Fixity open;
import Stdlib.Data.Bool open;
import Stdlib.Data.Pair open;
import Stdlib.Trait.Ord open;
import Stdlib.System.IO open;

syntax alias compare := Ord.cmp;

type T :=
| One
| Two
| Three
| Four;

deriving instance
ordT : Ord T;

main : IO :=
printLn (compare One One)
>>> printLn (compare One Two)
>>> printLn (compare Two One)
>>> printLn (compare (One, One) (One, Three))
>>> printLn (compare (Four, Four) (Four, Three));

0 comments on commit 094c6e9

Please sign in to comment.