Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions test/functional/Format.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,39 +57,43 @@ providerTests = testGroup "formatting provider" [
resp <- request STextDocumentFormatting $ DocumentFormattingParams Nothing doc (FormattingOptions 2 True Nothing Nothing Nothing)
liftIO $ resp ^. LSP.result @?= (Left $ ResponseError InvalidRequest "No plugin enabled for STextDocumentFormatting, available: []" Nothing)

#if AGPL
, testCase "respects initial" $ runSessionWithConfig (formatConfig "floskell") hlsCommand fullCaps "test/testdata/format" $ do
doc <- openDoc "Format.hs" "haskell"
formattedFloskell <- liftIO $ T.readFile "test/testdata/format/Format.floskell.initial.hs"
formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing)
documentContents doc >>= liftIO . (@?= formattedFloskell)

, testCase "can change on the fly" $ runSession hlsCommand fullCaps "test/testdata/format" $ do
formattedBrittany <- liftIO $ T.readFile "test/testdata/format/Format.brittany.formatted.hs"
formattedOrmolu <- liftIO $ T.readFile "test/testdata/format/Format.ormolu.formatted.hs"
formattedFloskell <- liftIO $ T.readFile "test/testdata/format/Format.floskell.formatted.hs"
formattedBrittanyPostFloskell <- liftIO $ T.readFile "test/testdata/format/Format.brittany_post_floskell.formatted.hs"
formattedOrmoluPostFloskell <- liftIO $ T.readFile "test/testdata/format/Format.ormolu_post_floskell.formatted.hs"

doc <- openDoc "Format.hs" "haskell"

sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "brittany"))
sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "ormolu"))
formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing)
documentContents doc >>= liftIO . (@?= formattedBrittany)
documentContents doc >>= liftIO . (@?= formattedOrmolu)

sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "floskell"))
formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing)
documentContents doc >>= liftIO . (@?= formattedFloskell)

sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "brittany"))
sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "ormolu"))
formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing)
documentContents doc >>= liftIO . (@?= formattedBrittanyPostFloskell)
documentContents doc >>= liftIO . (@?= formattedOrmoluPostFloskell)
, testCase "supports both new and old configuration sections" $ runSession hlsCommand fullCaps "test/testdata/format" $ do
formattedBrittany <- liftIO $ T.readFile "test/testdata/format/Format.brittany.formatted.hs"
formattedOrmolu <- liftIO $ T.readFile "test/testdata/format/Format.ormolu.formatted.hs"
formattedFloskell <- liftIO $ T.readFile "test/testdata/format/Format.floskell.formatted.hs"

doc <- openDoc "Format.hs" "haskell"

sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfigOld "brittany"))
sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfigOld "ormolu"))
formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing)
documentContents doc >>= liftIO . (@?= formattedBrittany)
documentContents doc >>= liftIO . (@?= formattedOrmolu)

sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfigOld "floskell"))
formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing)
documentContents doc >>= liftIO . (@?= formattedFloskell)
#endif
]

stylishHaskellTests :: TestTree
Expand Down
3 changes: 1 addition & 2 deletions test/testdata/format/Format.floskell.formatted.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Format where

import Data.List
import Data.Int
import Data.List
import Prelude

foo :: Int -> Int
Expand All @@ -14,4 +14,3 @@ bar s = do
return "asdf"

data Baz = Baz { a :: Int, b :: String }

17 changes: 17 additions & 0 deletions test/testdata/format/Format.floskell.initial.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Format where

import Data.List
import Prelude
import Data.Int

foo :: Int -> Int
foo 3 = 2
foo x = x

bar :: String -> IO String
bar s = do
x <- return "hello"
return "asdf"

data Baz = Baz { a :: Int, b :: String }

16 changes: 16 additions & 0 deletions test/testdata/format/Format.ormolu_post_floskell.formatted.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Format where

import Data.Int
import Data.List
import Prelude

foo :: Int -> Int
foo 3 = 2
foo x = x

bar :: String -> IO String
bar s = do
x <- return "hello"
return "asdf"

data Baz = Baz {a :: Int, b :: String}