-
Notifications
You must be signed in to change notification settings - Fork 144
Avoid per-byte loop in cstring{,Utf8} builders #569
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 all commits
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 | ||||
---|---|---|---|---|---|---|
|
@@ -14,6 +14,7 @@ import Data.Char (ord) | |||||
import qualified Data.ByteString.Lazy as L | ||||||
import qualified Data.ByteString.Lazy.Char8 as LC | ||||||
import Data.ByteString.Builder | ||||||
import Data.ByteString.Builder.Extra as BE | ||||||
import qualified Data.ByteString.Builder.Prim as BP | ||||||
import Data.ByteString.Builder.Prim.TestUtils | ||||||
|
||||||
|
@@ -22,17 +23,28 @@ import Test.Tasty.QuickCheck | |||||
|
||||||
tests :: [TestTree] | ||||||
tests = concat [ testsBinary, testsASCII, testsChar8, testsUtf8 | ||||||
, testsCombinatorsB, [testCString, testCStringUtf8] ] | ||||||
, testsCombinatorsB | ||||||
, [ testCString | ||||||
, testCStringUtf8 1 | ||||||
, testCStringUtf8 6 | ||||||
, testCStringUtf8 64 | ||||||
] | ||||||
] | ||||||
|
||||||
testCString :: TestTree | ||||||
testCString = testProperty "cstring" $ | ||||||
toLazyByteString (BP.cstring "hello world!"#) == | ||||||
LC.pack "hello" `L.append` L.singleton 0x20 `L.append` LC.pack "world!" | ||||||
|
||||||
testCStringUtf8 :: TestTree | ||||||
testCStringUtf8 = testProperty "cstringUtf8" $ | ||||||
toLazyByteString (BP.cstringUtf8 "hello\xc0\x80world!"#) == | ||||||
LC.pack "hello" `L.append` L.singleton 0x00 `L.append` LC.pack "world!" | ||||||
testCStringUtf8 :: Int -> TestTree | ||||||
testCStringUtf8 sz = testProperty ("cstringUtf8 (chunk size " ++ shows sz ")") $ | ||||||
BE.toLazyByteStringWith (BE.untrimmedStrategy sz sz) L.empty | ||||||
(BP.cstringUtf8 "hello\xc0\x80\xc0\x80\xd0\xbc\xd0\xb8\xd1\x80\xc0\x80\xC0"#) == | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do think it is best to test that the code does not blow up with input that unexpectedly ends with just |
||||||
LC.pack "hello" `L.append` L.singleton 0x00 | ||||||
`L.append` L.singleton 0x00 | ||||||
`L.append` LC.pack "\xd0\xbc\xd0\xb8\xd1\x80" | ||||||
`L.append` L.singleton 0x00 | ||||||
`L.append` L.singleton 0x00 | ||||||
|
||||||
------------------------------------------------------------------------------ | ||||||
-- Binary | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.