@@ -12,6 +12,7 @@ import Data.Monoid (Monoid(..))
12import Data.String (fromString)
12import Data.String (fromString)
13import Debug.Trace (trace)
13import Debug.Trace (trace)
14import Control.Arrow ((***), second)
14import Control.Arrow ((***), second)
15+import Control.DeepSeq
15import Data.Word (Word8, Word16, Word32)
16import Data.Word (Word8, Word16, Word32)
16import qualified Data.Text as T
17import qualified Data.Text as T
17import qualified Data.Text.IO as T
18import qualified Data.Text.IO as T
@@ -582,14 +583,42 @@ t_builderAssociative s1 s2 s3 = TB.toLazyText (b1 `mappend` (b2 `mappend` b3)) =
583-- Input and output.
584-- Input and output.
586+-- Work around lack of Show instance for TextEncoding.
587+data Encoding = E String TextEncoding
589+instance Show Encoding where show (E n _) = "utf" ++ n
591+instance Arbitrary Encoding where
592+ arbitrary = oneof . map return $
593+ [ E "8" utf8, E "8_bom" utf8_bom, E "16" utf16, E "16le" utf16le,
594+ E "16be" utf16be, E "32" utf32, E "32le" utf32le, E "32be" utf32be ]
596+windowsNewlineMode = NewlineMode { inputNL = CRLF, outputNL = CRLF }
598+instance Show Newline where
602+instance Show NewlineMode where
603+ show (NewlineMode i o) = "NewlineMode { inputNL = " ++ show i ++
604+ ", outputNL = " ++ show o ++ " }"
606+instance Arbitrary NewlineMode where
607+ arbitrary = oneof . map return $
608+ [ noNewlineTranslation, universalNewlineMode, nativeNewlineMode,
609+ windowsNewlineMode ]
585−write_read writer reader locale t = monadicIO $ assert . (==t) =<< run act
611+write_read writer reader (E _ e) m t = monadicIO $ assert . (==t) =<< run act
586 where act = withTempFile $ \path h -> do
612 where act = withTempFile $ \path h -> do
587− hSetEncoding h locale
613+ hSetEncoding h e
588 () <- writer h t
615 () <- writer h t
590 bracket (openFile path ReadMode) hClose $ \h' -> do
617 bracket (openFile path ReadMode) hClose $ \h' -> do
591− hSetEncoding h' locale
618+ hSetEncoding h' e
619+ hSetNewlineMode h' m
592− reader h'
620+ r <- reader h'
621+ r `deepseq` return r
594t_write_read = write_read T.hPutStr T.hGetContents
623t_write_read = write_read T.hPutStr T.hGetContents
@@ -987,22 +1016,8 @@ tests = [
989 testGroup "input-output" [
1018 testGroup "input-output" [
990− testProperty "t_write_read_8" $ t_write_read utf8,
1019+ testProperty "t_write_read" t_write_read,
991− testProperty "t_write_read_8bom" $ t_write_read utf8_bom,
1020+ testProperty "tl_write_read" tl_write_read
992− testProperty "t_write_read_16" $ t_write_read utf16,
993− testProperty "t_write_read_16le" $ t_write_read utf16le,
994− testProperty "t_write_read_16be" $ t_write_read utf16be,
995− testProperty "t_write_read_32" $ t_write_read utf32,
996− testProperty "t_write_read_32le" $ t_write_read utf32le,
997− testProperty "t_write_read_32be" $ t_write_read utf32be,
998− testProperty "tl_write_read_8" $ tl_write_read utf8,
999− testProperty "tl_write_read_8bom" $ tl_write_read utf8_bom,
1000− testProperty "tl_write_read_16" $ tl_write_read utf16,
1001− testProperty "tl_write_read_16le" $ tl_write_read utf16le,
1002− testProperty "tl_write_read_16be" $ tl_write_read utf16be,
1003− testProperty "tl_write_read_32" $ tl_write_read utf32,
1004− testProperty "tl_write_read_32le" $ tl_write_read utf32le,
1005− testProperty "tl_write_read_32be" $ tl_write_read utf32be
1008 testGroup "lowlevel" [
1023 testGroup "lowlevel" [