diff --git a/src/Data/Text/Lazy.hs b/src/Data/Text/Lazy.hs index 0bb73972..152fef7d 100644 --- a/src/Data/Text/Lazy.hs +++ b/src/Data/Text/Lazy.hs @@ -328,6 +328,13 @@ instance Read Text where -- | @since 1.2.2.0 instance Semigroup Text where (<>) = append + stimes n _ | n < 0 = P.error "Data.Text.Lazy.stimes: given number is negative!" + stimes n a = + let nInt64 = fromIntegral n :: Int64 + len = if n == fromIntegral nInt64 && nInt64 >= 0 then nInt64 else P.maxBound + -- We clamp the length to maxBound :: Int64. + -- To tell the difference, the caller would have to skip through 2^63 chunks. + in replicate len a instance Monoid Text where mempty = empty diff --git a/tests/Tests/Properties/Instances.hs b/tests/Tests/Properties/Instances.hs index f4971408..fde961c9 100644 --- a/tests/Tests/Properties/Instances.hs +++ b/tests/Tests/Properties/Instances.hs @@ -41,6 +41,9 @@ tl_mappend s = mappend s`eqP` (unpackS . mappend (TL.pack s)) t_stimes = \ number -> eq ((stimes :: Int -> String -> String) number . unSqrt) (unpackS . (stimes :: Int -> T.Text -> T.Text) number . T.pack . unSqrt) +tl_stimes = \ number -> eq + ((stimes :: Int -> String -> String) number . unSqrt) + (unpackS . (stimes :: Int -> TL.Text -> TL.Text) number . TL.pack . unSqrt) t_mconcat = (mconcat . unSqrt) `eq` (unpackS . mconcat . L.map T.pack . unSqrt) tl_mconcat = (mconcat . unSqrt) `eq` (unpackS . mconcat . L.map TL.pack . unSqrt) t_mempty = mempty === (unpackS (mempty :: T.Text)) @@ -76,6 +79,7 @@ testInstances = testProperty "t_mappend" t_mappend, testProperty "tl_mappend" tl_mappend, testProperty "t_stimes" t_stimes, + testProperty "tl_stimes" tl_stimes, testProperty "t_mconcat" t_mconcat, testProperty "tl_mconcat" tl_mconcat, testProperty "t_mempty" t_mempty,