File tree Expand file tree Collapse file tree 2 files changed +43
-3
lines changed
test/Test/Codec/CBOR/Cuddle/CDDL Expand file tree Collapse file tree 2 files changed +43
-3
lines changed Original file line number Diff line number Diff line change @@ -124,9 +124,7 @@ pGroup = Group <$> NE.sepBy1 (space *> pGrpChoice <* space) (string "//")
124
124
pGrpChoice :: Parser GrpChoice
125
125
pGrpChoice =
126
126
many
127
- ( (space *> (noComment <$> pGrpEntry) <* space)
128
- <* optional (char ' ,' )
129
- )
127
+ (try $ (space *> (noComment <$> pGrpEntry) <* space) <* optional (char ' ,' ))
130
128
131
129
pGrpEntry :: Parser GroupEntry
132
130
pGrpEntry =
Original file line number Diff line number Diff line change @@ -182,6 +182,35 @@ type2Spec = describe "type2" $ do
182
182
]
183
183
)
184
184
)
185
+ it " Commas are optional" $
186
+ parse pType2 " " " { 1 => string, 2 => int 3 => bytes}"
187
+ `shouldParse` T2Map
188
+ ( Group
189
+ ( [ WithComments
190
+ ( GEType
191
+ Nothing
192
+ (Just (MKType (Type1 (T2Value (VUInt 1 )) Nothing )))
193
+ (Type0 (Type1 (T2Name (Name " string" ) Nothing ) Nothing NE. :| [] ))
194
+ )
195
+ Nothing
196
+ , WithComments
197
+ ( GEType
198
+ Nothing
199
+ (Just (MKType (Type1 (T2Value (VUInt 2 )) Nothing )))
200
+ (Type0 (Type1 (T2Name (Name " int" ) Nothing ) Nothing NE. :| [] ))
201
+ )
202
+ Nothing
203
+ , WithComments
204
+ ( GEType
205
+ Nothing
206
+ (Just (MKType (Type1 (T2Value (VUInt 3 )) Nothing )))
207
+ (Type0 (Type1 (T2Name (Name " bytes" ) Nothing ) Nothing NE. :| [] ))
208
+ )
209
+ Nothing
210
+ ]
211
+ NE. :| []
212
+ )
213
+ )
185
214
describe " Array" $ do
186
215
it " Parses an array with an alternative" $
187
216
parse pType2 " " " [int // string]"
@@ -236,6 +265,19 @@ type2Spec = describe "type2" $ do
236
265
]
237
266
)
238
267
)
268
+ it " Trailing commas permitted" $
269
+ parse pType2 " " " [ 1 , ]"
270
+ `shouldParse` T2Array
271
+ ( Group
272
+ ( [ noComment $
273
+ GEType
274
+ Nothing
275
+ Nothing
276
+ (Type0 ((NE. :| [] ) (Type1 (T2Value (VUInt 1 )) Nothing )))
277
+ ]
278
+ NE. :| []
279
+ )
280
+ )
239
281
240
282
grpEntrySpec :: SpecWith ()
241
283
grpEntrySpec = describe " GroupEntry" $ do
You can’t perform that action at this time.
0 commit comments