Skip to content

Commit a953ecb

Browse files
committed
tests
1 parent d616c54 commit a953ecb

File tree

8 files changed

+80
-4
lines changed

8 files changed

+80
-4
lines changed

haskell-language-server.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ test-suite hls-cabal-plugin-tests
281281
Completer
282282
Context
283283
Utils
284+
Outline
284285
build-depends:
285286
, base
286287
, bytestring

plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/Outline.hs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
{-# LANGUAGE RecordWildCards #-}
77
{-# LANGUAGE ViewPatterns #-}
88

9-
module Ide.Plugin.Cabal.Outline
10-
( moduleOutline,
11-
)
12-
where
9+
module Ide.Plugin.Cabal.Outline where
1310

1411
import Control.Monad.IO.Class
1512
import Data.Maybe

plugins/hls-cabal-plugin/test/Main.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import qualified Data.Text as Text
1616
import Ide.Plugin.Cabal.LicenseSuggest (licenseErrorSuggestion)
1717
import qualified Ide.Plugin.Cabal.Parse as Lib
1818
import qualified Language.LSP.Protocol.Lens as L
19+
import Outline (outlineTests)
1920
import System.FilePath
2021
import Test.Hls
2122
import Utils
@@ -29,6 +30,7 @@ main = do
2930
, pluginTests
3031
, completerTests
3132
, contextTests
33+
, outlineTests
3234
]
3335

3436
-- ------------------------------------------------------------------------
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{-# LANGUAGE DisambiguateRecordFields #-}
2+
{-# LANGUAGE OverloadedStrings #-}
3+
4+
module Outline (
5+
outlineTests
6+
) where
7+
8+
import qualified Ide.Plugin.Cabal.Outline as Outline
9+
import qualified Language.LSP.Protocol.Types as LSP
10+
import Test.Hls
11+
import Utils
12+
13+
testSymbols :: (HasCallStack) => TestName -> FilePath -> [DocumentSymbol] -> TestTree
14+
testSymbols testName path expectedSymbols =
15+
runCabalTestCaseSession testName "outline-cabal" $ do
16+
docId <- openDoc path "cabal"
17+
symbols <- getDocumentSymbols docId
18+
liftIO $ symbols @?= Right expectedSymbols
19+
20+
outlineTests :: TestTree
21+
outlineTests =
22+
testGroup
23+
"Cabal Outline Tests"
24+
[ testSymbols
25+
"cabal Field outline test"
26+
"field.cabal"
27+
[fieldDocumentSymbol],
28+
testSymbols
29+
"cabal FieldLine outline test"
30+
"fieldline.cabal"
31+
[fieldLineDocumentSymbol],
32+
testSymbols
33+
"cabal Section outline test"
34+
"section.cabal"
35+
[sectionDocumentSymbol],
36+
testSymbols
37+
"cabal SectionArg outline test"
38+
"sectionarg.cabal"
39+
[sectionArgDocumentSymbol]
40+
]
41+
where
42+
fieldDocumentSymbol = (Outline.defDocumentSymbol (LSP.Range {_start = LSP.Position {_line = 0, _character = 0},
43+
_end = LSP.Position {_line = 0, _character = 8}}))
44+
{ LSP._name = "homepage",
45+
LSP._kind = LSP.SymbolKind_Field,
46+
LSP._children = Nothing
47+
}
48+
fieldLineDocumentSymbol = (Outline.defDocumentSymbol (LSP.Range {_start = LSP.Position {_line = 0, _character = 0},
49+
_end = LSP.Position {_line = 0, _character = 13}}))
50+
{ LSP._name = "cabal-version",
51+
LSP._kind = LSP.SymbolKind_Field,
52+
LSP._children = Nothing -- the values of fieldLine are removed from the outline
53+
}
54+
sectionDocumentSymbol = (Outline.defDocumentSymbol (LSP.Range {_start = LSP.Position {_line = 0, _character = 2},
55+
_end = LSP.Position {_line = 0, _character = 15}}))
56+
{ LSP._name = "build-depends",
57+
LSP._kind = LSP.SymbolKind_Field,
58+
LSP._children = Nothing -- the values of fieldLine are removed from the outline
59+
}
60+
sectionArgDocumentSymbol = (Outline.defDocumentSymbol (LSP.Range {_start = LSP.Position {_line = 0, _character = 2},
61+
_end = LSP.Position {_line = 0, _character = 19}}))
62+
{ LSP._name = "if os ( windows )",
63+
LSP._kind = LSP.SymbolKind_Object,
64+
LSP._children = Just $ [sectionArgChildrenDocumentSymbol] }
65+
sectionArgChildrenDocumentSymbol = (Outline.defDocumentSymbol (LSP.Range {_start = LSP.Position {_line = 1, _character = 4},
66+
_end = LSP.Position {_line = 1, _character = 17}}))
67+
{ LSP._name = "build-depends",
68+
LSP._kind = LSP.SymbolKind_Field,
69+
LSP._children = Nothing
70+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
homepage:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cabal-version: 3.0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build-depends:
2+
base >=4.16 && <5
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
if os(windows)
2+
build-depends: Win32

0 commit comments

Comments
 (0)