Skip to content

Commit 769797c

Browse files
committed
Format tests pass for Ormolu
1 parent 2521a7f commit 769797c

File tree

4 files changed

+94
-79
lines changed

4 files changed

+94
-79
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ stack*.yaml.lock
1313
shake.yaml.lock
1414

1515
.vscode
16+
/test-logs/

stack.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ extra-deps:
3030
- temporary-1.2.1.1
3131
- topograph-1
3232

33-
# flags:
34-
# haskell-language-server:
35-
# pedantic: true
33+
flags:
34+
haskell-language-server:
35+
pedantic: true
3636

3737
# allow-newer: true
3838

test/functional/FormatSpec.hs

Lines changed: 84 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -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 ()\nfoo 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 ()\nfoo 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

111125
formattedDocTabSize2 :: T.Text
112126
formattedDocTabSize2 =

test/utils/TestUtils.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,33 @@ module TestUtils
2323
)
2424
where
2525

26-
import Control.Concurrent.STM
26+
-- import Control.Concurrent.STM
2727
import Control.Monad
2828
import Data.Aeson.Types (typeMismatch)
2929
import Data.Default
3030
import Data.List (intercalate)
3131
import Data.Text (pack)
32-
import Data.Typeable
32+
-- import Data.Typeable
3333
import Data.Yaml
34-
import qualified Data.Map as Map
34+
-- import qualified Data.Map as Map
3535
import Data.Maybe
3636
import Language.Haskell.LSP.Core
3737
import Language.Haskell.LSP.Types
3838
-- import Haskell.Ide.Engine.MonadTypes hiding (withProgress, withIndefiniteProgress)
39-
import qualified Ide.Cradle as Bios
39+
-- import qualified Ide.Cradle as Bios
4040
-- import qualified Ide.Engine.Config as Config
4141
import System.Directory
4242
import System.Environment
4343
import System.FilePath
4444
import qualified System.Log.Logger as L
45-
import Test.Hspec
45+
-- import Test.Hspec
4646
import Test.Hspec.Runner
4747
import Test.Hspec.Core.Formatters
4848
import Text.Blaze.Renderer.String (renderMarkup)
4949
import Text.Blaze.Internal
5050
-- import qualified Haskell.Ide.Engine.PluginApi as HIE (BiosOptions, defaultOptions)
5151

52-
import HIE.Bios.Types
52+
-- import HIE.Bios.Types
5353

5454
-- testOptions :: HIE.BiosOptions
5555
-- testOptions = HIE.defaultOptions { cradleOptsVerbosity = Verbose }

0 commit comments

Comments
 (0)