Skip to content

Commit 91f90fd

Browse files
committed
Add some more shrinkers
1 parent c9c5ffc commit 91f90fd

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lsp-types/src/Language/LSP/Protocol/Message/LspId.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import qualified Data.Aeson as A
55
import Data.Hashable
66
import Data.IxMap
77
import Data.Text (Text)
8+
import GHC.Generics
89

910
import Language.LSP.Protocol.Types.Common
1011
import Language.LSP.Protocol.Internal.Method
1112
import Language.LSP.Protocol.Message.Meta
1213

1314
-- | Id used for a request, Can be either a String or an Int
1415
data LspId (m :: Method f Request) = IdInt !Int32 | IdString !Text
15-
deriving stock (Show,Read,Eq,Ord)
16+
deriving stock (Show,Read,Eq,Ord,Generic)
1617

1718
instance A.ToJSON (LspId m) where
1819
toJSON (IdInt i) = A.toJSON i

lsp-types/test/JsonSpec.hs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ propertyJsonRoundtrip a = J.Success a === J.fromJSON (J.toJSON a)
9191

9292
instance (Arbitrary a, Arbitrary b) => Arbitrary (a |? b) where
9393
arbitrary = oneof [InL <$> arbitrary, InR <$> arbitrary]
94+
shrink = genericShrink
9495

9596
instance Arbitrary Null where
9697
arbitrary = pure Null
@@ -103,54 +104,66 @@ deriving newtype instance Arbitrary MarkedString
103104

104105
instance Arbitrary MarkupContent where
105106
arbitrary = MarkupContent <$> arbitrary <*> arbitrary
107+
shrink = genericShrink
106108

107109
instance Arbitrary MarkupKind where
108110
arbitrary = oneof [pure MarkupKind_PlainText,pure MarkupKind_Markdown]
111+
shrink = genericShrink
109112

110113
instance Arbitrary UInt where
111114
arbitrary = fromInteger <$> arbitrary
112115

113116
instance Arbitrary Uri where
114117
arbitrary = Uri <$> arbitrary
118+
shrink = genericShrink
115119

116120
--deriving newtype instance Arbitrary URI
117121

118122
instance Arbitrary WorkspaceFolder where
119123
arbitrary = WorkspaceFolder <$> arbitrary <*> arbitrary
124+
shrink = genericShrink
120125

121126
instance Arbitrary RelativePattern where
122127
arbitrary = RelativePattern <$> arbitrary <*> arbitrary
128+
shrink = genericShrink
123129

124130
deriving newtype instance Arbitrary Pattern
125131
deriving newtype instance Arbitrary GlobPattern
126132

127133
instance Arbitrary Position where
128134
arbitrary = Position <$> arbitrary <*> arbitrary
129-
shrink (Position s e) = [ Position s' e' | s' <- shrink s, e' <- shrink e ]
135+
shrink = genericShrink
130136

131137
instance Arbitrary Location where
132138
arbitrary = Location <$> arbitrary <*> arbitrary
139+
shrink = genericShrink
133140

134141
instance Arbitrary Range where
135142
arbitrary = Range <$> arbitrary <*> arbitrary
143+
shrink = genericShrink
136144

137145
instance Arbitrary Hover where
138146
arbitrary = Hover <$> arbitrary <*> arbitrary
147+
shrink = genericShrink
139148

140149
instance {-# OVERLAPPING #-} Arbitrary (Maybe Void) where
141150
arbitrary = pure Nothing
142151

143152
instance (ErrorData m ~ Maybe Void) => Arbitrary (TResponseError m) where
144153
arbitrary = TResponseError <$> arbitrary <*> arbitrary <*> pure Nothing
154+
shrink = genericShrink
145155

146156
instance Arbitrary ResponseError where
147157
arbitrary = ResponseError <$> arbitrary <*> arbitrary <*> pure Nothing
158+
shrink = genericShrink
148159

149160
instance (Arbitrary (MessageResult m), ErrorData m ~ Maybe Void) => Arbitrary (TResponseMessage m) where
150161
arbitrary = TResponseMessage <$> arbitrary <*> arbitrary <*> arbitrary
162+
shrink = genericShrink
151163

152164
instance Arbitrary (LspId m) where
153165
arbitrary = oneof [IdInt <$> arbitrary, IdString <$> arbitrary]
166+
shrink = genericShrink
154167

155168
instance Arbitrary ErrorCodes where
156169
arbitrary =
@@ -163,6 +176,7 @@ instance Arbitrary ErrorCodes where
163176
, ErrorCodes_ServerNotInitialized
164177
, ErrorCodes_UnknownErrorCode
165178
]
179+
shrink = genericShrink
166180

167181
instance Arbitrary LSPErrorCodes where
168182
arbitrary =
@@ -172,19 +186,24 @@ instance Arbitrary LSPErrorCodes where
172186
, LSPErrorCodes_ContentModified
173187
, LSPErrorCodes_RequestCancelled
174188
]
189+
shrink = genericShrink
175190
-- ---------------------------------------------------------------------
176191

177192
instance Arbitrary DidChangeWatchedFilesRegistrationOptions where
178193
arbitrary = DidChangeWatchedFilesRegistrationOptions <$> arbitrary
194+
shrink = genericShrink
179195

180196
instance Arbitrary FileSystemWatcher where
181197
arbitrary = FileSystemWatcher <$> arbitrary <*> arbitrary
198+
shrink = genericShrink
182199

183200
-- TODO: watchKind is weird
184201
instance Arbitrary WatchKind where
185202
arbitrary = oneof [pure WatchKind_Change, pure WatchKind_Create, pure WatchKind_Delete]
203+
shrink = genericShrink
186204

187205
-- ---------------------------------------------------------------------
188206
--
189207
instance Arbitrary TextDocumentContentChangeEvent where
190208
arbitrary = TextDocumentContentChangeEvent <$> arbitrary
209+
shrink = genericShrink

0 commit comments

Comments
 (0)