Skip to content

Commit 7cd1deb

Browse files
LysxiaBodigrim
authored andcommitted
Define stimes 0 for lazy text
1 parent 5578f3b commit 7cd1deb

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/Data/Text/Lazy.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,13 @@ instance Read Text where
328328
-- | @since 1.2.2.0
329329
instance Semigroup Text where
330330
(<>) = append
331+
stimes n _ | n < 0 = P.error "Data.Text.Lazy.stimes: given number is negative!"
332+
stimes n a =
333+
let nInt64 = fromIntegral n :: Int64
334+
len = if n == fromIntegral nInt64 && nInt64 >= 0 then nInt64 else P.maxBound
335+
-- We clamp the length to maxBound :: Int64.
336+
-- To tell the difference, the caller would have to skip through 2^63 chunks.
337+
in replicate len a
331338

332339
instance Monoid Text where
333340
mempty = empty

tests/Tests/Properties/Instances.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ tl_mappend s = mappend s`eqP` (unpackS . mappend (TL.pack s))
4141
t_stimes = \ number -> eq
4242
((stimes :: Int -> String -> String) number . unSqrt)
4343
(unpackS . (stimes :: Int -> T.Text -> T.Text) number . T.pack . unSqrt)
44+
tl_stimes = \ number -> eq
45+
((stimes :: Int -> String -> String) number . unSqrt)
46+
(unpackS . (stimes :: Int -> TL.Text -> TL.Text) number . TL.pack . unSqrt)
4447
t_mconcat = (mconcat . unSqrt) `eq` (unpackS . mconcat . L.map T.pack . unSqrt)
4548
tl_mconcat = (mconcat . unSqrt) `eq` (unpackS . mconcat . L.map TL.pack . unSqrt)
4649
t_mempty = mempty === (unpackS (mempty :: T.Text))
@@ -76,6 +79,7 @@ testInstances =
7679
testProperty "t_mappend" t_mappend,
7780
testProperty "tl_mappend" tl_mappend,
7881
testProperty "t_stimes" t_stimes,
82+
testProperty "tl_stimes" tl_stimes,
7983
testProperty "t_mconcat" t_mconcat,
8084
testProperty "tl_mconcat" tl_mconcat,
8185
testProperty "t_mempty" t_mempty,

0 commit comments

Comments
 (0)