|
2 | 2 | {-# LANGUAGE OverloadedStrings #-}
|
3 | 3 | {-# LANGUAGE ScopedTypeVariables #-}
|
4 | 4 |
|
5 |
| -module Eval (tests) where |
| 5 | +module Eval |
| 6 | + ( tests |
| 7 | + ) |
| 8 | +where |
6 | 9 |
|
7 |
| -import Control.Applicative.Combinators (skipManyTill) |
8 |
| -import Control.Monad.IO.Class (MonadIO (liftIO)) |
9 |
| -import qualified Data.Text.IO as T |
| 10 | +import Control.Applicative.Combinators |
| 11 | + ( skipManyTill ) |
| 12 | +import Control.Monad.IO.Class ( MonadIO(liftIO) ) |
| 13 | +import qualified Data.Text.IO as T |
10 | 14 | import Language.Haskell.LSP.Test
|
11 |
| -import Language.Haskell.LSP.Types (ApplyWorkspaceEditRequest, |
12 |
| - CodeLens (CodeLens, _command, _range), |
13 |
| - Command (_title), |
14 |
| - Position (..), Range (..)) |
| 15 | +import Language.Haskell.LSP.Types ( ApplyWorkspaceEditRequest |
| 16 | + , CodeLens |
| 17 | + ( CodeLens |
| 18 | + , _command |
| 19 | + , _range |
| 20 | + ) |
| 21 | + , Command(_title) |
| 22 | + , Position(..) |
| 23 | + , Range(..) |
| 24 | + ) |
15 | 25 | import System.FilePath
|
16 | 26 | import Test.Hls.Util
|
17 | 27 | import Test.Tasty
|
18 | 28 | import Test.Tasty.HUnit
|
19 | 29 |
|
20 | 30 | tests :: TestTree
|
21 |
| -tests = |
22 |
| - testGroup |
23 |
| - "eval" |
24 |
| - [ testCase "Produces Evaluate code lenses" $ do |
25 |
| - runSession hieCommand fullCaps evalPath $ do |
26 |
| - doc <- openDoc "T1.hs" "haskell" |
27 |
| - lenses <- getCodeLenses doc |
28 |
| - liftIO $ map (fmap _title . _command) lenses @?= [Just "Evaluate..."], |
29 |
| - testCase "Produces Refresh code lenses" $ do |
30 |
| - runSession hieCommand fullCaps evalPath $ do |
31 |
| - doc <- openDoc "T2.hs" "haskell" |
32 |
| - lenses <- getCodeLenses doc |
33 |
| - liftIO $ map (fmap _title . _command) lenses @?= [Just "Refresh..."], |
34 |
| - testCase "Code lenses have ranges" $ do |
35 |
| - runSession hieCommand fullCaps evalPath $ do |
36 |
| - doc <- openDoc "T1.hs" "haskell" |
37 |
| - lenses <- getCodeLenses doc |
38 |
| - liftIO $ map _range lenses @?= [Range (Position 4 0) (Position 4 15)], |
39 |
| - testCase "Multi-line expressions have a multi-line range" $ do |
40 |
| - runSession hieCommand fullCaps evalPath $ do |
41 |
| - doc <- openDoc "T3.hs" "haskell" |
42 |
| - lenses <- getCodeLenses doc |
43 |
| - liftIO $ map _range lenses @?= [Range (Position 3 0) (Position 4 15)], |
44 |
| - testCase "Executed expressions range covers only the expression" $ do |
45 |
| - runSession hieCommand fullCaps evalPath $ do |
46 |
| - doc <- openDoc "T2.hs" "haskell" |
47 |
| - lenses <- getCodeLenses doc |
48 |
| - liftIO $ map _range lenses @?= [Range (Position 4 0) (Position 4 15)], |
49 |
| - testCase "Evaluation of expressions" $ goldenTest "T1.hs", |
50 |
| - testCase "Reevaluation of expressions" $ goldenTest "T2.hs", |
51 |
| - testCase "Evaluation of expressions w/ imports" $ goldenTest "T3.hs", |
52 |
| - testCase "Evaluation of expressions w/ lets" $ goldenTest "T4.hs", |
53 |
| - testCase "Refresh an evaluation" $ goldenTest "T5.hs", |
54 |
| - testCase "Refresh an evaluation w/ lets" $ goldenTest "T6.hs", |
55 |
| - testCase "Refresh a multiline evaluation" $ goldenTest "T7.hs" |
56 |
| - ] |
| 31 | +tests = testGroup |
| 32 | + "eval" |
| 33 | + [ testCase "Produces Evaluate code lenses" $ do |
| 34 | + runSession hieCommand fullCaps evalPath $ do |
| 35 | + doc <- openDoc "T1.hs" "haskell" |
| 36 | + lenses <- getCodeLenses doc |
| 37 | + liftIO $ map (fmap _title . _command) lenses @?= [Just "Evaluate..."] |
| 38 | + , testCase "Produces Refresh code lenses" $ do |
| 39 | + runSession hieCommand fullCaps evalPath $ do |
| 40 | + doc <- openDoc "T2.hs" "haskell" |
| 41 | + lenses <- getCodeLenses doc |
| 42 | + liftIO $ map (fmap _title . _command) lenses @?= [Just "Refresh..."] |
| 43 | + , testCase "Code lenses have ranges" $ do |
| 44 | + runSession hieCommand fullCaps evalPath $ do |
| 45 | + doc <- openDoc "T1.hs" "haskell" |
| 46 | + lenses <- getCodeLenses doc |
| 47 | + liftIO $ map _range lenses @?= [Range (Position 4 0) (Position 4 15)] |
| 48 | + , testCase "Multi-line expressions have a multi-line range" $ do |
| 49 | + runSession hieCommand fullCaps evalPath $ do |
| 50 | + doc <- openDoc "T3.hs" "haskell" |
| 51 | + lenses <- getCodeLenses doc |
| 52 | + liftIO $ map _range lenses @?= [Range (Position 3 0) (Position 4 15)] |
| 53 | + , testCase "Executed expressions range covers only the expression" $ do |
| 54 | + runSession hieCommand fullCaps evalPath $ do |
| 55 | + doc <- openDoc "T2.hs" "haskell" |
| 56 | + lenses <- getCodeLenses doc |
| 57 | + liftIO $ map _range lenses @?= [Range (Position 4 0) (Position 4 15)] |
| 58 | + , testCase "Evaluation of expressions" $ goldenTest "T1.hs" |
| 59 | + , testCase "Reevaluation of expressions" $ goldenTest "T2.hs" |
| 60 | + , testCase "Evaluation of expressions w/ imports" $ goldenTest "T3.hs" |
| 61 | + , testCase "Evaluation of expressions w/ lets" $ goldenTest "T4.hs" |
| 62 | + , testCase "Refresh an evaluation" $ goldenTest "T5.hs" |
| 63 | + , testCase "Refresh an evaluation w/ lets" $ goldenTest "T6.hs" |
| 64 | + , testCase "Refresh a multiline evaluation" $ goldenTest "T7.hs" |
| 65 | + , testCase "Evaluate incorrect expressions" $ goldenTest "T8.hs" |
| 66 | + ] |
57 | 67 |
|
58 | 68 | goldenTest :: FilePath -> IO ()
|
59 | 69 | goldenTest input = runSession hieCommand fullCaps evalPath $ do
|
60 |
| - doc <- openDoc input "haskell" |
61 |
| - [CodeLens {_command = Just c}] <- getCodeLenses doc |
| 70 | + doc <- openDoc input "haskell" |
| 71 | + [CodeLens { _command = Just c }] <- getCodeLenses doc |
62 | 72 | executeCommand c
|
63 | 73 | _resp :: ApplyWorkspaceEditRequest <- skipManyTill anyMessage message
|
64 | 74 | edited <- documentContents doc
|
|
0 commit comments