@@ -17,14 +17,14 @@ import Test.Hspec.Expectations
1717
1818tests :: TestTree
1919tests = 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
2121 doc <- openDoc " Format.hs" " haskell"
2222 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
2525 doc <- openDoc " Format.hs" " haskell"
2626 formatDoc doc (FormattingOptions 5 True )
27- documentContents doc >>= liftIO . ( `shouldBe` formattedDocTabSize5)
27+ BS. fromStrict . T. encodeUtf8 <$> documentContents doc
2828 , rangeTests
2929 , providerTests
3030 , stylishHaskellTests
@@ -34,14 +34,14 @@ tests = testGroup "format document" [
3434
3535rangeTests :: TestTree
3636rangeTests = 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
3838 doc <- openDoc " Format.hs" " haskell"
3939 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
4242 doc <- openDoc " Format.hs" " haskell"
4343 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
4545 ]
4646
4747providerTests :: TestTree
@@ -61,7 +61,7 @@ providerTests = testGroup "formatting provider" [
6161
6262 sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig " brittany" ))
6363 formatDoc doc (FormattingOptions 2 True )
64- documentContents doc >>= liftIO . (`shouldBe` formattedDocTabSize2 )
64+ documentContents doc >>= liftIO . (`shouldBe` formattedBrittany )
6565
6666 sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig " floskell" ))
6767 formatDoc doc (FormattingOptions 2 True )
@@ -74,68 +74,58 @@ providerTests = testGroup "formatting provider" [
7474
7575stylishHaskellTests :: TestTree
7676stylishHaskellTests = 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
7878 sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig " stylish-haskell" ))
7979 doc <- openDoc " StylishHaskell.hs" " haskell"
8080 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
8483 sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig " stylish-haskell" ))
8584 doc <- openDoc " StylishHaskell.hs" " haskell"
8685 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
8987 ]
9088
9189brittanyTests :: TestTree
9290brittanyTests = 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
9492 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
9995
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
10197 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
106100
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
108102 doc <- openDoc " BrittanyLF.hs" " haskell"
109103 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
114106
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
116108 doc <- openDoc " BrittanyCRLF.hs" " haskell"
117109 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
122112 ]
123113
124114ormoluTests :: TestTree
125115ormoluTests = 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
127117 let formatLspConfig provider =
128118 object [ " languageServerHaskell" .= object [" formattingProvider" .= (provider :: Value )] ]
129119 sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig " ormolu" ))
130120 doc <- openDoc " Format.hs" " haskell"
131121 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
138123 ]
124+ where
125+ ormoluGoldenSuffix = case ghcVersion of
126+ GHC88 -> " formatted"
127+ GHC86 -> " formatted"
128+ _ -> " unchanged"
139129
140130
141131formatLspConfig :: Value -> Value
@@ -148,8 +138,8 @@ goldenGitDiff :: FilePath -> FilePath -> [String]
148138goldenGitDiff fRef fNew = [" git" , " diff" , " --no-index" , " --text" , " --exit-code" , fRef, fNew]
149139
150140
151- formattedDocTabSize2 :: T. Text
152- formattedDocTabSize2 =
141+ formattedBrittany :: T. Text
142+ formattedBrittany =
153143 " module Format where\n \
154144 \foo :: Int -> Int\n \
155145 \foo 3 = 2\n \
@@ -160,44 +150,6 @@ formattedDocTabSize2 =
160150 \ return \" asdf\"\n\n \
161151 \data Baz = Baz { a :: Int, b :: String }\n\n "
162152
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-
201153formattedFloskell :: T. Text
202154formattedFloskell =
203155 " module Format where\n \
@@ -225,30 +177,3 @@ formattedBrittanyPostFloskell =
225177 \ x <- return \" hello\"\n \
226178 \ return \" asdf\"\n\n \
227179 \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