diff --git a/tests/Main.idr b/tests/Main.idr index 95b711bf5..3eda2de67 100644 --- a/tests/Main.idr +++ b/tests/Main.idr @@ -131,6 +131,7 @@ nodeTests , "node011", "node012", "node015", "node017", "node018", "node019" -- node014 , "node021" --, "node020" , "reg001" + , "syntax001" , "tailrec001" ] diff --git a/tests/node/syntax001/caseBlock.idr b/tests/node/syntax001/caseBlock.idr new file mode 100644 index 000000000..16adc4e6d --- /dev/null +++ b/tests/node/syntax001/caseBlock.idr @@ -0,0 +1,27 @@ +module Main + +-- When generating javasript from idris, it is possible that the same name may appear in +-- different clauses when translating cases from Idris. To avoid a javascript syntax error +-- from occuring due to duplicate declations, each case clause is wrapped in brackets +-- to create unique block scopes. + +-- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch + +-- Without wrapping in a block, the test error may look like the following: +-- syntax001/build/exec/_tmp_node.js:39 +-- const x = ({h:1}); +-- ^ +-- SyntaxError: Identifier 'x' has already been declared + +test : Bool -> Int +test x @ True = + case x of + _ => 0 +test x @ False = + case x of + _ => 1 + +main : IO () +main = do + printLn $ test True + printLn $ test False diff --git a/tests/node/syntax001/expected b/tests/node/syntax001/expected new file mode 100644 index 000000000..0d66ea1ae --- /dev/null +++ b/tests/node/syntax001/expected @@ -0,0 +1,2 @@ +0 +1 diff --git a/tests/node/syntax001/run b/tests/node/syntax001/run new file mode 100644 index 000000000..9bdd3cff9 --- /dev/null +++ b/tests/node/syntax001/run @@ -0,0 +1,3 @@ +$1 --cg node caseBlock.idr -x main + +rm -rf build