Skip to content

Commit 45a1388

Browse files
committed
Regression tests for Declaration splice and kind-error ones
1 parent 9f8a868 commit 45a1388

File tree

9 files changed

+105
-2
lines changed

9 files changed

+105
-2
lines changed

test/functional/Splice.hs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE OverloadedStrings #-}
12
{-# LANGUAGE ScopedTypeVariables #-}
23
{-# LANGUAGE ViewPatterns #-}
34

@@ -8,6 +9,7 @@ import Control.Monad
89
import Control.Monad.IO.Class
910
import Data.List (find)
1011
import Data.Text (Text)
12+
import qualified Data.Text as T
1113
import qualified Data.Text.IO as T
1214
import Ide.Plugin.Splice.Types
1315
import Language.Haskell.LSP.Test
@@ -17,9 +19,12 @@ import Language.Haskell.LSP.Types
1719
CodeAction (..),
1820
Position (..),
1921
Range (..),
22+
TextDocumentContentChangeEvent (..),
23+
TextEdit (..),
2024
)
2125
import System.Directory
2226
import System.FilePath
27+
import System.Time.Extra (sleep)
2328
import Test.Hls.Util
2429
import Test.Tasty
2530
import Test.Tasty.HUnit
@@ -55,6 +60,9 @@ tests =
5560
, goldenTest "TQQTypeTypeError.hs" Inplace 8 19
5661
, goldenTest "TQQTypeTypeError.hs" Inplace 8 28
5762
, goldenTest "TSimpleDecl.hs" Inplace 8 1
63+
, goldenTest "TQQDecl.hs" Inplace 5 1
64+
, goldenTestWithEdit "TTypeKindError.hs" Inplace 7 9
65+
, goldenTestWithEdit "TDeclKindError.hs" Inplace 8 1
5866
]
5967

6068
goldenTest :: FilePath -> ExpandStyle -> Int -> Int -> TestTree
@@ -78,6 +86,38 @@ goldenTest input tc line col =
7886
expected <- liftIO $ T.readFile expected_name
7987
liftIO $ edited @?= expected
8088

89+
goldenTestWithEdit :: FilePath -> ExpandStyle -> Int -> Int -> TestTree
90+
goldenTestWithEdit input tc line col =
91+
testCase (input <> " (golden)") $ do
92+
runSession hlsCommand fullCaps spliceTestPath $ do
93+
doc <- openDoc input "haskell"
94+
orig <- documentContents doc
95+
let lns = T.lines orig
96+
theRange =
97+
Range
98+
{ _start = Position 0 0
99+
, _end = Position (length lns + 1) 1
100+
}
101+
liftIO $ sleep 1
102+
alt <- liftIO $ T.readFile (spliceTestPath </> input <.> "error")
103+
void $ applyEdit doc $ TextEdit theRange alt
104+
changeDoc doc [TextDocumentContentChangeEvent (Just theRange) Nothing alt]
105+
void waitForDiagnostics
106+
actions <- getCodeActions doc $ pointRange line col
107+
Just (CACodeAction CodeAction {_command = Just c}) <-
108+
pure $ find ((== Just (toExpandCmdTitle tc)) . codeActionTitle) actions
109+
executeCommand c
110+
_resp :: ApplyWorkspaceEditRequest <- skipManyTill anyMessage message
111+
edited <- documentContents doc
112+
let expected_name = spliceTestPath </> input <.> "expected"
113+
-- Write golden tests if they don't already exist
114+
liftIO $
115+
(doesFileExist expected_name >>=) $
116+
flip unless $ do
117+
T.writeFile expected_name edited
118+
expected <- liftIO $ T.readFile expected_name
119+
liftIO $ edited @?= expected
120+
81121
spliceTestPath :: FilePath
82122
spliceTestPath = "test/testdata/splice"
83123

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{-# LANGUAGE TemplateHaskell #-}
2+
{-# LANGUAGE QuasiQuotes #-}
3+
module TSimpleDecl where
4+
import Language.Haskell.TH ( mkName, clause, normalB, funD, sigD )
5+
6+
-- Foo
7+
-- Bar
8+
$(sequence
9+
[sigD (mkName "foo") [t|Int|]
10+
,funD (mkName "foo") [clause [] (normalB [|42|]) []]
11+
]
12+
)
13+
-- Bar
14+
-- ee
15+
-- dddd
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{-# LANGUAGE TemplateHaskell #-}
2+
{-# LANGUAGE QuasiQuotes #-}
3+
module TSimpleDecl where
4+
import Language.Haskell.TH ( mkName, clause, normalB, funD, sigD )
5+
6+
-- Foo
7+
-- Bar
8+
$(sequence
9+
[sigD (mkName "foo") [t|Int|]
10+
,funD (mkName "foo") [clause [] (normalB [|42|]) []]
11+
,sigD (mkName "bar") [t|Int|]
12+
]
13+
)
14+
-- Bar
15+
-- ee
16+
-- dddd
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{-# LANGUAGE TemplateHaskell #-}
2+
{-# LANGUAGE QuasiQuotes #-}
3+
module TSimpleDecl where
4+
import Language.Haskell.TH ( mkName, clause, normalB, funD, sigD )
5+
6+
-- Foo
7+
-- Bar
8+
foo :: Int
9+
foo = 42
10+
bar :: Int
11+
-- Bar
12+
-- ee
13+
-- dddd

test/testdata/splice/TQQDecl.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{-# LANGUAGE QuasiQuotes #-}
2+
module TQQDecl where
3+
import QQ (str)
4+
5+
[str|foo|]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{-# LANGUAGE QuasiQuotes #-}
2+
module TQQDecl where
3+
import QQ (str)
4+
5+
foo :: String
6+
foo = "foo"

test/testdata/splice/TTypeKindError.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ module TTypeKindError where
44
import Language.Haskell.TH ( numTyLit, litT )
55
import Data.Proxy ( Proxy )
66

7-
main :: $(litT (numTyLit 42))
7+
main :: IO ()
88
main = return ()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE TemplateHaskell #-}
3+
module TTypeKindError where
4+
import Language.Haskell.TH ( numTyLit, litT )
5+
import Data.Proxy ( Proxy )
6+
7+
main :: $(litT (numTyLit 42))
8+
main = return ()

test/testdata/splice/TTypeKindError.hs.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ module TTypeKindError where
44
import Language.Haskell.TH ( numTyLit, litT )
55
import Data.Proxy ( Proxy )
66

7-
main :: 42
7+
main :: (42)
88
main = return ()

0 commit comments

Comments
 (0)