@@ -54,12 +54,30 @@ repackBS_ = go . cycle
5454 | otherwise = let (h,t) = B.splitAt b s
5555 in h : go bs t
5656 go _ _ = error "unpossible"
57+
58+
59+newtype Unicode = Unicode {fromUnicode :: Char}
60+
61+valid :: Unicode -> Bool
62+valid (Unicode c) = c < '\55296' || '\57343' < c
63+
64+instance Arbitrary Unicode where
65+ arbitrary = fmap Unicode (oneof [arbitrary, arbitraryBoundedEnum]) `suchThat` valid
66+ shrink = filter valid . map (Unicode . toEnum) . shrink . fromEnum . fromUnicode
67+
68+packUnicode :: [Unicode] -> T.Text
69+packUnicode = T.pack . map fromUnicode
70+
71+unpackUnicode :: T.Text -> [Unicode]
72+unpackUnicode = map Unicode . T.unpack
5773
5874instance Arbitrary T.Text where
59− arbitrary = T.pack <$> arbitrary
75+ arbitrary = packUnicode <$> arbitrary
76+ shrink = map packUnicode . shrink . unpackUnicode
6077
6178instance Arbitrary TL.Text where
6279 arbitrary = repackT <$> arbitrary <*> arbitrary
80+ shrink = map TL.fromChunks . shrink . TL.toChunks
6381
6482repackT :: Repack -> T.Text -> TL.Text
6583repackT (NonEmpty bs) =