forked from haskell/haskell-language-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.hs
57 lines (48 loc) · 2.26 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
module Main
( main
) where
import Control.Monad (void)
import qualified Ide.Plugin.ModuleName as ModuleName
import System.FilePath
import Test.Hls
main :: IO ()
main = defaultTestRunner tests
moduleNamePlugin :: PluginDescriptor IdeState
moduleNamePlugin = ModuleName.descriptor mempty "moduleName"
tests :: TestTree
tests =
testGroup "moduleName"
[ goldenWithModuleName "Add module header to empty module" "TEmptyModule" $ \doc -> do
[CodeLens { _command = Just c }] <- getCodeLenses doc
executeCommand c
void $ skipManyTill anyMessage (message SWorkspaceApplyEdit)
, goldenWithModuleName "Fix wrong module name" "TWrongModuleName" $ \doc -> do
[CodeLens { _command = Just c }] <- getCodeLenses doc
executeCommand c
void $ skipManyTill anyMessage (message SWorkspaceApplyEdit)
, goldenWithModuleName "Must infer module name as Main, if the file name starts with a lowercase" "mainlike" $ \doc -> do
[CodeLens { _command = Just c }] <- getCodeLenses doc
executeCommand c
void $ skipManyTill anyMessage (message SWorkspaceApplyEdit)
, goldenWithModuleName "Fix wrong module name in nested directory" "subdir/TWrongModuleName" $ \doc -> do
[CodeLens { _command = Just c }] <- getCodeLenses doc
executeCommand c
void $ skipManyTill anyMessage (message SWorkspaceApplyEdit)
, testCase "Should not show code lens if the module name is correct" $
runSessionWithServer moduleNamePlugin testDataDir $ do
doc <- openDoc "CorrectName.hs" "haskell"
lenses <- getCodeLenses doc
liftIO $ lenses @?= []
closeDoc doc
-- https://github.com/haskell/haskell-language-server/issues/3047
, goldenWithModuleName "Fix#3047" "canonicalize/Lib/A" $ \doc -> do
[CodeLens { _command = Just c }] <- getCodeLenses doc
executeCommand c
void $ skipManyTill anyMessage (message SWorkspaceApplyEdit)
]
goldenWithModuleName :: TestName -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree
goldenWithModuleName title path = goldenWithHaskellDoc moduleNamePlugin title testDataDir path "expected" "hs"
testDataDir :: FilePath
testDataDir = "test" </> "testdata"