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 May 10, 2023
1 parent b07ef9b commit a41bdf4
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 @@ -272,7 +272,7 @@ idrisTests = MkTestPool "Misc" [] Nothing
"import001", "import002", "import003", "import004", "import005", "import006",
"import007", "import008",
-- Implicit laziness, lazy evaluation
"lazy001", "lazy002",
"lazy001", "lazy002", "lazy003",
-- Namespace blocks
"namespace001", "namespace002", "namespace003", "namespace004",
-- Parameters blocks
Expand Down
28 changes: 28 additions & 0 deletions tests/idris2/lazy003/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/lazy003/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/lazy003/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/lazy003/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
rm -rf build

$1 --no-color --console-width 0 --no-banner -p contrib --exec main LiftedTrace.idr
$1 --no-color --console-width 0 --no-banner -p contrib --exec main LiftedBot.idr

0 comments on commit a41bdf4

Please sign in to comment.