Skip to content

Commit

Permalink
[ test ] Added regression tests for #2927
Browse files Browse the repository at this point in the history
  • Loading branch information
AlgebraicWolf committed Oct 9, 2023
1 parent cc30795 commit b6afdfa
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/Main.idr
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ idrisTests = MkTestPool "Misc" [] Nothing
"import001", "import002", "import003", "import004", "import005", "import006",
"import007", "import008", "import009",
-- Implicit laziness, lazy evaluation
"lazy001", "lazy002", "lazy003", "lazy004",
"lazy001", "lazy002", "lazy003", "lazy004", "lazy005",
-- Namespace blocks
"namespace001", "namespace002", "namespace003", "namespace004", "namespace005",
-- Parameters blocks
Expand Down
28 changes: 28 additions & 0 deletions tests/idris2/misc/lazy005/LiftedBot.idr
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Data.List.Lazy

import Debug.Trace

showHead : Show a => LazyList a -> String
showHead [] = "Empty"
showHead (x::xs) = show x

%inline
(::) : Maybe a -> Lazy (LazyList a) -> LazyList a
Nothing :: xs = xs
Just x :: xs = x :: xs

bot : a
bot = bot

fufu : a -> Maybe a
fufu = Just

g : LazyList Nat
g = [ fufu 6
, fufu bot
]

-- Note that this should finish in finite time, as tail containing
-- `bot` is lazy and should never be computed
main : IO Unit
main = printLn $ showHead g
22 changes: 22 additions & 0 deletions tests/idris2/misc/lazy005/LiftedTrace.idr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Data.List.Lazy

import Debug.Trace

%default total

%inline
(::) : Maybe a -> Lazy (LazyList a) -> LazyList a
Nothing :: xs = xs
Just x :: xs = x :: xs

fufu : a -> Maybe a
fufu = Just

g : LazyList Nat
g = trace "--- outmost ---"
[ fufu $ trace "pure 6" 6
, fufu $ trace "pure 5" 5
]

main : IO Unit
main = printLn g
5 changes: 5 additions & 0 deletions tests/idris2/misc/lazy005/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pure 6
--- outmost ---
pure 5
[6, 5]
"6"
4 changes: 4 additions & 0 deletions tests/idris2/misc/lazy005/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
. ../../../testutils.sh

idris2 -p contrib --exec main LiftedTrace.idr
idris2 -p contrib --exec main LiftedBot.idr

0 comments on commit b6afdfa

Please sign in to comment.