@@ -16,6 +16,8 @@ import Test.Framework.Providers.HUnit
16import Test.HUnit hiding (Test, path)
16import Test.HUnit hiding (Test, path)
17--import Test.QuickCheck
17--import Test.QuickCheck
19+import Control.Exception
19main :: IO ()
21main :: IO ()
20main = defaultMain
22main = defaultMain
21 [ testCase "count scalars with anchor" caseCountScalarsWithAnchor
23 [ testCase "count scalars with anchor" caseCountScalarsWithAnchor
@@ -27,6 +29,7 @@ main = defaultMain
27 , testCase "encode/decode" caseEncodeDecode
29 , testCase "encode/decode" caseEncodeDecode
28 , testCase "encode/decode file" caseEncodeDecodeFile
30 , testCase "encode/decode file" caseEncodeDecodeFile
29 , testCase "interleaved encode/decode" caseInterleave
31 , testCase "interleaved encode/decode" caseInterleave
32+ , testCase "decode invalid document (without segfault)" caseDecodeInvalidDocument
32caseCountScalarsWithAnchor :: Assertion
35caseCountScalarsWithAnchor :: Assertion
@@ -173,3 +176,17 @@ caseInterleave = do
173 case e of
176 case e of
174 EventNone -> return ()
177 EventNone -> return ()
175 _ -> emitEvent e >> inside
178 _ -> emitEvent e >> inside
180+caseDecodeInvalidDocument :: Assertion
181+caseDecodeInvalidDocument = do
182+ handle (\(YamlParserException {}) -> return ()) $ do
183+ _ <- decode yamlBS $ dec id
184+ assertFailure "expected parsing exception, but got no errors"
186+ yamlString = " - foo\n - baz\nbuz"
187+ yamlBS = B8.pack yamlString
191+ EventNone -> return $ front []
192+ _ -> dec $ front . (:) e