|
1 | 1 | {-# LANGUAGE OverloadedStrings #-} |
2 | | -module Main(main) where |
| 2 | +module Main |
| 3 | + ( main |
| 4 | + ) where |
3 | 5 |
|
4 | | -import qualified Data.ByteString.Lazy as BS |
5 | | -import qualified Data.Text.Encoding as T |
6 | | -import qualified Data.Text.IO as T |
7 | 6 | import qualified Ide.Plugin.StylishHaskell as StylishHaskell |
| 7 | +import System.FilePath |
8 | 8 | import Test.Hls |
9 | 9 |
|
10 | 10 | main :: IO () |
11 | 11 | main = defaultTestRunner tests |
12 | 12 |
|
13 | | -plugin :: PluginDescriptor IdeState |
14 | | -plugin = StylishHaskell.descriptor "stylishHaskell" |
| 13 | +stylishHaskellPlugin :: PluginDescriptor IdeState |
| 14 | +stylishHaskellPlugin = StylishHaskell.descriptor "stylishHaskell" |
15 | 15 |
|
16 | 16 | tests :: TestTree |
17 | | -tests = testGroup "stylish-haskell" [ |
18 | | - goldenGitDiff "formats a document" "test/testdata/StylishHaskell.formatted_document.hs" $ runSessionWithServerFormatter plugin "stylishHaskell" "test/testdata" $ do |
19 | | - doc <- openDoc "StylishHaskell.hs" "haskell" |
| 17 | +tests = testGroup "stylish-haskell" |
| 18 | + [ goldenWithStylishHaskell "formats a document" "StylishHaskell" "formatted_document" $ \doc -> do |
20 | 19 | formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing) |
21 | | - BS.fromStrict . T.encodeUtf8 <$> documentContents doc |
22 | | - , goldenGitDiff "formats a range" "test/testdata/StylishHaskell.formatted_range.hs" $ runSessionWithServerFormatter plugin "stylishHaskell" "test/testdata" $ do |
23 | | - doc <- openDoc "StylishHaskell.hs" "haskell" |
| 20 | + , goldenWithStylishHaskell "formats a range" "StylishHaskell" "formatted_range" $ \doc -> do |
24 | 21 | formatRange doc (FormattingOptions 2 True Nothing Nothing Nothing) (Range (Position 0 0) (Position 2 21)) |
25 | | - BS.fromStrict . T.encodeUtf8 <$> documentContents doc |
26 | 22 | ] |
| 23 | + |
| 24 | +goldenWithStylishHaskell :: TestName -> FilePath -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree |
| 25 | +goldenWithStylishHaskell title fp desc = goldenWithHaskellDoc stylishHaskellPlugin title testDataDir fp desc "hs" |
| 26 | + |
| 27 | +testDataDir :: FilePath |
| 28 | +testDataDir = "test" </> "data" |
0 commit comments