Skip to content

Commit a430a43

Browse files
committed
test: add integration test for folding ranges
1 parent 6975302 commit a430a43

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

plugins/hls-code-range-plugin/test/Main.hs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ main = do
2828
testGroup "Code Range" [
2929
testGroup "Integration Tests" [
3030
makeSelectionRangeGoldenTest recorder "Import" [(4, 36), (1, 8)],
31-
makeSelectionRangeGoldenTest recorder "Function" [(5, 19), (5, 12), (4, 4), (3, 5)]
31+
makeSelectionRangeGoldenTest recorder "Function" [(5, 19), (5, 12), (4, 4), (3, 5)],
32+
foldingRangeGoldenTest recorder "Function"
3233
],
3334
testGroup "Unit Tests" [
3435
Ide.Plugin.CodeRangeTest.testTree,
@@ -64,3 +65,28 @@ makeSelectionRangeGoldenTest recorder testName positions = goldenGitDiff testNam
6465
showPosition :: Position -> ByteString
6566
showPosition (Position line col) = "(" <> showLBS (line + 1) <> "," <> showLBS (col + 1) <> ")"
6667
showLBS = fromString . show
68+
69+
foldingRangeGoldenTest :: Recorder (WithPriority Log) -> TestName -> TestTree
70+
foldingRangeGoldenTest recorder testName = goldenGitDiff testName (testDataDir </> testName <.> "golden" <.> "txt") $ do
71+
res <- runSessionWithServer (plugin recorder) testDataDir $ do
72+
doc <- openDoc (testName <.> "hs") "haskell"
73+
resp <- request STextDocumentFoldingRange $ FoldingRangeParams Nothing Nothing doc
74+
let res = resp ^. result
75+
pure $ fmap showFoldingRangesForTest res
76+
77+
case res of
78+
Left err -> assertFailure (show err)
79+
Right golden -> pure golden
80+
81+
where
82+
testDataDir :: FilePath
83+
testDataDir = "test" </> "testdata" </> "folding-range"
84+
85+
showFoldingRangesForTest :: List FoldingRange -> ByteString
86+
showFoldingRangesForTest (List foldingRanges) = LBSChar8.intercalate "\n" $ fmap showFoldingRangeForTest foldingRanges
87+
88+
showFoldingRangeForTest :: FoldingRange -> ByteString
89+
showFoldingRangeForTest f@(FoldingRange sl (Just sc) el (Just ec) (Just frk)) = "((" <> showLBS sl <>", "<> showLBS sc <> ")" <> " : " <> "(" <> showLBS el <>", "<> showLBS ec<> ")) : " <> showFRK frk
90+
91+
showLBS = fromString . show
92+
showFRK = fromString . show
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
((4, 0) : (7, 21)) : FoldingRangeRegion
2+
((4, 0) : (4, 25)) : FoldingRangeRegion
3+
((4, 0) : (4, 6)) : FoldingRangeRegion
4+
((4, 10) : (4, 25)) : FoldingRangeRegion
5+
((4, 10) : (4, 17)) : FoldingRangeRegion
6+
((4, 21) : (4, 25)) : FoldingRangeRegion
7+
((5, 0) : (7, 21)) : FoldingRangeRegion
8+
((5, 0) : (5, 6)) : FoldingRangeRegion
9+
((5, 7) : (5, 8)) : FoldingRangeRegion
10+
((5, 9) : (7, 21)) : FoldingRangeRegion
11+
((5, 11) : (7, 21)) : FoldingRangeRegion
12+
((5, 14) : (5, 28)) : FoldingRangeRegion
13+
((5, 14) : (5, 23)) : FoldingRangeRegion
14+
((5, 14) : (5, 15)) : FoldingRangeRegion
15+
((5, 16) : (5, 21)) : FoldingRangeRegion
16+
((5, 22) : (5, 23)) : FoldingRangeRegion
17+
((5, 24) : (5, 26)) : FoldingRangeRegion
18+
((5, 27) : (5, 28)) : FoldingRangeRegion
19+
((6, 16) : (6, 20)) : FoldingRangeRegion
20+
((7, 16) : (7, 21)) : FoldingRangeRegion
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
2+
{-# HLINT ignore "Use module export list" #-}
3+
module FuncMultiMatch where
4+
5+
isEven :: Integer -> Bool
6+
isEven n = if n `mod` 2 == 0
7+
then True
8+
else False
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
cradle:
2+
direct:
3+
arguments:
4+
- "Function"

0 commit comments

Comments
 (0)