Skip to content

Commit 03efa21

Browse files
committed
Additional Tests.
1 parent 35da971 commit 03efa21

File tree

8 files changed

+52
-1
lines changed

8 files changed

+52
-1
lines changed

plugins/hls-alternate-number-format-plugin/test/Main.hs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,24 @@ test = testGroup "alternateNumberFormat" [
4949
liftIO $ length actions @?= 4
5050
, codeActionProperties "TFindLiteralList" [(3, 28)] $ \actions -> do
5151
liftIO $ length actions @?= 2
52+
, codeActionProperties "TExpectNoBinaryFormat" [(3, 12)] $ \actions -> do
53+
liftIO $ length actions @?= 2
54+
liftIO $ actions `doesNotContain` binaryRegex @? "Contains binary codeAction"
55+
, codeActionProperties "TExpectBinaryFormat" [(4, 10)] $ \actions -> do
56+
liftIO $ length actions @?= 3
57+
liftIO $ actions `contains` binaryRegex @? "Does not contain binary codeAction"
58+
, codeActionProperties "TExpectNoHexFloatFormat" [(3, 14)] $ \actions -> do
59+
liftIO $ length actions @?= 1
60+
liftIO $ actions `doesNotContain` hexFloatRegex @? "Contains hex float codeAction"
61+
, codeActionProperties "TExpectHexFloatFormat" [(4, 12)] $ \actions -> do
62+
liftIO $ length actions @?= 2
63+
liftIO $ actions `contains` hexFloatRegex @? "Does not contain hex float codeAction"
64+
, codeActionProperties "TExpectNoNumDecimalFormat" [(3, 16)] $ \actions -> do
65+
liftIO $ length actions @?= 2
66+
liftIO $ actions `doesNotContain` numDecimalRegex @? "Contains numDecimal codeAction"
67+
, codeActionProperties "TExpectNumDecimalFormat" [(4, 14)] $ \actions -> do
68+
liftIO $ length actions @?= 5
69+
liftIO $ actions `contains` numDecimalRegex @? "Contains numDecimal codeAction"
5270
, conversions
5371
]
5472

@@ -85,7 +103,6 @@ codeActionTest filter' fp line col = goldenAlternateFormat fp $ \doc -> do
85103
Just (InR x) -> executeCodeAction x
86104
_ -> liftIO $ assertFailure "Unable to find CodeAction"
87105

88-
89106
codeActionDecimal :: FilePath -> Int -> Int -> TestTree
90107
codeActionDecimal = codeActionTest isDecimalCodeAction
91108

@@ -111,12 +128,21 @@ codeActionTitle :: (Command |? CodeAction) -> Maybe Text
111128
codeActionTitle (InR CodeAction {_title}) = Just _title
112129
codeActionTitle _ = Nothing
113130

131+
codeActionTitle' :: CodeAction -> Text
132+
codeActionTitle' CodeAction{_title} = _title
133+
114134
pointRange :: Int -> Int -> Range
115135
pointRange
116136
(subtract 1 -> line)
117137
(subtract 1 -> col) =
118138
Range (Position line col) (Position line $ col + 1)
119139

140+
contains :: [CodeAction] -> Text -> Bool
141+
acts `contains` regex = any (\action -> codeActionTitle' action =~ regex) acts
142+
143+
doesNotContain :: [CodeAction] -> Text -> Bool
144+
acts `doesNotContain` regex = not $ acts `contains` regex
145+
120146
convertPrefix, intoInfix, hexRegex, hexFloatRegex, binaryRegex, octalRegex, numDecimalRegex, decimalRegex :: Text
121147
convertPrefix = "Convert (" <> T.intercalate "|" [Conversion.hexRegex, Conversion.hexFloatRegex, Conversion.binaryRegex, Conversion.octalRegex, Conversion.numDecimalRegex, Conversion.decimalRegex] <> ")"
122148
intoInfix = " into "
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{-# LANGUAGE BinaryLiterals #-}
2+
module TExpectBinaryFormat where
3+
4+
binary = 459
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{-# LANGUAGE HexFloatLiterals #-}
2+
module TExpectHexFloatFormat where
3+
4+
hexFloat = 459.123
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module TExpectNoBinaryFormat where
2+
3+
noBinary = 459
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module TExpectNoHexFloatFormat where
2+
3+
noHexFloat = 459.123
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module TExpectNoNumDecimalFormat where
2+
3+
noNumDecimal = 499999
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{-# LANGUAGE NumDecimals #-}
2+
module TExpectNumDecimalFormat where
3+
4+
numDecimal = 499999

plugins/hls-alternate-number-format-plugin/test/testdata/hie.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@ cradle:
1717
- TFindLiteralDoReturn
1818
- TFindLiteralDoLet
1919
- TFindLiteralList
20+
- TExpectNoBinaryFormat
21+
- TExpectBinaryFormat
22+
- TExpectNoHexFloatFormat
23+
- TExpectHexFloatFormat
2024
- -Wall

0 commit comments

Comments
 (0)