@@ -16,6 +16,8 @@ import Test.Framework.Providers.HUnit
1616import Test.HUnit hiding (Test, path)
1717--import Test.QuickCheck
1818
19+import Control.Exception
20+
1921main :: IO ()
2022main = defaultMain
2123 [ testCase "count scalars with anchor" caseCountScalarsWithAnchor
@@ -27,6 +29,7 @@ main = defaultMain
2729 , testCase "encode/decode" caseEncodeDecode
2830 , testCase "encode/decode file" caseEncodeDecodeFile
2931 , testCase "interleaved encode/decode" caseInterleave
32+ , testCase "decode invalid document (without segfault)" caseDecodeInvalidDocument
3033 ]
3134
3235caseCountScalarsWithAnchor :: Assertion
@@ -173,3 +176,17 @@ caseInterleave = do
173176 case e of
174177 EventNone -> return ()
175178 _ -> emitEvent e >> inside
179+
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"
185+ where
186+ yamlString = " - foo\n - baz\nbuz"
187+ yamlBS = B8.pack yamlString
188+ dec front = do
189+ e <- parseEvent
190+ case e of
191+ EventNone -> return $ front []
192+ _ -> dec $ front . (:) e