From 0faf2f8e0ac8cb69cb602489d5895d23095d25fd Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Mon, 15 Feb 2021 20:49:13 +0000 Subject: [PATCH 1/3] Add a test for #1376 --- test/functional/Format.hs | 20 +++++++++++-------- .../format/Format.floskell.formatted.hs | 3 +-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/test/functional/Format.hs b/test/functional/Format.hs index 4b58b6d793..539f11358b 100644 --- a/test/functional/Format.hs +++ b/test/functional/Format.hs @@ -57,15 +57,20 @@ 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" + formattedBrittany <- 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" + formattedBrittanyPostFloskell <- 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) @@ -73,23 +78,22 @@ providerTests = testGroup "formatting provider" [ 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) , 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" + formattedBrittany <- 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) 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 } - From 37636b82dc75f7b264a8ea03fcf894e2b86528c9 Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Sat, 20 Feb 2021 13:26:16 +0000 Subject: [PATCH 2/3] add missing files --- test/testdata/format/Format.floskell.initial.hs | 17 +++++++++++++++++ .../Format.ormolu_post_floskell.formatted.hs | 16 ++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 test/testdata/format/Format.floskell.initial.hs create mode 100644 test/testdata/format/Format.ormolu_post_floskell.formatted.hs 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} From 72f303ab69bb7acdc371630a9de9ff9f394dd9ac Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Sat, 20 Feb 2021 14:07:23 +0000 Subject: [PATCH 3/3] fix identifiers --- test/functional/Format.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/functional/Format.hs b/test/functional/Format.hs index 539f11358b..75968373b7 100644 --- a/test/functional/Format.hs +++ b/test/functional/Format.hs @@ -64,15 +64,15 @@ providerTests = testGroup "formatting provider" [ 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.ormolu.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.ormolu_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 "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) @@ -80,16 +80,16 @@ providerTests = testGroup "formatting provider" [ 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.ormolu.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 "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)