@@ -17,14 +17,14 @@ import Test.Hspec.Expectations
17
17
18
18
tests :: TestTree
19
19
tests = testGroup " format document" [
20
- ignoreTestBecause " Broken " $ testCase " works " $ runSession hieCommand fullCaps " test/testdata" $ do
20
+ goldenVsStringDiff " works " goldenGitDiff " test/testdata/Format.formatted_document.hs " $ runSession hieCommand fullCaps " test/testdata" $ do
21
21
doc <- openDoc " Format.hs" " haskell"
22
22
formatDoc doc (FormattingOptions 2 True )
23
- documentContents doc >>= liftIO . ( `shouldBe` formattedDocTabSize2)
24
- , ignoreTestBecause " Broken " $ testCase " works with custom tab size" $ runSession hieCommand fullCaps " test/testdata" $ do
23
+ BS. fromStrict . T. encodeUtf8 <$> documentContents doc
24
+ , goldenVsStringDiff " works with custom tab size" goldenGitDiff " test/testdata/Format.formatted_document_with_tabsize.hs " $ runSession hieCommand fullCaps " test/testdata" $ do
25
25
doc <- openDoc " Format.hs" " haskell"
26
26
formatDoc doc (FormattingOptions 5 True )
27
- documentContents doc >>= liftIO . ( `shouldBe` formattedDocTabSize5)
27
+ BS. fromStrict . T. encodeUtf8 <$> documentContents doc
28
28
, rangeTests
29
29
, providerTests
30
30
, stylishHaskellTests
@@ -34,14 +34,14 @@ tests = testGroup "format document" [
34
34
35
35
rangeTests :: TestTree
36
36
rangeTests = testGroup " format range" [
37
- ignoreTestBecause " Broken " $ testCase " works " $ runSession hieCommand fullCaps " test/testdata" $ do
37
+ goldenVsStringDiff " works " goldenGitDiff " test/testdata/Format.formatted_range.hs " $ runSession hieCommand fullCaps " test/testdata" $ do
38
38
doc <- openDoc " Format.hs" " haskell"
39
39
formatRange doc (FormattingOptions 2 True ) (Range (Position 1 0 ) (Position 3 10 ))
40
- documentContents doc >>= liftIO . ( `shouldBe` formattedRangeTabSize2)
41
- , ignoreTestBecause " Broken " $ testCase " works with custom tab size" $ runSession hieCommand fullCaps " test/testdata" $ do
40
+ BS. fromStrict . T. encodeUtf8 <$> documentContents doc
41
+ , goldenVsStringDiff " works with custom tab size" goldenGitDiff " test/testdata/Format.formatted_range_with_tabsize.hs " $ runSession hieCommand fullCaps " test/testdata" $ do
42
42
doc <- openDoc " Format.hs" " haskell"
43
43
formatRange doc (FormattingOptions 5 True ) (Range (Position 4 0 ) (Position 7 19 ))
44
- documentContents doc >>= liftIO . ( `shouldBe` formattedRangeTabSize5)
44
+ BS. fromStrict . T. encodeUtf8 <$> documentContents doc
45
45
]
46
46
47
47
providerTests :: TestTree
@@ -61,7 +61,7 @@ providerTests = testGroup "formatting provider" [
61
61
62
62
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig " brittany" ))
63
63
formatDoc doc (FormattingOptions 2 True )
64
- documentContents doc >>= liftIO . (`shouldBe` formattedDocTabSize2 )
64
+ documentContents doc >>= liftIO . (`shouldBe` formattedBrittany )
65
65
66
66
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig " floskell" ))
67
67
formatDoc doc (FormattingOptions 2 True )
@@ -74,68 +74,58 @@ providerTests = testGroup "formatting provider" [
74
74
75
75
stylishHaskellTests :: TestTree
76
76
stylishHaskellTests = testGroup " stylish-haskell" [
77
- goldenVsStringDiff " formats a document" goldenGitDiff " test/testdata/StylishHaksell.format_document .hs" $ runSession hieCommand fullCaps " test/testdata" $ do
77
+ goldenVsStringDiff " formats a document" goldenGitDiff " test/testdata/StylishHaksell.formatted_document .hs" $ runSession hieCommand fullCaps " test/testdata" $ do
78
78
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig " stylish-haskell" ))
79
79
doc <- openDoc " StylishHaskell.hs" " haskell"
80
80
formatDoc doc (FormattingOptions 2 True )
81
- contents <- documentContents doc
82
- return $ BS. fromStrict $ T. encodeUtf8 contents
83
- , goldenVsStringDiff " formats a range" goldenGitDiff " test/testdata/StylishHaksell.format_range.hs" $ runSession hieCommand fullCaps " test/testdata" $ do
81
+ BS. fromStrict . T. encodeUtf8 <$> documentContents doc
82
+ , goldenVsStringDiff " formats a range" goldenGitDiff " test/testdata/StylishHaksell.formatted_range.hs" $ runSession hieCommand fullCaps " test/testdata" $ do
84
83
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig " stylish-haskell" ))
85
84
doc <- openDoc " StylishHaskell.hs" " haskell"
86
85
formatRange doc (FormattingOptions 2 True ) (Range (Position 0 0 ) (Position 2 21 ))
87
- contents <- documentContents doc
88
- return $ BS. fromStrict $ T. encodeUtf8 contents
86
+ BS. fromStrict . T. encodeUtf8 <$> documentContents doc
89
87
]
90
88
91
89
brittanyTests :: TestTree
92
90
brittanyTests = testGroup " brittany" [
93
- ignoreTestBecause " Broken " $ testCase " formats a document with LF endings" $ runSession hieCommand fullCaps " test/testdata" $ do
91
+ goldenVsStringDiff " formats a document with LF endings" goldenGitDiff " test/testdata/BrittanyLF.formatted_document.hs " $ runSession hieCommand fullCaps " test/testdata" $ do
94
92
doc <- openDoc " BrittanyLF.hs" " haskell"
95
- let opts = DocumentFormattingParams doc (FormattingOptions 4 True ) Nothing
96
- ResponseMessage _ _ (Right edits) <- request TextDocumentFormatting opts
97
- liftIO $ edits `shouldBe` [TextEdit (Range (Position 0 0 ) (Position 3 0 ))
98
- " foo :: Int -> String -> IO ()\n foo x y = do\n print x\n return 42\n " ]
93
+ formatDoc doc (FormattingOptions 4 True )
94
+ BS. fromStrict . T. encodeUtf8 <$> documentContents doc
99
95
100
- , ignoreTestBecause " Broken " $ testCase " formats a document with CRLF endings" $ runSession hieCommand fullCaps " test/testdata" $ do
96
+ , goldenVsStringDiff " formats a document with CRLF endings" goldenGitDiff " test/testdata/BrittanyCRLF.formatted_document.hs " $ runSession hieCommand fullCaps " test/testdata" $ do
101
97
doc <- openDoc " BrittanyCRLF.hs" " haskell"
102
- let opts = DocumentFormattingParams doc (FormattingOptions 4 True ) Nothing
103
- ResponseMessage _ _ (Right edits) <- request TextDocumentFormatting opts
104
- liftIO $ edits `shouldBe` [TextEdit (Range (Position 0 0 ) (Position 3 0 ))
105
- " foo :: Int -> String -> IO ()\n foo x y = do\n print x\n return 42\n " ]
98
+ formatDoc doc (FormattingOptions 4 True )
99
+ BS. fromStrict . T. encodeUtf8 <$> documentContents doc
106
100
107
- , ignoreTestBecause " Broken " $ testCase " formats a range with LF endings" $ runSession hieCommand fullCaps " test/testdata" $ do
101
+ , goldenVsStringDiff " formats a range with LF endings" goldenGitDiff " test/testdata/BrittanyLF.formatted_range.hs " $ runSession hieCommand fullCaps " test/testdata" $ do
108
102
doc <- openDoc " BrittanyLF.hs" " haskell"
109
103
let range = Range (Position 1 0 ) (Position 2 22 )
110
- opts = DocumentRangeFormattingParams doc range (FormattingOptions 4 True ) Nothing
111
- ResponseMessage _ _ (Right edits) <- request TextDocumentRangeFormatting opts
112
- liftIO $ edits `shouldBe` [TextEdit (Range (Position 1 0 ) (Position 3 0 ))
113
- " foo x y = do\n print x\n return 42\n " ]
104
+ formatRange doc (FormattingOptions 4 True ) range
105
+ BS. fromStrict . T. encodeUtf8 <$> documentContents doc
114
106
115
- , ignoreTestBecause " Broken " $ testCase " formats a range with CRLF endings" $ runSession hieCommand fullCaps " test/testdata" $ do
107
+ , goldenVsStringDiff " formats a range with CRLF endings" goldenGitDiff " test/testdata/BrittanyCRLF.formatted_range.hs " $ runSession hieCommand fullCaps " test/testdata" $ do
116
108
doc <- openDoc " BrittanyCRLF.hs" " haskell"
117
109
let range = Range (Position 1 0 ) (Position 2 22 )
118
- opts = DocumentRangeFormattingParams doc range (FormattingOptions 4 True ) Nothing
119
- ResponseMessage _ _ (Right edits) <- request TextDocumentRangeFormatting opts
120
- liftIO $ edits `shouldBe` [TextEdit (Range (Position 1 0 ) (Position 3 0 ))
121
- " foo x y = do\n print x\n return 42\n " ]
110
+ formatRange doc (FormattingOptions 4 True ) range
111
+ BS. fromStrict . T. encodeUtf8 <$> documentContents doc
122
112
]
123
113
124
114
ormoluTests :: TestTree
125
115
ormoluTests = testGroup " ormolu" [
126
- ignoreTestBecause " Broken " $ testCase " formats correctly " $ runSession hieCommand fullCaps " test/testdata" $ do
116
+ goldenVsStringDiff " formats correctly " goldenGitDiff ( " test/testdata/Format.ormolu. " ++ ormoluGoldenSuffix ++ " .hs " ) $ runSession hieCommand fullCaps " test/testdata" $ do
127
117
let formatLspConfig provider =
128
118
object [ " languageServerHaskell" .= object [" formattingProvider" .= (provider :: Value )] ]
129
119
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig " ormolu" ))
130
120
doc <- openDoc " Format.hs" " haskell"
131
121
formatDoc doc (FormattingOptions 2 True )
132
- docContent <- documentContents doc
133
- let formatted = liftIO $ docContent `shouldBe` formattedOrmolu
134
- case ghcVersion of
135
- GHC88 -> formatted
136
- GHC86 -> formatted
137
- _ -> liftIO $ docContent `shouldBe` unchangedOrmolu
122
+ BS. fromStrict . T. encodeUtf8 <$> documentContents doc
138
123
]
124
+ where
125
+ ormoluGoldenSuffix = case ghcVersion of
126
+ GHC88 -> " formatted"
127
+ GHC86 -> " formatted"
128
+ _ -> " unchanged"
139
129
140
130
141
131
formatLspConfig :: Value -> Value
@@ -148,8 +138,8 @@ goldenGitDiff :: FilePath -> FilePath -> [String]
148
138
goldenGitDiff fRef fNew = [" git" , " diff" , " --no-index" , " --text" , " --exit-code" , fRef, fNew]
149
139
150
140
151
- formattedDocTabSize2 :: T. Text
152
- formattedDocTabSize2 =
141
+ formattedBrittany :: T. Text
142
+ formattedBrittany =
153
143
" module Format where\n \
154
144
\foo :: Int -> Int\n \
155
145
\foo 3 = 2\n \
@@ -160,44 +150,6 @@ formattedDocTabSize2 =
160
150
\ return \" asdf\"\n\n \
161
151
\data Baz = Baz { a :: Int, b :: String }\n\n "
162
152
163
- formattedDocTabSize5 :: T. Text
164
- formattedDocTabSize5 =
165
- " module Format where\n \
166
- \foo :: Int -> Int\n \
167
- \foo 3 = 2\n \
168
- \foo x = x\n \
169
- \bar :: String -> IO String\n \
170
- \bar s = do\n \
171
- \ x <- return \" hello\"\n \
172
- \ return \" asdf\"\n\n \
173
- \data Baz = Baz { a :: Int, b :: String }\n\n "
174
-
175
- formattedRangeTabSize2 :: T. Text
176
- formattedRangeTabSize2 =
177
- " module Format where\n \
178
- \foo :: Int -> Int\n \
179
- \foo 3 = 2\n \
180
- \foo x = x\n \
181
- \bar :: String -> IO String\n \
182
- \bar s = do\n \
183
- \ x <- return \" hello\"\n \
184
- \ return \" asdf\"\n \
185
- \\n \
186
- \data Baz = Baz { a :: Int, b :: String }\n\n "
187
-
188
- formattedRangeTabSize5 :: T. Text
189
- formattedRangeTabSize5 =
190
- " module Format where\n \
191
- \foo :: Int -> Int\n \
192
- \foo 3 = 2\n \
193
- \foo x = x\n \
194
- \bar :: String -> IO String\n \
195
- \bar s = do\n \
196
- \ x <- return \" hello\"\n \
197
- \ return \" asdf\"\n \
198
- \\n \
199
- \data Baz = Baz { a :: Int, b :: String }\n\n "
200
-
201
153
formattedFloskell :: T. Text
202
154
formattedFloskell =
203
155
" module Format where\n \
@@ -225,30 +177,3 @@ formattedBrittanyPostFloskell =
225
177
\ x <- return \" hello\"\n \
226
178
\ return \" asdf\"\n\n \
227
179
\data Baz = Baz { a :: Int, b :: String }\n\n "
228
-
229
- formattedOrmolu :: T. Text
230
- formattedOrmolu =
231
- " module Format where\n \
232
- \\n \
233
- \foo :: Int -> Int\n \
234
- \foo 3 = 2\n \
235
- \foo x = x\n \
236
- \\n \
237
- \bar :: String -> IO String\n \
238
- \bar s = do\n \
239
- \ x <- return \" hello\"\n \
240
- \ return \" asdf\"\n\n \
241
- \data Baz = Baz {a :: Int, b :: String}\n "
242
-
243
- unchangedOrmolu :: T. Text
244
- unchangedOrmolu =
245
- " module Format where\n \
246
- \foo :: Int -> Int\n \
247
- \foo 3 = 2\n \
248
- \foo x = x\n \
249
- \bar :: String -> IO String\n \
250
- \bar s = do\n \
251
- \ x <- return \" hello\"\n \
252
- \ return \" asdf\"\n \
253
- \\n \
254
- \data Baz = Baz { a :: Int, b :: String }\n\n "
0 commit comments