@@ -9,7 +9,8 @@ import Data.Char (isPrint)
9
9
import qualified Data.Set as Set
10
10
import qualified Data.Text as T
11
11
import qualified Ide.Plugin.RangeMap as RangeMap
12
- import Ide.PluginUtils (positionInRange , unescape )
12
+ import Ide.PluginUtils (extractTextInRange ,
13
+ positionInRange , unescape )
13
14
import Language.LSP.Protocol.Types (Position (.. ), Range (Range ),
14
15
UInt , isSubrangeOf )
15
16
import Test.Tasty
@@ -19,6 +20,7 @@ import Test.Tasty.QuickCheck
19
20
tests :: TestTree
20
21
tests = testGroup " PluginUtils"
21
22
[ unescapeTest
23
+ , extractTextInRangeTest
22
24
, localOption (QuickCheckMaxSize 10000 ) $
23
25
testProperty " RangeMap-List filtering identical" $
24
26
prop_rangemapListEq @ Int
@@ -42,6 +44,57 @@ unescapeTest = testGroup "unescape"
42
44
unescape " \"\\ n\\ t\" " @?= " \"\\ n\\ t\" "
43
45
]
44
46
47
+ extractTextInRangeTest :: TestTree
48
+ extractTextInRangeTest = testGroup " extractTextInRange"
49
+ [ testCase " inline range" $
50
+ extractTextInRange
51
+ ( Range (Position 0 3 ) (Position 3 5 ) )
52
+ src
53
+ @?= T. intercalate " \n "
54
+ [ " ule Main where"
55
+ , " "
56
+ , " main :: IO ()"
57
+ , " main "
58
+ ]
59
+ , testCase " inline range with empty content" $
60
+ extractTextInRange
61
+ ( Range (Position 0 0 ) (Position 0 1 ) )
62
+ emptySrc
63
+ @?= " "
64
+ , testCase " multiline range with empty content" $
65
+ extractTextInRange
66
+ ( Range (Position 0 0 ) (Position 1 0 ) )
67
+ emptySrc
68
+ @?= " \n "
69
+ , testCase " multiline range" $
70
+ extractTextInRange
71
+ ( Range (Position 1 0 ) (Position 4 0 ) )
72
+ src
73
+ @?= T. unlines
74
+ [ " "
75
+ , " main :: IO ()"
76
+ , " main = do"
77
+ ]
78
+ , testCase " multiline range with end pos at the line below the last line" $
79
+ extractTextInRange
80
+ ( Range (Position 2 0 ) (Position 5 0 ) )
81
+ src
82
+ @?= T. unlines
83
+ [ " main :: IO ()"
84
+ , " main = do"
85
+ , " putStrLn \" hello, world\" "
86
+ ]
87
+ ]
88
+ where
89
+ src = T. unlines
90
+ [ " module Main where"
91
+ , " "
92
+ , " main :: IO ()"
93
+ , " main = do"
94
+ , " putStrLn \" hello, world\" "
95
+ ]
96
+ emptySrc = " \n "
97
+
45
98
genRange :: Gen Range
46
99
genRange = oneof [ genRangeInline, genRangeMultiline ]
47
100
0 commit comments