diff options
author | Tamar Christina <tamar@zhox.com> | 2020-10-06 09:52:14 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-10-09 08:50:51 -0400 |
commit | 0fd3d360cab977e00fb6d90d0519962227b029bb (patch) | |
tree | af63cff10553beb1db7a4cedc1b38787791c3008 /libraries/base/tests | |
parent | 6f0243ae5b359124936a8ff3dd0a287df3d7aca2 (diff) | |
download | haskell-0fd3d360cab977e00fb6d90d0519962227b029bb.tar.gz |
winio: fixed bytestring reading interface.
Diffstat (limited to 'libraries/base/tests')
-rw-r--r-- | libraries/base/tests/IO/all.T | 1 | ||||
-rw-r--r-- | libraries/base/tests/IO/bytestringread001.hs | 33 | ||||
-rw-r--r-- | libraries/base/tests/IO/bytestringread001.stdout | 1 |
3 files changed, 35 insertions, 0 deletions
diff --git a/libraries/base/tests/IO/all.T b/libraries/base/tests/IO/all.T index c828975584..9475183b3c 100644 --- a/libraries/base/tests/IO/all.T +++ b/libraries/base/tests/IO/all.T @@ -149,3 +149,4 @@ test('T17414', high_memory_usage], compile_and_run, ['']) test('T17510', expect_broken(17510), compile_and_run, ['']) +test('bytestringread001', extra_run_opts('test.data'), compile_and_run, ['']) diff --git a/libraries/base/tests/IO/bytestringread001.hs b/libraries/base/tests/IO/bytestringread001.hs new file mode 100644 index 0000000000..e020efe711 --- /dev/null +++ b/libraries/base/tests/IO/bytestringread001.hs @@ -0,0 +1,33 @@ +import System.Environment
+import qualified Data.ByteString.Lazy as BL
+import Data.Word
+
+fold_tailrec :: (a -> b -> a) -> a -> [b] -> a
+fold_tailrec _ acc [] =
+ acc
+fold_tailrec foldFun acc (x : xs) =
+ fold_tailrec foldFun (foldFun acc x) xs
+
+fold_tailrec' :: (a -> b -> a) -> a -> [b] -> a
+fold_tailrec' _ acc [] =
+ acc
+fold_tailrec' foldFun acc (x : xs) =
+ let acc' = foldFun acc x
+ in seq acc' (fold_tailrec' foldFun acc' xs)
+
+main :: IO ()
+main =
+ do
+ args <- getArgs
+ let filename = head args
+
+ -- generate file
+ let dt = replicate (65 * 1024) 'a'
+ writeFile filename dt
+
+ byteString <- BL.readFile filename
+ let wordsList = BL.unpack byteString
+ -- wordsList is supposed to be lazy (bufferized)
+ let bytesCount = fold_tailrec (\acc word -> acc + 1) 0 wordsList
+ print ("Total bytes in " ++ filename ++ ": "
+ ++ (show bytesCount))
diff --git a/libraries/base/tests/IO/bytestringread001.stdout b/libraries/base/tests/IO/bytestringread001.stdout new file mode 100644 index 0000000000..03f5607472 --- /dev/null +++ b/libraries/base/tests/IO/bytestringread001.stdout @@ -0,0 +1 @@ +"Total bytes in test.data: 66560" |