@@ -15,82 +15,86 @@ spec = do
1515 it " works" $ runSession hieCommand fullCaps " test/testdata" $ do
1616 doc <- openDoc " Format.hs" " haskell"
1717 formatDoc doc (FormattingOptions 2 True )
18- documentContents doc >>= liftIO . (`shouldBe` formattedDocTabSize2)
19- it " works with custom tab size" $ runSession hieCommand fullCaps " test/testdata" $ do
20- doc <- openDoc " Format.hs" " haskell"
21- formatDoc doc (FormattingOptions 5 True )
22- documentContents doc >>= liftIO . (`shouldBe` formattedDocTabSize5)
18+ documentContents doc >>= liftIO . (`shouldBe` formattedDocOrmolu)
19+ it " works with custom tab size" $ do
20+ pendingWith " ormolu does not accept parameters"
21+ -- $ runSession hieCommand fullCaps "test/testdata" $ do
22+ -- doc <- openDoc "Format.hs" "haskell"
23+ -- formatDoc doc (FormattingOptions 5 True)
24+ -- documentContents doc >>= liftIO . (`shouldBe` formattedDocTabSize5)
2325
2426 describe " format range" $ do
2527 it " works" $ runSession hieCommand fullCaps " test/testdata" $ do
2628 doc <- openDoc " Format.hs" " haskell"
2729 formatRange doc (FormattingOptions 2 True ) (Range (Position 1 0 ) (Position 3 10 ))
2830 documentContents doc >>= liftIO . (`shouldBe` formattedRangeTabSize2)
29- it " works with custom tab size" $ runSession hieCommand fullCaps " test/testdata" $ do
30- doc <- openDoc " Format.hs" " haskell"
31- formatRange doc (FormattingOptions 5 True ) (Range (Position 4 0 ) (Position 7 19 ))
32- documentContents doc >>= liftIO . (`shouldBe` formattedRangeTabSize5)
33-
34- describe " formatting provider" $ do
35- let formatLspConfig provider =
36- object [ " languageServerHaskell" .= object [" formattingProvider" .= (provider :: Value )] ]
37- formatConfig provider = defaultConfig { lspConfig = Just (formatLspConfig provider) }
38-
39- it " respects none" $ runSessionWithConfig (formatConfig " none" ) hieCommand fullCaps " test/testdata" $ do
40- doc <- openDoc " Format.hs" " haskell"
41- orig <- documentContents doc
42-
43- formatDoc doc (FormattingOptions 2 True )
44- documentContents doc >>= liftIO . (`shouldBe` orig)
45-
46- formatRange doc (FormattingOptions 2 True ) (Range (Position 1 0 ) (Position 3 10 ))
47- documentContents doc >>= liftIO . (`shouldBe` orig)
48-
49- it " can change on the fly" $ runSession hieCommand fullCaps " test/testdata" $ do
50- doc <- openDoc " Format.hs" " haskell"
51-
52- sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig " brittany" ))
53- formatDoc doc (FormattingOptions 2 True )
54- documentContents doc >>= liftIO . (`shouldBe` formattedDocTabSize2)
55-
56- sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig " floskell" ))
57- formatDoc doc (FormattingOptions 2 True )
58- documentContents doc >>= liftIO . (`shouldBe` formattedFloskell)
59-
60- sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig " brittany" ))
61- formatDoc doc (FormattingOptions 2 True )
62- documentContents doc >>= liftIO . (`shouldBe` formattedBrittanyPostFloskell)
63-
64- describe " brittany" $ do
65- it " formats a document with LF endings" $ runSession hieCommand fullCaps " test/testdata" $ do
66- doc <- openDoc " BrittanyLF.hs" " haskell"
67- let opts = DocumentFormattingParams doc (FormattingOptions 4 True ) Nothing
68- ResponseMessage _ _ (Just edits) _ <- request TextDocumentFormatting opts
69- liftIO $ edits `shouldBe` [TextEdit (Range (Position 0 0 ) (Position 3 0 ))
70- " foo :: Int -> String -> IO ()\n foo x y = do\n print x\n return 42\n " ]
71-
72- it " formats a document with CRLF endings" $ runSession hieCommand fullCaps " test/testdata" $ do
73- doc <- openDoc " BrittanyCRLF.hs" " haskell"
74- let opts = DocumentFormattingParams doc (FormattingOptions 4 True ) Nothing
75- ResponseMessage _ _ (Just edits) _ <- request TextDocumentFormatting opts
76- liftIO $ edits `shouldBe` [TextEdit (Range (Position 0 0 ) (Position 3 0 ))
77- " foo :: Int -> String -> IO ()\n foo x y = do\n print x\n return 42\n " ]
78-
79- it " formats a range with LF endings" $ runSession hieCommand fullCaps " test/testdata" $ do
80- doc <- openDoc " BrittanyLF.hs" " haskell"
81- let range = Range (Position 1 0 ) (Position 2 22 )
82- opts = DocumentRangeFormattingParams doc range (FormattingOptions 4 True ) Nothing
83- ResponseMessage _ _ (Just edits) _ <- request TextDocumentRangeFormatting opts
84- liftIO $ edits `shouldBe` [TextEdit (Range (Position 1 0 ) (Position 3 0 ))
85- " foo x y = do\n print x\n return 42\n " ]
86-
87- it " formats a range with CRLF endings" $ runSession hieCommand fullCaps " test/testdata" $ do
88- doc <- openDoc " BrittanyCRLF.hs" " haskell"
89- let range = Range (Position 1 0 ) (Position 2 22 )
90- opts = DocumentRangeFormattingParams doc range (FormattingOptions 4 True ) Nothing
91- ResponseMessage _ _ (Just edits) _ <- request TextDocumentRangeFormatting opts
92- liftIO $ edits `shouldBe` [TextEdit (Range (Position 1 0 ) (Position 3 0 ))
93- " foo x y = do\n print x\n return 42\n " ]
31+ it " works with custom tab size" $ do
32+ pendingWith " ormolu does not accept parameters"
33+ -- $ runSession hieCommand fullCaps "test/testdata" $ do
34+ -- doc <- openDoc "Format.hs" "haskell"
35+ -- formatRange doc (FormattingOptions 5 True) (Range (Position 4 0) (Position 7 19))
36+ -- documentContents doc >>= liftIO . (`shouldBe` formattedRangeTabSize5)
37+
38+ -- describe "formatting provider" $ do
39+ -- let formatLspConfig provider =
40+ -- object [ "languageServerHaskell" .= object ["formattingProvider" .= (provider :: Value)] ]
41+ -- formatConfig provider = defaultConfig { lspConfig = Just (formatLspConfig provider) }
42+
43+ -- it "respects none" $ runSessionWithConfig (formatConfig "none") hieCommand fullCaps "test/testdata" $ do
44+ -- doc <- openDoc "Format.hs" "haskell"
45+ -- orig <- documentContents doc
46+
47+ -- formatDoc doc (FormattingOptions 2 True)
48+ -- documentContents doc >>= liftIO . (`shouldBe` orig)
49+
50+ -- formatRange doc (FormattingOptions 2 True) (Range (Position 1 0) (Position 3 10))
51+ -- documentContents doc >>= liftIO . (`shouldBe` orig)
52+
53+ -- it "can change on the fly" $ runSession hieCommand fullCaps "test/testdata" $ do
54+ -- doc <- openDoc "Format.hs" "haskell"
55+
56+ -- sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "brittany"))
57+ -- formatDoc doc (FormattingOptions 2 True)
58+ -- documentContents doc >>= liftIO . (`shouldBe` formattedDocTabSize2)
59+
60+ -- sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "floskell"))
61+ -- formatDoc doc (FormattingOptions 2 True)
62+ -- documentContents doc >>= liftIO . (`shouldBe` formattedFloskell)
63+
64+ -- sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "brittany"))
65+ -- formatDoc doc (FormattingOptions 2 True)
66+ -- documentContents doc >>= liftIO . (`shouldBe` formattedBrittanyPostFloskell)
67+
68+ -- describe "brittany" $ do
69+ -- it "formats a document with LF endings" $ runSession hieCommand fullCaps "test/testdata" $ do
70+ -- doc <- openDoc "BrittanyLF.hs" "haskell"
71+ -- let opts = DocumentFormattingParams doc (FormattingOptions 4 True) Nothing
72+ -- ResponseMessage _ _ (Just edits) _ <- request TextDocumentFormatting opts
73+ -- liftIO $ edits `shouldBe` [TextEdit (Range (Position 0 0) (Position 3 0))
74+ -- "foo :: Int -> String -> IO ()\nfoo x y = do\n print x\n return 42\n"]
75+
76+ -- it "formats a document with CRLF endings" $ runSession hieCommand fullCaps "test/testdata" $ do
77+ -- doc <- openDoc "BrittanyCRLF.hs" "haskell"
78+ -- let opts = DocumentFormattingParams doc (FormattingOptions 4 True) Nothing
79+ -- ResponseMessage _ _ (Just edits) _ <- request TextDocumentFormatting opts
80+ -- liftIO $ edits `shouldBe` [TextEdit (Range (Position 0 0) (Position 3 0))
81+ -- "foo :: Int -> String -> IO ()\nfoo x y = do\n print x\n return 42\n"]
82+
83+ -- it "formats a range with LF endings" $ runSession hieCommand fullCaps "test/testdata" $ do
84+ -- doc <- openDoc "BrittanyLF.hs" "haskell"
85+ -- let range = Range (Position 1 0) (Position 2 22)
86+ -- opts = DocumentRangeFormattingParams doc range (FormattingOptions 4 True) Nothing
87+ -- ResponseMessage _ _ (Just edits) _ <- request TextDocumentRangeFormatting opts
88+ -- liftIO $ edits `shouldBe` [TextEdit (Range (Position 1 0) (Position 3 0))
89+ -- "foo x y = do\n print x\n return 42\n"]
90+
91+ -- it "formats a range with CRLF endings" $ runSession hieCommand fullCaps "test/testdata" $ do
92+ -- doc <- openDoc "BrittanyCRLF.hs" "haskell"
93+ -- let range = Range (Position 1 0) (Position 2 22)
94+ -- opts = DocumentRangeFormattingParams doc range (FormattingOptions 4 True) Nothing
95+ -- ResponseMessage _ _ (Just edits) _ <- request TextDocumentRangeFormatting opts
96+ -- liftIO $ edits `shouldBe` [TextEdit (Range (Position 1 0) (Position 3 0))
97+ -- "foo x y = do\n print x\n return 42\n"]
9498
9599 describe " ormolu" $ do
96100 let formatLspConfig provider =
@@ -107,6 +111,16 @@ spec = do
107111 GHC86 -> formatted
108112 _ -> liftIO $ docContent `shouldBe` unchangedOrmolu
109113
114+ formattedDocOrmolu :: T. Text
115+ formattedDocOrmolu =
116+ " module Format where\n\n \
117+ \foo :: Int -> Int\n \
118+ \foo 3 = 2\n \
119+ \foo x = x\n\n \
120+ \bar :: String -> IO String\n \
121+ \bar s = do\n \
122+ \ x <- return \" hello\"\n \
123+ \ return \" asdf\"\n "
110124
111125formattedDocTabSize2 :: T. Text
112126formattedDocTabSize2 =
0 commit comments