@@ -1,38 +1,37 @@
11{-# LANGUAGE CPP #-}
22{-# LANGUAGE PackageImports #-}
33{-# LANGUAGE ScopedTypeVariables #-}
4−import Test.Framework (defaultMain)
54
65import Text.Libyaml
76import qualified Data.ByteString.Char8 as B8
87
9−import Test.Framework.Providers.HUnit
108import Test.HUnit hiding (Test, path)
119
1210import qualified Data.Conduit as C
1311import qualified Data.Conduit.List as CL
14−import Data.List (foldl')
1512
1613import System.Directory
1714import Control.Monad
1815import Control.Exception (try, SomeException)
16+import Test.Hspec.Monadic
17+import Test.Hspec.HUnit ()
1918
2019main :: IO ()
21−main = defaultMain
22− [ testCase "count scalars with anchor" caseCountScalarsWithAnchor
23− , testCase "count sequences with anchor" caseCountSequencesWithAnchor
24− , testCase "count mappings with anchor" caseCountMappingsWithAnchor
25− , testCase "count aliases" caseCountAliases
26− , testCase "count scalars" caseCountScalars
27− , testCase "largest string" caseLargestString
28− , testCase "encode/decode" caseEncodeDecode
29− , testCase "encode/decode file" caseEncodeDecodeFile
30− , testCase "interleaved encode/decode" caseInterleave
31− , testCase "decode invalid document (without segfault)" caseDecodeInvalidDocument
32− ]
33−
34−counter :: (Event -> Bool) -> Int -> C.Sink Event IO Int
35−counter pred' acc =
20+main = hspecX $ do
21+ describe "streaming" $ do
22+ it "count scalars with anchor" caseCountScalarsWithAnchor
23+ it "count sequences with anchor" caseCountSequencesWithAnchor
24+ it "count mappings with anchor" caseCountMappingsWithAnchor
25+ it "count aliases" caseCountAliases
26+ it "count scalars" caseCountScalars
27+ it "largest string" caseLargestString
28+ it "encode/decode" caseEncodeDecode
29+ it "encode/decode file" caseEncodeDecodeFile
30+ it "interleaved encode/decode" caseInterleave
31+ it "decode invalid document (without segfault)" caseDecodeInvalidDocument
32+
33+counter :: (Event -> Bool) -> C.Sink Event IO Int
34+counter pred' =
3635 CL.fold (\cnt e -> (if pred' e then 1 else 0) + cnt) 0
3736
3837caseHelper :: String
@@ -40,7 +39,7 @@ caseHelper :: String
4039 -> Int
4140 -> Assertion
4241caseHelper 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'
4443 res @?= expRes
4544
4645caseCountScalarsWithAnchor :: Assertion
@@ -152,7 +151,7 @@ caseDecodeInvalidDocument :: Assertion
152151caseDecodeInvalidDocument = do
153152 x <- try $ C.runResourceT $ decode yamlBS C.$$ CL.sinkNull
154153 case x of
155− Left (e :: SomeException) -> return ()
154+ Left (_ :: SomeException) -> return ()
156155 Right y -> do
157156 putStrLn $ "bad return value: " ++ show y
158157 assertFailure "expected parsing exception, but got no errors"