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 "//")
124124pGrpChoice :: Parser GrpChoice
125125pGrpChoice =
126126 many
127- ( (space *> (noComment <$> pGrpEntry) <* space)
128- <* optional (char ' ,' )
129- )
127+ (try $ (space *> (noComment <$> pGrpEntry) <* space) <* optional (char ' ,' ))
130128
131129pGrpEntry :: Parser GroupEntry
132130pGrpEntry =
Original file line number Diff line number Diff line change @@ -182,6 +182,35 @@ type2Spec = describe "type2" $ do
182182 ]
183183 )
184184 )
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+ )
185214 describe " Array" $ do
186215 it " Parses an array with an alternative" $
187216 parse pType2 " " " [int // string]"
@@ -236,6 +265,19 @@ type2Spec = describe "type2" $ do
236265 ]
237266 )
238267 )
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+ )
239281
240282grpEntrySpec :: SpecWith ()
241283grpEntrySpec = describe " GroupEntry" $ do
You can’t perform that action at this time.
0 commit comments