Skip to content

Commit 2e1d118

Browse files
committed
Share combineResponses document definition and document type definition tests
1 parent 9bbf42a commit 2e1d118

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

hls-plugin-api/test/Ide/TypesTests.hs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
{-# LANGUAGE DerivingStrategies #-}
2-
{-# LANGUAGE TypeOperators #-}
1+
{-# LANGUAGE DerivingStrategies #-}
2+
{-# LANGUAGE DuplicateRecordFields #-}
3+
{-# LANGUAGE TypeOperators #-}
34
module Ide.TypesTests
45
( tests
56
) where
@@ -25,6 +26,7 @@ import Language.LSP.Protocol.Types (ClientCapabilities,
2526
Range (Range),
2627
TextDocumentClientCapabilities (TextDocumentClientCapabilities, _definition),
2728
TextDocumentIdentifier (TextDocumentIdentifier),
29+
TypeDefinitionParams (..),
2830
Uri (Uri), filePathToUri,
2931
type (|?) (..))
3032
import Test.Tasty (TestTree, testGroup)
@@ -37,19 +39,26 @@ tests = testGroup "PluginTypes"
3739
combineResponsesTests :: TestTree
3840
combineResponsesTests = testGroup "combineResponses"
3941
[ combineResponsesTextDocumentDefinitionTests
42+
, combineResponsesTextDocumentTypeDefinitionTests
4043
]
4144

4245
combineResponsesTextDocumentDefinitionTests :: TestTree
43-
combineResponsesTextDocumentDefinitionTests = testGroup "TextDocumentDefinition"
44-
[ testCase "merges all single location responses into one response with all locations and upgrades them into links (with link support)" $ do
46+
combineResponsesTextDocumentDefinitionTests = testGroup "TextDocumentDefinition" $
47+
defAndTypeDefSharedTests SMethod_TextDocumentDefinition definitionParams
48+
49+
combineResponsesTextDocumentTypeDefinitionTests :: TestTree
50+
combineResponsesTextDocumentTypeDefinitionTests = testGroup "TextDocumentTypeDefinition" $
51+
defAndTypeDefSharedTests SMethod_TextDocumentTypeDefinition typeDefinitionParams
52+
53+
defAndTypeDefSharedTests message params = [ testCase "merges all single location responses into one response with all locations and upgrades them into links (with link support)" $ do
4554
let pluginResponses :: NonEmpty (Definition |? ([DefinitionLink] |? Null))
4655
pluginResponses =
4756
(InL . Definition . InL . Location testFileUri $ range1) :|
4857
[ InL . Definition . InL . Location testFileUri $ range2
4958
, InL . Definition . InL . Location testFileUri $ range3
5059
]
5160

52-
result = combineResponses SMethod_TextDocumentDefinition def supportsLinkInDefinitionCaps definitionParams pluginResponses
61+
result = combineResponses message def supportsLinkInDefinitionCaps params pluginResponses
5362

5463
expectedResult :: Definition |? ([DefinitionLink] |? Null)
5564
expectedResult = InR . InL $
@@ -69,7 +78,7 @@ combineResponsesTextDocumentDefinitionTests = testGroup "TextDocumentDefinition"
6978
]
7079
]
7180

72-
result = combineResponses SMethod_TextDocumentDefinition def supportsLinkInDefinitionCaps definitionParams pluginResponses
81+
result = combineResponses message def supportsLinkInDefinitionCaps params pluginResponses
7382

7483
expectedResult :: Definition |? ([DefinitionLink] |? Null)
7584
expectedResult = InR . InL $
@@ -87,7 +96,7 @@ combineResponsesTextDocumentDefinitionTests = testGroup "TextDocumentDefinition"
8796
, InL . Definition . InR $ [Location testFileUri range3]
8897
]
8998

90-
result = combineResponses SMethod_TextDocumentDefinition def supportsLinkInDefinitionCaps definitionParams pluginResponses
99+
result = combineResponses message def supportsLinkInDefinitionCaps params pluginResponses
91100

92101
expectedResult :: Definition |? ([DefinitionLink] |? Null)
93102
expectedResult = InR . InL $
@@ -105,7 +114,7 @@ combineResponsesTextDocumentDefinitionTests = testGroup "TextDocumentDefinition"
105114
, InL . Definition . InR $ [Location testFileUri range3]
106115
]
107116

108-
result = combineResponses SMethod_TextDocumentDefinition def supportsLinkInDefinitionCaps definitionParams pluginResponses
117+
result = combineResponses message def supportsLinkInDefinitionCaps params pluginResponses
109118

110119
expectedResult :: Definition |? ([DefinitionLink] |? Null)
111120
expectedResult = InR . InL $
@@ -122,7 +131,7 @@ combineResponsesTextDocumentDefinitionTests = testGroup "TextDocumentDefinition"
122131
, InR . InR $ Null
123132
]
124133

125-
result = combineResponses SMethod_TextDocumentDefinition def supportsLinkInDefinitionCaps definitionParams pluginResponses
134+
result = combineResponses message def supportsLinkInDefinitionCaps params pluginResponses
126135

127136
expectedResult :: Definition |? ([DefinitionLink] |? Null)
128137
expectedResult = InR . InR $ Null
@@ -145,5 +154,13 @@ definitionParams = DefinitionParams
145154
, _partialResultToken = Nothing
146155
}
147156

157+
typeDefinitionParams :: TypeDefinitionParams
158+
typeDefinitionParams = TypeDefinitionParams
159+
{ _textDocument = TextDocumentIdentifier testFileUri
160+
, _position = Position 5 4
161+
, _workDoneToken = Nothing
162+
, _partialResultToken = Nothing
163+
}
164+
148165
testFileUri :: Uri
149166
testFileUri = filePathToUri "file://tester/Test.hs"

0 commit comments

Comments
 (0)