-
Notifications
You must be signed in to change notification settings - Fork 137
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
TH Lift #392
TH Lift #392
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 |
---|---|---|
|
@@ -70,7 +70,7 @@ source-repository head | |
location: https://github.com/haskell/bytestring | ||
|
||
library | ||
build-depends: base >= 4.9 && < 5, ghc-prim, deepseq | ||
build-depends: base >= 4.9 && < 5, ghc-prim, deepseq, template-haskell | ||
|
||
exposed-modules: Data.ByteString | ||
Data.ByteString.Char8 | ||
|
@@ -165,6 +165,15 @@ test-suite test-builder | |
ghc-options: -Wall -fwarn-tabs -threaded -rtsopts | ||
default-language: Haskell2010 | ||
|
||
test-suite bytestring-th | ||
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. Please put this into one of existing test suites. Linking an additional executable is expensive on Windows. 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. In which of three it belongs? lazy-hclose and test-builder seems to be testing specific features, and prop-compiled is for properties. It looks like fourth test-suite for an isolated feature is following the example. |
||
type: exitcode-stdio-1.0 | ||
hs-source-dirs: tests | ||
main-is: bytestring-th.hs | ||
other-extensions: TemplateHaskell | ||
build-depends: base, bytestring, template-haskell, tasty, tasty-hunit | ||
ghc-options: -Wall -fwarn-tabs -threaded -rtsopts | ||
default-language: Haskell2010 | ||
|
||
benchmark bytestring-bench | ||
main-is: BenchAll.hs | ||
other-modules: BenchBoundsCheckFusion | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
{-# LANGUAGE CPP #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module Main (main) where | ||
|
||
import Test.Tasty (defaultMain, testGroup) | ||
import Test.Tasty.HUnit (testCase, (@=?)) | ||
import qualified Data.ByteString as BS | ||
import qualified Data.ByteString.Lazy as LBS | ||
import qualified Data.ByteString.Short as SBS | ||
import qualified Language.Haskell.TH.Syntax as TH | ||
|
||
main :: IO () | ||
main = defaultMain $ testGroup "bytestring-th" | ||
[ testGroup "strict" | ||
[ testCase "normal" $ do | ||
let bs :: BS.ByteString | ||
bs = "foobar" | ||
|
||
bs @=? $(TH.lift $ BS.pack [102,111,111,98,97,114]) | ||
|
||
, testCase "binary" $ do | ||
let bs :: BS.ByteString | ||
bs = "\0\1\2\3\0\1\2\3" | ||
|
||
bs @=? $(TH.lift $ BS.pack [0,1,2,3,0,1,2,3]) | ||
|
||
#if MIN_VERSION_template_haskell(2,16,0) | ||
, testCase "typed" $ do | ||
let bs :: BS.ByteString | ||
bs = "\0\1\2\3\0\1\2\3" | ||
|
||
bs @=? $$(TH.liftTyped $ BS.pack [0,1,2,3,0,1,2,3]) | ||
#endif | ||
] | ||
|
||
, testGroup "lazy" | ||
[ testCase "normal" $ do | ||
let bs :: LBS.ByteString | ||
bs = "foobar" | ||
|
||
bs @=? $(TH.lift $ LBS.pack [102,111,111,98,97,114]) | ||
|
||
, testCase "binary" $ do | ||
let bs :: LBS.ByteString | ||
bs = "\0\1\2\3\0\1\2\3" | ||
|
||
-- print $ LBS.unpack bs | ||
-- print $ LBS.unpack $(TH.lift $ LBS.pack [0,1,2,3,0,1,2,3]) | ||
phadej marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
bs @=? $(TH.lift $ LBS.pack [0,1,2,3,0,1,2,3]) | ||
|
||
#if MIN_VERSION_template_haskell(2,16,0) | ||
, testCase "typed" $ do | ||
let bs :: LBS.ByteString | ||
bs = "\0\1\2\3\0\1\2\3" | ||
|
||
bs @=? $$(TH.liftTyped $ LBS.pack [0,1,2,3,0,1,2,3]) | ||
#endif | ||
] | ||
|
||
, testGroup "short" | ||
[ testCase "normal" $ do | ||
let bs :: SBS.ShortByteString | ||
bs = "foobar" | ||
|
||
bs @=? $(TH.lift $ SBS.pack [102,111,111,98,97,114]) | ||
|
||
, testCase "binary" $ do | ||
let bs :: SBS.ShortByteString | ||
bs = "\0\1\2\3\0\1\2\3" | ||
|
||
bs @=? $(TH.lift $ SBS.pack [0,1,2,3,0,1,2,3]) | ||
|
||
#if MIN_VERSION_template_haskell(2,16,0) | ||
, testCase "typed" $ do | ||
let bs :: SBS.ShortByteString | ||
bs = "\0\1\2\3\0\1\2\3" | ||
|
||
bs @=? $$(TH.liftTyped $ SBS.pack [0,1,2,3,0,1,2,3]) | ||
#endif | ||
] | ||
] |
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.
Could we possibly have less duplication? It seems that only the last line is conditional on
template-haskell
version. Same forSBS
.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.
it's not the same,
vs
Disable unused variable warning and I will simpify.