Skip to content

Commit

Permalink
Merge pull request #86 from SeanRBurton/improve_tests
Browse files Browse the repository at this point in the history
Improve QC instances
  • Loading branch information
bos committed Dec 11, 2014
2 parents bc39852 + a773af4 commit a6913c1
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tests/QC/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,30 @@ repackBS_ = go . cycle
| otherwise = let (h,t) = B.splitAt b s
in h : go bs t
go _ _ = error "unpossible"


newtype Unicode = Unicode {fromUnicode :: Char}

valid :: Unicode -> Bool
valid (Unicode c) = c < '\55296' || '\57343' < c

instance Arbitrary Unicode where
arbitrary = fmap Unicode (oneof [arbitrary, arbitraryBoundedEnum]) `suchThat` valid
shrink = filter valid . map (Unicode . toEnum) . shrink . fromEnum . fromUnicode

packUnicode :: [Unicode] -> T.Text
packUnicode = T.pack . map fromUnicode

unpackUnicode :: T.Text -> [Unicode]
unpackUnicode = map Unicode . T.unpack

instance Arbitrary T.Text where
arbitrary = T.pack <$> arbitrary
arbitrary = packUnicode <$> arbitrary
shrink = map packUnicode . shrink . unpackUnicode

instance Arbitrary TL.Text where
arbitrary = repackT <$> arbitrary <*> arbitrary
shrink = map TL.fromChunks . shrink . TL.toChunks

repackT :: Repack -> T.Text -> TL.Text
repackT (NonEmpty bs) =
Expand Down

0 comments on commit a6913c1

Please sign in to comment.