@@ -1,38 +1,37 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE CPP #-}
2{-# LANGUAGE PackageImports #-}
2{-# LANGUAGE PackageImports #-}
3{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE ScopedTypeVariables #-}
4−import Test.Framework (defaultMain)
6import Text.Libyaml
5import Text.Libyaml
7import qualified Data.ByteString.Char8 as B8
6import qualified Data.ByteString.Char8 as B8
9−import Test.Framework.Providers.HUnit
10import Test.HUnit hiding (Test, path)
8import Test.HUnit hiding (Test, path)
12import qualified Data.Conduit as C
10import qualified Data.Conduit as C
13import qualified Data.Conduit.List as CL
11import qualified Data.Conduit.List as CL
14−import Data.List (foldl')
16import System.Directory
13import System.Directory
17import Control.Monad
14import Control.Monad
18import Control.Exception (try, SomeException)
15import Control.Exception (try, SomeException)
16+import Test.Hspec.Monadic
17+import Test.Hspec.HUnit ()
20main :: IO ()
19main :: IO ()
21−main = defaultMain
20+main = hspecX $ do
21+ describe "streaming" $ do
22− [ testCase "count scalars with anchor" caseCountScalarsWithAnchor
22+ it "count scalars with anchor" caseCountScalarsWithAnchor
23− , testCase "count sequences with anchor" caseCountSequencesWithAnchor
23+ it "count sequences with anchor" caseCountSequencesWithAnchor
24− , testCase "count mappings with anchor" caseCountMappingsWithAnchor
24+ it "count mappings with anchor" caseCountMappingsWithAnchor
25− , testCase "count aliases" caseCountAliases
25+ it "count aliases" caseCountAliases
26− , testCase "count scalars" caseCountScalars
26+ it "count scalars" caseCountScalars
27− , testCase "largest string" caseLargestString
27+ it "largest string" caseLargestString
28− , testCase "encode/decode" caseEncodeDecode
28+ it "encode/decode" caseEncodeDecode
29− , testCase "encode/decode file" caseEncodeDecodeFile
29+ it "encode/decode file" caseEncodeDecodeFile
30− , testCase "interleaved encode/decode" caseInterleave
30+ it "interleaved encode/decode" caseInterleave
31− , testCase "decode invalid document (without segfault)" caseDecodeInvalidDocument
31+ it "decode invalid document (without segfault)" caseDecodeInvalidDocument
34−counter :: (Event -> Bool) -> Int -> C.Sink Event IO Int
33+counter :: (Event -> Bool) -> C.Sink Event IO Int
35−counter pred' acc =
34+counter pred' =
36 CL.fold (\cnt e -> (if pred' e then 1 else 0) + cnt) 0
35 CL.fold (\cnt e -> (if pred' e then 1 else 0) + cnt) 0
38caseHelper :: String
37caseHelper :: String
@@ -40,7 +39,7 @@ caseHelper :: String
41 -> Assertion
40 -> Assertion
42caseHelper yamlString pred' expRes = do
41caseHelper yamlString pred' expRes = do
43− res <- C.runResourceT $ decode (B8.pack yamlString) C.$$ counter pred' 0
42+ res <- C.runResourceT $ decode (B8.pack yamlString) C.$$ counter pred'
44 res @?= expRes
43 res @?= expRes
46caseCountScalarsWithAnchor :: Assertion
45caseCountScalarsWithAnchor :: Assertion
@@ -152,7 +151,7 @@ caseDecodeInvalidDocument :: Assertion
152caseDecodeInvalidDocument = do
151caseDecodeInvalidDocument = do
153 x <- try $ C.runResourceT $ decode yamlBS C.$$ CL.sinkNull
152 x <- try $ C.runResourceT $ decode yamlBS C.$$ CL.sinkNull
154 case x of
153 case x of
155− Left (e :: SomeException) -> return ()
154+ Left (_ :: SomeException) -> return ()
156 Right y -> do
155 Right y -> do
157 putStrLn $ "bad return value: " ++ show y
156 putStrLn $ "bad return value: " ++ show y
158 assertFailure "expected parsing exception, but got no errors"
157 assertFailure "expected parsing exception, but got no errors"