Skip to content

Commit 3614ecc

Browse files
authored
Add a test for #1376 (#1414)
* Add a test for #1376 * add missing files * fix identifiers
1 parent a0d01bb commit 3614ecc

File tree

4 files changed

+49
-13
lines changed

4 files changed

+49
-13
lines changed

test/functional/Format.hs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,39 +57,43 @@ providerTests = testGroup "formatting provider" [
5757
resp <- request STextDocumentFormatting $ DocumentFormattingParams Nothing doc (FormattingOptions 2 True Nothing Nothing Nothing)
5858
liftIO $ resp ^. LSP.result @?= (Left $ ResponseError InvalidRequest "No plugin enabled for STextDocumentFormatting, available: []" Nothing)
5959

60-
#if AGPL
60+
, testCase "respects initial" $ runSessionWithConfig (formatConfig "floskell") hlsCommand fullCaps "test/testdata/format" $ do
61+
doc <- openDoc "Format.hs" "haskell"
62+
formattedFloskell <- liftIO $ T.readFile "test/testdata/format/Format.floskell.initial.hs"
63+
formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing)
64+
documentContents doc >>= liftIO . (@?= formattedFloskell)
65+
6166
, testCase "can change on the fly" $ runSession hlsCommand fullCaps "test/testdata/format" $ do
62-
formattedBrittany <- liftIO $ T.readFile "test/testdata/format/Format.brittany.formatted.hs"
67+
formattedOrmolu <- liftIO $ T.readFile "test/testdata/format/Format.ormolu.formatted.hs"
6368
formattedFloskell <- liftIO $ T.readFile "test/testdata/format/Format.floskell.formatted.hs"
64-
formattedBrittanyPostFloskell <- liftIO $ T.readFile "test/testdata/format/Format.brittany_post_floskell.formatted.hs"
69+
formattedOrmoluPostFloskell <- liftIO $ T.readFile "test/testdata/format/Format.ormolu_post_floskell.formatted.hs"
6570

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

68-
sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "brittany"))
73+
sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "ormolu"))
6974
formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing)
70-
documentContents doc >>= liftIO . (@?= formattedBrittany)
75+
documentContents doc >>= liftIO . (@?= formattedOrmolu)
7176

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

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

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

85-
sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfigOld "brittany"))
90+
sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfigOld "ormolu"))
8691
formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing)
87-
documentContents doc >>= liftIO . (@?= formattedBrittany)
92+
documentContents doc >>= liftIO . (@?= formattedOrmolu)
8893

8994
sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfigOld "floskell"))
9095
formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing)
9196
documentContents doc >>= liftIO . (@?= formattedFloskell)
92-
#endif
9397
]
9498

9599
stylishHaskellTests :: TestTree

test/testdata/format/Format.floskell.formatted.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Format where
22

3-
import Data.List
43
import Data.Int
4+
import Data.List
55
import Prelude
66

77
foo :: Int -> Int
@@ -14,4 +14,3 @@ bar s = do
1414
return "asdf"
1515

1616
data Baz = Baz { a :: Int, b :: String }
17-
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module Format where
2+
3+
import Data.List
4+
import Prelude
5+
import Data.Int
6+
7+
foo :: Int -> Int
8+
foo 3 = 2
9+
foo x = x
10+
11+
bar :: String -> IO String
12+
bar s = do
13+
x <- return "hello"
14+
return "asdf"
15+
16+
data Baz = Baz { a :: Int, b :: String }
17+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Format where
2+
3+
import Data.Int
4+
import Data.List
5+
import Prelude
6+
7+
foo :: Int -> Int
8+
foo 3 = 2
9+
foo x = x
10+
11+
bar :: String -> IO String
12+
bar s = do
13+
x <- return "hello"
14+
return "asdf"
15+
16+
data Baz = Baz {a :: Int, b :: String}

0 commit comments

Comments
 (0)