-
Notifications
You must be signed in to change notification settings - Fork 143
Making ByteString.hGetLine behave like System.IO.hGetLine #327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
5b169ec
a70a788
537080c
a3d4c5f
6f6a098
3e34f48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1614,6 +1614,36 @@ prop_read_write_file_D x = unsafePerformIO $ do | |
| (const $ do y <- D.readFile f | ||
| return (x==y)) | ||
|
|
||
| prop_hgetline_like_s8_hgetline (LinedASCII filetext) (lineEndIn, lineEndOut) = idempotentIOProperty $ do | ||
| tid <- myThreadId | ||
| let f = "qc-test-"++show tid | ||
| let newlineMode = NewlineMode (if lineEndIn then LF else CRLF) (if lineEndOut then LF else CRLF) | ||
|
||
| bracket_ | ||
|
||
| (writeFile f filetext) | ||
dbramucci marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| (removeFile f) | ||
| $ do | ||
| bsLines <- withFile f ReadMode (\h -> do | ||
| hSetNewlineMode h newlineMode | ||
| readByLines C.hGetLine h | ||
| ) | ||
| sLines <- withFile f ReadMode (\h -> do | ||
| hSetNewlineMode h newlineMode | ||
| readByLines System.IO.hGetLine h | ||
| ) | ||
|
||
| return $ map C.unpack bsLines === sLines | ||
|
|
||
| where | ||
| readByLines getLine h_ = go [] | ||
|
||
| where | ||
| go lines = do | ||
| isEnd <- hIsEOF h_ | ||
| if isEnd | ||
| then return lines | ||
| else do | ||
| !nextLine <- getLine h_ | ||
| go (nextLine : lines) | ||
|
|
||
|
|
||
| ------------------------------------------------------------------------ | ||
|
|
||
| prop_append_file_P x y = unsafePerformIO $ do | ||
|
|
@@ -1791,7 +1821,8 @@ io_tests = | |
| , testProperty "appendFile " prop_append_file_D | ||
|
|
||
| , testProperty "packAddress " prop_packAddress | ||
|
|
||
|
|
||
| , testProperty "pack.hGetLine=hGetLine" prop_hgetline_like_s8_hgetline | ||
| ] | ||
|
|
||
| misc_tests = | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
openTempFile, e. g.,bytestring/tests/LazyHClose.hs
Line 18 in 54133b3