on master help sign in
Check line-oriented I/O.

--HG-- extra : convert_revision : 47a50606a4d6814db3fce85d2312a73842968069

commit29d955e5586bc0ff664897233f9326ba375804ac authorBryan O'Sullivan <bos@serpentine.com> dateFri 27 Aug 2010, 06:32 (16 years ago) parent7ca8b32
1 file changed+24−5
tests/Properties.hs+24−5
tests/Properties.hs+24−5
@@ -608,8 +608,21 @@ instance Arbitrary NewlineMode where
608608 [ noNewlineTranslation, universalNewlineMode, nativeNewlineMode,
609609 windowsNewlineMode ]
610610
611−write_read writer reader (E _ e) m t = monadicIO $ assert . (==t) =<< run act
612− where act = withTempFile $ \path h -> do
611+-- This test harness is complex! What property are we checking?
612+--
613+-- Reading after writing a multi-line file should give the same
614+-- results as were written.
615+--
616+-- What do we vary while checking this property?
617+-- * The lines themselves, scrubbed to contain neither CR nor LF. (By
618+-- working with a list of lines, we ensure that the data will
619+-- sometimes contain line endings.)
620+-- * Encoding.
621+-- * Newline translation mode.
622+write_read unline filt writer reader (E _ e) m ts =
623+ monadicIO $ assert . (==t) =<< run act
624+ where t = unline . map (filt (not . (`elem` "\r\n"))) $ ts
625+ act = withTempFile $ \path h -> do
613626 hSetEncoding h e
614627 hSetNewlineMode h m
615628 () <- writer h t
@@ -620,9 +633,13 @@ write_read writer reader (E _ e) m t = monadicIO $ assert . (==t) =<< run act
620633 r <- reader h'
621634 r `deepseq` return r
622635
623−t_write_read = write_read T.hPutStr T.hGetContents
636+t_write_read = write_read T.unlines T.filter T.hPutStr T.hGetContents
637+tl_write_read = write_read TL.unlines TL.filter TL.hPutStr TL.hGetContents
624638
625−tl_write_read = write_read TL.hPutStr TL.hGetContents
639+t_write_read_line e m t = write_read head T.filter T.hPutStrLn
640+ T.hGetLine e m [t]
641+tl_write_read_line e m t = write_read head TL.filter TL.hPutStrLn
642+ TL.hGetLine e m [t]
626643
627644-- Low-level.
628645
@@ -1017,7 +1034,9 @@ tests = [
10171034
10181035 testGroup "input-output" [
10191036 testProperty "t_write_read" t_write_read,
1020− testProperty "tl_write_read" tl_write_read
1037+ testProperty "tl_write_read" tl_write_read,
1038+ testProperty "t_write_read_line" t_write_read_line,
1039+ testProperty "tl_write_read_line" tl_write_read_line
10211040 ],
10221041
10231042 testGroup "lowlevel" [