1
- {-# LANGUAGE DuplicateRecordFields #-}
2
- {-# LANGUAGE OverloadedStrings #-}
3
- {-# LANGUAGE ScopedTypeVariables #-}
4
- module Main (
5
- main ,
6
- ) where
1
+ {-# LANGUAGE OverloadedStrings #-}
2
+ module Main
3
+ ( main
4
+ ) where
7
5
8
6
import Control.Lens ((^.) )
9
- import qualified Data.Text as T
10
- import qualified Data.Text.IO as T
11
- import qualified Data.Text.Lazy as TL
12
- import qualified Data.Text.Lazy.Encoding as TL
13
7
import qualified Ide.Plugin.Pragmas as Pragmas
14
8
import qualified Language.LSP.Types.Lens as L
15
9
import System.FilePath
@@ -31,78 +25,62 @@ tests =
31
25
codeActionTests :: TestTree
32
26
codeActionTests =
33
27
testGroup " code actions"
34
- [ pragmasGolden " adds TypeSynonymInstances pragma" " NeedsPragmas" $ \ path -> do
35
- doc <- openDoc path " haskell"
28
+ [ goldenWithPragmas " adds TypeSynonymInstances pragma" " NeedsPragmas" $ \ doc -> do
36
29
_ <- waitForDiagnosticsFromSource doc " typecheck"
37
30
cas <- map fromAction <$> getAllCodeActions doc
38
31
liftIO $ " Add \" TypeSynonymInstances\" " `elem` map (^. L. title) cas @? " Contains TypeSynonymInstances code action"
39
32
liftIO $ " Add \" FlexibleInstances\" " `elem` map (^. L. title) cas @? " Contains FlexibleInstances code action"
40
33
executeCodeAction $ head cas
41
- documentContents doc
42
34
43
- , pragmasGolden " adds TypeApplications pragma" " TypeApplications" $ \ path -> do
44
- doc <- openDoc path " haskell"
35
+ , goldenWithPragmas " adds TypeApplications pragma" " TypeApplications" $ \ doc -> do
45
36
_ <- waitForDiagnosticsFrom doc
46
37
cas <- map fromAction <$> getAllCodeActions doc
47
38
liftIO $ " Add \" TypeApplications\" " `elem` map (^. L. title) cas @? " Contains TypeApplications code action"
48
39
executeCodeAction $ head cas
49
- documentContents doc
50
40
51
- , pragmasGolden " no duplication" " NamedFieldPuns" $ \ path -> do
52
- doc <- openDoc path " haskell"
41
+ , goldenWithPragmas " no duplication" " NamedFieldPuns" $ \ doc -> do
53
42
_ <- waitForDiagnosticsFrom doc
54
43
cas <- map fromAction <$> getCodeActions doc (Range (Position 8 9 ) (Position 8 9 ))
55
44
liftIO $ length cas == 1 @? " Expected one code action, but got: " <> show cas
56
45
let ca = head cas
57
46
liftIO $ (ca ^. L. title == " Add \" NamedFieldPuns\" " ) @? " NamedFieldPuns code action"
58
47
executeCodeAction ca
59
- documentContents doc
60
48
61
- , pragmasGolden " after shebang" " AfterShebang" $ \ path -> do
62
- doc <- openDoc path " haskell"
49
+ , goldenWithPragmas " after shebang" " AfterShebang" $ \ doc -> do
63
50
_ <- waitForDiagnosticsFrom doc
64
51
cas <- map fromAction <$> getAllCodeActions doc
65
52
liftIO $ " Add \" NamedFieldPuns\" " `elem` map (^. L. title) cas @? " Contains NamedFieldPuns code action"
66
53
executeCodeAction $ head cas
67
- documentContents doc
68
54
69
- , pragmasGolden " append to existing pragmas" " AppendToExisting" $ \ path -> do
70
- doc <- openDoc path " haskell"
55
+ , goldenWithPragmas " append to existing pragmas" " AppendToExisting" $ \ doc -> do
71
56
_ <- waitForDiagnosticsFrom doc
72
57
cas <- map fromAction <$> getAllCodeActions doc
73
58
liftIO $ " Add \" NamedFieldPuns\" " `elem` map (^. L. title) cas @? " Contains NamedFieldPuns code action"
74
59
executeCodeAction $ head cas
75
- documentContents doc
76
60
77
- , pragmasGolden " before doc comments" " BeforeDocComment" $ \ path -> do
78
- doc <- openDoc path " haskell"
61
+ , goldenWithPragmas " before doc comments" " BeforeDocComment" $ \ doc -> do
79
62
_ <- waitForDiagnosticsFrom doc
80
63
cas <- map fromAction <$> getAllCodeActions doc
81
64
liftIO $ " Add \" NamedFieldPuns\" " `elem` map (^. L. title) cas @? " Contains NamedFieldPuns code action"
82
65
executeCodeAction $ head cas
83
- documentContents doc
84
66
85
- , pragmasGolden " before doc comments" " MissingSignatures" $ \ path -> do
86
- doc <- openDoc path " haskell"
67
+ , goldenWithPragmas " before doc comments" " MissingSignatures" $ \ doc -> do
87
68
_ <- waitForDiagnosticsFrom doc
88
69
cas <- map fromAction <$> getAllCodeActions doc
89
70
liftIO $ " Disable \" missing-signatures\" warnings" `elem` map (^. L. title) cas @? " Contains missing-signatures code action"
90
71
executeCodeAction $ head cas
91
- documentContents doc
92
72
93
- , pragmasGolden " before doc comments" " UnusedImports" $ \ path -> do
94
- doc <- openDoc path " haskell"
73
+ , goldenWithPragmas " before doc comments" " UnusedImports" $ \ doc -> do
95
74
_ <- waitForDiagnosticsFrom doc
96
75
cas <- map fromAction <$> getAllCodeActions doc
97
76
liftIO $ " Disable \" unused-imports\" warnings" `elem` map (^. L. title) cas @? " Contains unused-imports code action"
98
77
executeCodeAction $ head cas
99
- documentContents doc
100
78
]
101
79
102
80
completionTests :: TestTree
103
81
completionTests =
104
82
testGroup " completions"
105
- [ testCase " completes pragmas" $ runSessionWithServer pragmasPlugin testDirectory $ do
83
+ [ testCase " completes pragmas" $ runSessionWithServer pragmasPlugin testDataDir $ do
106
84
doc <- openDoc " Completion.hs" " haskell"
107
85
_ <- waitForDiagnostics
108
86
let te = TextEdit (Range (Position 0 4 ) (Position 0 34 )) " "
@@ -115,7 +93,7 @@ completionTests =
115
93
item ^. L. insertTextFormat @?= Just Snippet
116
94
item ^. L. insertText @?= Just " LANGUAGE ${1:extension} #-}"
117
95
118
- , testCase " completes pragmas no close" $ runSessionWithServer pragmasPlugin testDirectory $ do
96
+ , testCase " completes pragmas no close" $ runSessionWithServer pragmasPlugin testDataDir $ do
119
97
doc <- openDoc " Completion.hs" " haskell"
120
98
let te = TextEdit (Range (Position 0 4 ) (Position 0 24 )) " "
121
99
_ <- applyEdit doc te
@@ -127,7 +105,7 @@ completionTests =
127
105
item ^. L. insertTextFormat @?= Just Snippet
128
106
item ^. L. insertText @?= Just " LANGUAGE ${1:extension}"
129
107
130
- , testCase " completes options pragma" $ runSessionWithServer pragmasPlugin testDirectory $ do
108
+ , testCase " completes options pragma" $ runSessionWithServer pragmasPlugin testDataDir $ do
131
109
doc <- openDoc " Completion.hs" " haskell"
132
110
_ <- waitForDiagnostics
133
111
let te = TextEdit (Range (Position 0 4 ) (Position 0 34 )) " OPTIONS"
@@ -140,7 +118,7 @@ completionTests =
140
118
item ^. L. insertTextFormat @?= Just Snippet
141
119
item ^. L. insertText @?= Just " OPTIONS_GHC -${1:option} #-}"
142
120
143
- , testCase " completes ghc options pragma values" $ runSessionWithServer pragmasPlugin testDirectory $ do
121
+ , testCase " completes ghc options pragma values" $ runSessionWithServer pragmasPlugin testDataDir $ do
144
122
doc <- openDoc " Completion.hs" " haskell"
145
123
let te = TextEdit (Range (Position 0 0 ) (Position 0 0 )) " {-# OPTIONS_GHC -Wno-red #-}\n "
146
124
_ <- applyEdit doc te
@@ -152,7 +130,7 @@ completionTests =
152
130
item ^. L. insertTextFormat @?= Nothing
153
131
item ^. L. insertText @?= Nothing
154
132
155
- , testCase " completes language extensions" $ runSessionWithServer pragmasPlugin testDirectory $ do
133
+ , testCase " completes language extensions" $ runSessionWithServer pragmasPlugin testDataDir $ do
156
134
doc <- openDoc " Completion.hs" " haskell"
157
135
_ <- waitForDiagnostics
158
136
let te = TextEdit (Range (Position 0 24 ) (Position 0 31 )) " "
@@ -163,7 +141,7 @@ completionTests =
163
141
item ^. L. label @?= " OverloadedStrings"
164
142
item ^. L. kind @?= Just CiKeyword
165
143
166
- , testCase " completes the Strict language extension" $ runSessionWithServer pragmasPlugin testDirectory $ do
144
+ , testCase " completes the Strict language extension" $ runSessionWithServer pragmasPlugin testDataDir $ do
167
145
doc <- openDoc " Completion.hs" " haskell"
168
146
_ <- waitForDiagnostics
169
147
let te = TextEdit (Range (Position 0 13 ) (Position 0 31 )) " Str"
@@ -174,7 +152,7 @@ completionTests =
174
152
item ^. L. label @?= " Strict"
175
153
item ^. L. kind @?= Just CiKeyword
176
154
177
- , testCase " completes No- language extensions" $ runSessionWithServer pragmasPlugin testDirectory $ do
155
+ , testCase " completes No- language extensions" $ runSessionWithServer pragmasPlugin testDataDir $ do
178
156
doc <- openDoc " Completion.hs" " haskell"
179
157
_ <- waitForDiagnostics
180
158
let te = TextEdit (Range (Position 0 13 ) (Position 0 31 )) " NoOverload"
@@ -186,12 +164,8 @@ completionTests =
186
164
item ^. L. kind @?= Just CiKeyword
187
165
]
188
166
189
- pragmasGolden :: TestName -> FilePath -> (FilePath -> Session T. Text ) -> TestTree
190
- pragmasGolden title path action =
191
- goldenGitDiff title (testDirectory </> path <.> " expected.hs" )
192
- $ runSessionWithServer pragmasPlugin testDirectory
193
- $ TL. encodeUtf8 . TL. fromStrict
194
- <$> action (path <.> " hs" )
167
+ goldenWithPragmas :: TestName -> FilePath -> (TextDocumentIdentifier -> Session () ) -> TestTree
168
+ goldenWithPragmas title path = goldenWithHaskellDoc pragmasPlugin title testDataDir path " expected" " hs"
195
169
196
- testDirectory :: FilePath
197
- testDirectory = " test" </> " testdata"
170
+ testDataDir :: FilePath
171
+ testDataDir = " test" </> " testdata"
0 commit comments