From 50bd268c21d659e1f1650495815cfe4205ea5562 Mon Sep 17 00:00:00 2001 From: Ishmum Jawad Khan Date: Wed, 24 Feb 2021 01:05:00 +0600 Subject: [PATCH] [test] test added for pragma addition after shebang --- test/functional/FunctionalCodeAction.hs | 29 ++++++++++++++++++++++++ test/testdata/addPragmas/AfterShebang.hs | 12 ++++++++++ 2 files changed, 41 insertions(+) create mode 100644 test/testdata/addPragmas/AfterShebang.hs diff --git a/test/functional/FunctionalCodeAction.hs b/test/functional/FunctionalCodeAction.hs index 116843390a..8bf0803799 100644 --- a/test/functional/FunctionalCodeAction.hs +++ b/test/functional/FunctionalCodeAction.hs @@ -561,6 +561,35 @@ missingPragmaTests = testGroup "missing pragma warning code actions" [ , "" , "f Record{a, b} = a" ] + liftIO $ T.lines contents @?= expected + , testCase "After Shebang" $ do + runSession hlsCommand fullCaps "test/testdata/addPragmas" $ do + doc <- openDoc "AfterShebang.hs" "haskell" + + _ <- waitForDiagnosticsFrom doc + cas <- map fromAction <$> getAllCodeActions doc + + liftIO $ "Add \"NamedFieldPuns\"" `elem` map (^. L.title) cas @? "Contains NamedFieldPuns code action" + + executeCodeAction $ head cas + + contents <- documentContents doc + + let expected = + [ "#! /usr/bin/env nix-shell" + , "#! nix-shell --pure -i runghc -p \"haskellPackages.ghcWithPackages (hp: with hp; [ turtle ])\"" + , "" + , "{-# LANGUAGE NamedFieldPuns #-}" + , "module AfterShebang where" + , "" + , "data Record = Record" + , " { a :: Int," + , " b :: Double," + , " c :: String" + , " }" + , "" + , "f Record{a, b} = a" + ] liftIO $ T.lines contents @?= expected ] diff --git a/test/testdata/addPragmas/AfterShebang.hs b/test/testdata/addPragmas/AfterShebang.hs new file mode 100644 index 0000000000..7abb60bc4b --- /dev/null +++ b/test/testdata/addPragmas/AfterShebang.hs @@ -0,0 +1,12 @@ +#! /usr/bin/env nix-shell +#! nix-shell --pure -i runghc -p "haskellPackages.ghcWithPackages (hp: with hp; [ turtle ])" + +module AfterShebang where + +data Record = Record + { a :: Int, + b :: Double, + c :: String + } + +f Record{a, b} = a