Skip to content

Commit c61f27a

Browse files
committed
Add test cases for stylish-haskell
1 parent 1b790db commit c61f27a

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

test/functional/Format.hs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ tests = testGroup "format document" [
2424
documentContents doc >>= liftIO . (`shouldBe` formattedDocTabSize5)
2525
, rangeTests
2626
, providerTests
27+
, stylishHaskellTests
2728
, brittanyTests
2829
, ormoluTests
2930
]
@@ -68,6 +69,38 @@ providerTests = testGroup "formatting provider" [
6869
documentContents doc >>= liftIO . (`shouldBe` formattedBrittanyPostFloskell)
6970
]
7071

72+
stylishHaskellTests :: TestTree
73+
stylishHaskellTests = testGroup "stylish-haskell" [
74+
testCase "formats a file" $ runSession hieCommand fullCaps "test/testdata" $ do
75+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "stylish-haskell"))
76+
doc <- openDoc "StylishHaskell.hs" "haskell"
77+
formatDoc doc (FormattingOptions 2 True)
78+
contents <- documentContents doc
79+
liftIO $ contents `shouldBe`
80+
"import Data.Char\n\
81+
\import qualified Data.List\n\
82+
\import Data.String\n\
83+
\\n\
84+
\bar :: Maybe (Either String Integer) -> Integer\n\
85+
\bar Nothing = 0\n\
86+
\bar (Just (Left _)) = 0\n\
87+
\bar (Just (Right x)) = x\n"
88+
, testCase "formats a range" $ runSession hieCommand fullCaps "test/testdata" $ do
89+
sendNotification WorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "stylish-haskell"))
90+
doc <- openDoc "StylishHaskell.hs" "haskell"
91+
formatRange doc (FormattingOptions 2 True) (Range (Position 0 0) (Position 2 21))
92+
contents <- documentContents doc
93+
liftIO $ contents `shouldBe`
94+
"import Data.Char\n\
95+
\import qualified Data.List\n\
96+
\import Data.String\n\
97+
\\n\
98+
\bar :: Maybe (Either String Integer) -> Integer\n\
99+
\bar Nothing = 0\n\
100+
\bar (Just (Left _)) = 0\n\
101+
\bar (Just (Right x)) = x\n"
102+
]
103+
71104
brittanyTests :: TestTree
72105
brittanyTests = testGroup "brittany" [
73106
ignoreTestBecause "Broken" $ testCase "formats a document with LF endings" $ runSession hieCommand fullCaps "test/testdata" $ do

test/testdata/StylishHaskell.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Data.Char
2+
import qualified Data.List
3+
import Data.String
4+
5+
bar :: Maybe (Either String Integer) -> Integer
6+
bar Nothing = 0
7+
bar (Just (Left _)) = 0
8+
bar (Just (Right x)) = x

0 commit comments

Comments
 (0)