@@ -28,7 +28,8 @@ main = do
28
28
testGroup " Code Range" [
29
29
testGroup " Integration Tests" [
30
30
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"
32
33
],
33
34
testGroup " Unit Tests" [
34
35
Ide.Plugin.CodeRangeTest. testTree,
@@ -64,3 +65,28 @@ makeSelectionRangeGoldenTest recorder testName positions = goldenGitDiff testNam
64
65
showPosition :: Position -> ByteString
65
66
showPosition (Position line col) = " (" <> showLBS (line + 1 ) <> " ," <> showLBS (col + 1 ) <> " )"
66
67
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
0 commit comments