mirror of
https://github.com/github/semantic.git
synced 2024-11-24 17:04:47 +03:00
Spike out an Arbitrary instance for BranchElement.
This commit is contained in:
parent
419bcfe776
commit
919f32a650
@ -211,6 +211,18 @@ instance Arbitrary Child where
|
||||
shrink Child {..} | null childContents, null childMargin = []
|
||||
| otherwise = Child childKey <$> "" : shrinkList (const []) childContents <*> "" : shrinkList (const []) childMargin
|
||||
|
||||
instance Arbitrary BranchElement where
|
||||
arbitrary = oneof [ Child' <$> key <*> joinTheseOf contents
|
||||
, Margin <$> joinTheseOf margin ]
|
||||
where key = listOf1 (elements (['a'..'z'] ++ ['A'..'Z'] ++ ['0'..'9']))
|
||||
contents = listOf (padding '*')
|
||||
margin = listOf (padding '-')
|
||||
padding char = frequency [ (10, pure char)
|
||||
, (1, pure '\n') ]
|
||||
joinTheseOf g = oneof [ Join . This <$> g
|
||||
, Join . That <$> g
|
||||
, (Join .) . These <$> g <*> g ]
|
||||
|
||||
instance Show Child where
|
||||
show Child {..} = childMargin ++ "(" ++ childKey ++ childContents ++ ")"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user