@@ -3,6 +3,7 @@
33{-# OPTIONS_GHC -fno-enable-rewrite-rules #-}
44
55import Test.QuickCheck
6+import Test.QuickCheck.Monadic
67import Text.Show.Functions ()
78
89import qualified Data.Bits as Bits (shiftL, shiftR)
@@ -13,6 +14,7 @@ import Debug.Trace (trace)
1314import Control.Arrow ((***), second)
1415import Data.Word (Word8, Word16, Word32)
1516import qualified Data.Text as T
17+import qualified Data.Text.IO as T
1618import qualified Data.Text.Lazy as TL
1719import qualified Data.Text.Lazy.Builder as TB
1820import qualified Data.Text.Encoding as E
@@ -26,6 +28,7 @@ import qualified Data.Text.Lazy.Fusion as SL
2628import qualified Data.Text.UnsafeShift as U
2729import qualified Data.List as L
2830import Prelude hiding (replicate)
31+import System.IO
2932import System.IO.Unsafe (unsafePerformIO)
3033import Test.Framework (defaultMain, testGroup)
3134import Test.Framework.Providers.QuickCheck2 (testProperty)
@@ -34,6 +37,7 @@ import qualified Data.Text.Lazy.Search as S (indices)
3437import qualified SlowFunctions as Slow
3538
3639import QuickCheckUtils (NotEmpty(..), small, genUnicode)
40+import TestUtils (withTempFile)
3741
3842-- Ensure that two potentially bottom values (in the sense of crashing
3943-- for some inputs, not looping infinitely) either both crash, or both
@@ -565,7 +569,8 @@ shiftR_Int = shiftR :: Int -> Property
565569shiftR_Word16 = shiftR :: Word16 -> Property
566570shiftR_Word32 = shiftR :: Word32 -> Property
567571
568−-- Builder
572+-- Builder.
573+
569574t_builderSingleton = id `eqP` (unpackS . TB.toLazyText . mconcat . map TB.singleton)
570575t_builderFromText = L.concat `eq` (unpackS . TB.toLazyText . mconcat . map (TB.fromText . packS))
571576t_builderAssociative s1 s2 s3 = TB.toLazyText (b1 `mappend` (b2 `mappend` b3)) ==
@@ -574,6 +579,16 @@ t_builderAssociative s1 s2 s3 = TB.toLazyText (b1 `mappend` (b2 `mappend` b3)) =
574579 b2 = TB.fromText (packS s2)
575580 b3 = TB.fromText (packS s3)
576581
582+-- Input and output.
583+
584+t_write_read (NotEmpty t) = monadicIO $ do
585+ r <- run act
586+ assert (r == t)
587+ where act = withTempFile $ \path h -> do
588+ T.hPutStr h t
589+ hClose h
590+ T.readFile path
591+
577592-- Low-level.
578593
579594t_dropWord16 m t = dropWord16 m t `T.isSuffixOf` t
@@ -965,6 +980,10 @@ tests = [
965980 testProperty "t_builderAssociative" t_builderAssociative
966981 ],
967982
983+ testGroup "io" [
984+ testProperty "t_write_read" t_write_read
985+ ],
986+
968987 testGroup "lowlevel" [
969988 testProperty "t_dropWord16" t_dropWord16,
970989 testProperty "t_takeWord16" t_takeWord16,