Something weird on the test.

I think (0,0) based edits are not applied properly
This commit is contained in:
Alan Zimmerman 2018-10-22 20:43:28 +02:00
parent 8b810a02ad
commit b094536193
4 changed files with 53 additions and 7 deletions

1
.gitignore vendored
View File

@ -61,3 +61,4 @@ test-logs/
.DS_Store
.hspec-failures
/test/testdata/addPragmas/stack.yaml

View File

@ -5,11 +5,11 @@ module Haskell.Ide.Engine.Plugin.Pragmas where
import Control.Lens
import Data.Aeson
import qualified Data.HashMap.Strict as H
import qualified Data.Text as T
import qualified GHC.Generics as Generics
import Haskell.Ide.Engine.MonadTypes hiding (_range)
-- import Haskell.Ide.Engine.Plugin.HieExtras
import qualified Data.HashMap.Strict as H
import Data.Monoid ((<>))
import qualified Data.Text as T
import qualified GHC.Generics as Generics
import Haskell.Ide.Engine.MonadTypes hiding (_range)
import qualified Language.Haskell.LSP.Types as J
import qualified Language.Haskell.LSP.Types.Lens as J

View File

@ -46,6 +46,8 @@ spec = describe "code actions" $ do
noDiagnostics
-- ---------------------------------
it "falls back to pre 3.8 code actions" $ runSession hieCommand noLiteralCaps "test/testdata" $ do
doc <- openDoc "ApplyRefact2.hs" "haskell"
@ -63,6 +65,8 @@ spec = describe "code actions" $ do
noDiagnostics
-- -----------------------------------
describe "rename suggestions" $ do
it "works" $ runSession hieCommand noLiteralCaps "test/testdata" $ do
doc <- openDoc "CodeActionRename.hs" "haskell"
@ -79,7 +83,7 @@ spec = describe "code actions" $ do
doc <- openDoc "CodeActionRename.hs" "haskell"
_ <- waitForDiagnosticsSource "ghcmod"
CACommand cmd <- (!! 2) <$> getAllCodeActions doc
let Just (List [Object args]) = cmd ^. L.arguments
Object editParams = args HM.! "fallbackWorkspaceEdit"
@ -92,6 +96,8 @@ spec = describe "code actions" $ do
_:x:_ <- T.lines <$> documentContents doc
liftIO $ x `shouldBe` "foo = putStrLn \"world\""
-- -----------------------------------
it "provides import suggestions and 3.8 code action kinds" $
runSession hieCommand fullCaps "test/testdata" $ do
doc <- openDoc "CodeActionImport.hs" "haskell"
@ -119,6 +125,7 @@ spec = describe "code actions" $ do
contents <- getDocumentEdit doc
liftIO $ contents `shouldBe` "import Control.Monad\nmain :: IO ()\nmain = when True $ putStrLn \"hello\""
-- -----------------------------------
describe "add package suggestions" $ do
it "adds to .cabal files" $ runSession hieCommand fullCaps "test/testdata/addPackageTest/cabal" $ do
@ -167,6 +174,8 @@ spec = describe "code actions" $ do
T.lines contents !! 12 `shouldNotSatisfy` T.isSuffixOf "zlib"
T.lines contents !! 13 `shouldNotSatisfy` T.isSuffixOf "zlib"
-- -----------------------------------
describe "redundant import code actions" $ do
it "remove solitary redundant imports" $
runSession hieCommand fullCaps "test/testdata/redundantImportTest/" $ do
@ -212,6 +221,8 @@ spec = describe "code actions" $ do
\foo :: Int\n\
\foo = fromJust (Just 3)\n"
-- -----------------------------------
describe "typed hole code actions" $ do
it "works" $
runSession hieCommand fullCaps "test/testdata" $ do
@ -278,6 +289,8 @@ spec = describe "code actions" $ do
\ where\n\
\ stuff (A a) = A (a + 1)\n"
-- -----------------------------------
describe "missing top level signature code actions" $
it "Adds top level signature" $
runSession hieCommand fullCaps "test/testdata/" $ do
@ -301,6 +314,38 @@ spec = describe "code actions" $ do
liftIO $ contents `shouldBe` expected
-- -----------------------------------
describe "missing pragma warning code actions" $
it "Adds TypeSynonymInstances pragma" $
runSession hieCommand fullCaps "test/testdata/addPragmas" $ do
doc <- openDoc "NeedsPragmas.hs" "haskell"
_ <- waitForDiagnosticsSource "ghcmod"
cas <- map fromAction <$> getAllCodeActions doc
liftIO $ map (^. L.title) cas `shouldContain` [ "Add \"TypeSynonymInstances\""]
liftIO $ map (^. L.title) cas `shouldContain` [ "Add \"FlexibleInstances\""]
executeCodeAction $ head cas
contents <- documentContents doc
let expected = "\n{-# LANGUAGE \"TypeSynonymInstances\" #-}\n\
\import GHC.Generics\n\n\
\main = putStrLn \"hello\"\n\n\
\type Foo = Int\n\n\
\instance Show Foo where\n\
\ show x = undefined\n\n\
\instance Show (Int,String) where\n\
\ show = undefined\n\n\
\data FFF a = FFF Int String a\n\
\deriving (Generic,Functor,Traversable)\n"
liftIO $ contents `shouldBe` expected
-- ---------------------------------------------------------------------
fromAction :: CAResult -> CodeAction
fromAction (CACodeAction action) = action
fromAction _ = error "Not a code action"

View File

@ -112,7 +112,7 @@ files =
[ "./test/testdata/"
, "./test/testdata/addPackageTest/cabal/"
, "./test/testdata/addPackageTest/hpack/"
, "./test/testdata/addPragmas"
, "./test/testdata/addPragmas/"
, "./test/testdata/completion/"
, "./test/testdata/definition/"
, "./test/testdata/gototest/"