2
2
{-# OPTIONS_GHC -Wno-orphans #-}
3
3
{-# LANGUAGE DisambiguateRecordFields #-}
4
4
{-# LANGUAGE NamedFieldPuns #-}
5
+ {-# LANGUAGE TypeOperators #-}
5
6
module Main
6
7
( main
7
8
) where
@@ -12,6 +13,7 @@ import qualified Data.ByteString as BS
12
13
import Data.Either (isRight )
13
14
import Data.Function
14
15
import qualified Data.Text as Text
16
+ import Debug.Trace
15
17
import Development.IDE.Types.Logger
16
18
import Ide.Plugin.Cabal
17
19
import Ide.Plugin.Cabal.LicenseSuggest (licenseErrorSuggestion )
@@ -26,7 +28,7 @@ cabalPlugin recorder = descriptor recorder "cabal"
26
28
27
29
main :: IO ()
28
30
main = do
29
- recorder <- initialiseRecorder True
31
+ recorder <- initialiseRecorder False
30
32
defaultTestRunner $
31
33
testGroup " Cabal Plugin Tests"
32
34
[ unitTests
@@ -75,11 +77,13 @@ codeActionUnitTests = testGroup "Code Action Tests"
75
77
licenseErrorSuggestion " Unknown license identifier: 'BSD3' Do you mean BSD-3-Clause?" @?= [] ,
76
78
77
79
testCase " BSD-3-Clause" $ do
78
- licenseErrorSuggestion " Unknown SPDX license identifier: 'BSD3' Do you mean BSD-3-Clause?" @?= [(" BSD3" , " BSD-3-Clause" )],
80
+ take 2 (licenseErrorSuggestion " Unknown SPDX license identifier: 'BSD3' Do you mean BSD-3-Clause?" )
81
+ @?= [(" BSD3" ," BSD-3-Clause" ),(" BSD3" ," BSD-3-Clause-LBNL" )],
79
82
80
- testCase " MIT " $ do
83
+ testCase " MiT " $ do
81
84
-- contains no suggestion
82
- licenseErrorSuggestion " Unknown SPDX license identifier: 'MIT3'" @?= [(" MIT3" , " MIT" )]
85
+ take 2 (licenseErrorSuggestion " Unknown SPDX license identifier: 'MiT'" )
86
+ @?= [(" MiT" ," MIT" ),(" MiT" ," MIT-0" )]
83
87
]
84
88
85
89
-- ------------------------------------------------------------------------
@@ -139,7 +143,7 @@ pluginTests recorder = testGroup "Plugin Tests"
139
143
length diags @?= 1
140
144
reduceDiag ^. J. range @?= Range (Position 3 24 ) (Position 4 0 )
141
145
reduceDiag ^. J. severity @?= Just DsError
142
- [codeAction] <- getLicenseAction " BSD-3-Clause" <$> getCodeActions doc (Range (Position 3 24 ) (Position 4 0 ))
146
+ [codeAction] <- getLicenseAction " BSD-3-Clause" <$> getCodeActions doc (Range (Position 3 24 ) (Position 4 0 ))
143
147
executeCodeAction codeAction
144
148
contents <- documentContents doc
145
149
liftIO $ contents @?= Text. unlines
@@ -154,14 +158,17 @@ pluginTests recorder = testGroup "Plugin Tests"
154
158
]
155
159
, runCabalTestCaseSession " Apache-2.0" recorder " " $ do
156
160
doc <- openDoc " licenseCodeAction2.cabal" " cabal"
157
- diags <- waitForDiagnosticsFromSource doc " parsing "
161
+ diags <- waitForDiagnosticsFromSource doc " cabal "
158
162
-- test if it supports typos in license name, here 'apahe'
159
- reduceDiag <- liftIO $ inspectDiagnostic diags [" Unknown SPDX license identifier: 'apahe'" ]
163
+ reduceDiag <- liftIO $ inspectDiagnostic diags [" Unknown SPDX license identifier: 'APAHE'" ]
164
+ traceShowM (reduceDiag)
160
165
liftIO $ do
161
166
length diags @?= 1
162
167
reduceDiag ^. J. range @?= Range (Position 3 25 ) (Position 4 0 )
163
168
reduceDiag ^. J. severity @?= Just DsError
164
- [codeAction] <- getLicenseAction " Apache-2.0" <$> getCodeActions doc (Range (Position 3 24 ) (Position 4 0 ))
169
+ cas <- getCodeActions doc (Range (Position 3 24 ) (Position 4 0 ))
170
+ traceShowM cas
171
+ [codeAction] <- pure $ getLicenseAction " Apache-2.0" cas
165
172
executeCodeAction codeAction
166
173
contents <- documentContents doc
167
174
liftIO $ contents @?= Text. unlines
@@ -177,10 +184,10 @@ pluginTests recorder = testGroup "Plugin Tests"
177
184
]
178
185
]
179
186
where
180
- getLicenseAction :: Text. Text -> [( |? ) Command CodeAction ] -> [CodeAction ]
187
+ getLicenseAction :: Text. Text -> [Command |? CodeAction ] -> [CodeAction ]
181
188
getLicenseAction license codeActions = do
182
189
InR action@ CodeAction {_title} <- codeActions
183
- guard (_title== " Replace with " <> license)
190
+ guard (_title== " Replace with " <> license)
184
191
pure action
185
192
186
193
-- ------------------------------------------------------------------------
0 commit comments