;; Phase 17 — parser polish unit tests. (hk-test "type-ann: literal int annotated" (hk-deep-force (hk-run "main = (42 :: Int)")) 42) (hk-test "type-ann: arithmetic annotated" (hk-deep-force (hk-run "main = (1 + 2 :: Int)")) 3) (hk-test "type-ann: function arg annotated" (hk-deep-force (hk-run "f x = x + 1\nmain = f (1 :: Int)")) 2) (hk-test "type-ann: string annotated" (hk-deep-force (hk-run "main = (\"hi\" :: String)")) "hi") (hk-test "type-ann: bool annotated" (hk-deep-force (hk-run "main = (True :: Bool)")) (list "True")) (hk-test "type-ann: tuple annotated" (hk-deep-force (hk-run "main = ((1, 2) :: (Int, Int))")) (list "Tuple" 1 2)) (hk-test "type-ann: nested annotation in arithmetic" (hk-deep-force (hk-run "main = (1 :: Int) + (2 :: Int)")) 3) (hk-test "type-ann: function-typed annotation passes through eval" (hk-deep-force (hk-run "main = let f = ((\\x -> x + 1) :: Int -> Int) in f 5")) 6) (hk-test "no regression: plain parens still work" (hk-deep-force (hk-run "main = (5)")) 5) (hk-test "no regression: 3-tuple still works" (hk-deep-force (hk-run "main = (1, 2, 3)")) (list "Tuple" 1 2 3)) (hk-test "no regression: section-left still works" (hk-deep-force (hk-run "main = (3 +) 4")) 7) (hk-test "no regression: section-right still works" (hk-deep-force (hk-run "main = (+ 3) 4")) 7) (hk-test "import: still works as the very first decl" (hk-deep-force (hk-run "import qualified Data.IORef as I main = do { r <- I.newIORef 7; I.readIORef r }")) (list "IO" 7)) (hk-test "import: between decls — after main" (hk-deep-force (hk-run "main = do { r <- I.newIORef 11; I.readIORef r } import qualified Data.IORef as I")) (list "IO" 11)) (hk-test "import: between two decls — uses helper after import" (hk-deep-force (hk-run "f x = x + 100 import qualified Data.IORef as I main = do { r <- I.newIORef 5; I.modifyIORef r f; I.readIORef r }")) (list "IO" 105)) (hk-test "import: two imports in different positions" (hk-deep-force (hk-run "import qualified Data.IORef as I helper x = x * 2 import qualified Data.Map as M main = do { r <- I.newIORef (helper 21); I.readIORef r }")) (list "IO" 42)) (hk-test "import: unqualified, mid-file" (hk-deep-force (hk-run "go x = x import Data.IORef main = go 9")) 9)