diff --git a/test/functional/Format.hs b/test/functional/Format.hs index 4b58b6d793..75968373b7 100644 --- a/test/functional/Format.hs +++ b/test/functional/Format.hs @@ -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 diff --git a/test/testdata/format/Format.floskell.formatted.hs b/test/testdata/format/Format.floskell.formatted.hs index ac0b2ebfb6..99879567c0 100644 --- a/test/testdata/format/Format.floskell.formatted.hs +++ b/test/testdata/format/Format.floskell.formatted.hs @@ -1,7 +1,7 @@ module Format where -import Data.List import Data.Int +import Data.List import Prelude foo :: Int -> Int @@ -14,4 +14,3 @@ bar s = do return "asdf" data Baz = Baz { a :: Int, b :: String } - diff --git a/test/testdata/format/Format.floskell.initial.hs b/test/testdata/format/Format.floskell.initial.hs new file mode 100644 index 0000000000..02de9c673d --- /dev/null +++ b/test/testdata/format/Format.floskell.initial.hs @@ -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 } + diff --git a/test/testdata/format/Format.ormolu_post_floskell.formatted.hs b/test/testdata/format/Format.ormolu_post_floskell.formatted.hs new file mode 100644 index 0000000000..ac43b2d285 --- /dev/null +++ b/test/testdata/format/Format.ormolu_post_floskell.formatted.hs @@ -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}