From e8660cab97fb5eac1805ca5366695b7cf7ba896a Mon Sep 17 00:00:00 2001 From: Steven Dunham Date: Fri, 7 Jan 2022 21:53:46 -0800 Subject: [PATCH] [ tests ] Add test case for #2243 --- tests/Main.idr | 1 + tests/node/tailrec002/EvenOdd.idr | 13 +++++++++++++ tests/node/tailrec002/Main.idr | 17 +++++++++++++++++ tests/node/tailrec002/expected | 1 + tests/node/tailrec002/run | 4 ++++ 5 files changed, 36 insertions(+) create mode 100644 tests/node/tailrec002/EvenOdd.idr create mode 100644 tests/node/tailrec002/Main.idr create mode 100644 tests/node/tailrec002/expected create mode 100755 tests/node/tailrec002/run diff --git a/tests/Main.idr b/tests/Main.idr index 2a18f3e8c..0fa2f2f1c 100644 --- a/tests/Main.idr +++ b/tests/Main.idr @@ -284,6 +284,7 @@ nodeTests = MkTestPool "Node backend" [] (Just Node) , "stringcast" , "syntax001" , "tailrec001" + , "tailrec002" , "idiom001" , "integers" , "fix1839" diff --git a/tests/node/tailrec002/EvenOdd.idr b/tests/node/tailrec002/EvenOdd.idr new file mode 100644 index 000000000..c428f14f5 --- /dev/null +++ b/tests/node/tailrec002/EvenOdd.idr @@ -0,0 +1,13 @@ +module Main + +mutual + is_even : Nat -> Bool + is_even Z = True + is_even (S k) = is_odd k + + is_odd : Nat -> Bool + is_odd Z = False + is_odd (S k) = is_even k + +main : IO () +main = printLn (is_even 10) diff --git a/tests/node/tailrec002/Main.idr b/tests/node/tailrec002/Main.idr new file mode 100644 index 000000000..b65d163e6 --- /dev/null +++ b/tests/node/tailrec002/Main.idr @@ -0,0 +1,17 @@ +module Main + +import System.File +import Data.String +import Data.List1 +import Data.List + +parse : String -> Maybe String +parse x = case forget $ split (\c => c == ' ' || c == '(') x of + "function" :: name :: _ => Just name + _ => Nothing + +main : IO () +main = do + Right res <- readFile "build/exec/app.js" | Left err => printLn err + let fns = mapMaybe parse $ lines res + printLn $ fns \\ nub fns diff --git a/tests/node/tailrec002/expected b/tests/node/tailrec002/expected new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/tests/node/tailrec002/expected @@ -0,0 +1 @@ +[] diff --git a/tests/node/tailrec002/run b/tests/node/tailrec002/run new file mode 100755 index 000000000..71cf6fd01 --- /dev/null +++ b/tests/node/tailrec002/run @@ -0,0 +1,4 @@ +$1 --no-color --console-width 0 --no-banner --cg node EvenOdd.idr -o app.js +$1 --no-color --console-width 0 --no-banner Main.idr -x main +rm -rf build +