@@ -34,6 +34,8 @@ import Data.Vector (Vector)
3434import qualified Data.Vector as V
3535import Data.HashMap.Strict (HashMap)
3636import qualified Data.HashMap.Strict as HM
37+import System.IO (hClose)
38+import System.IO.Temp (withSystemTempFile)
3739
3840data TestJSON = TestJSON
3941 { string :: Text
@@ -152,6 +154,8 @@ spec = do
152154
153155 it "preserves Scientific precision" casePreservesScientificPrecision
154156
157+ it "truncates files" caseTruncatesFiles
158+
155159
156160specialStrings :: [T.Text]
157161specialStrings =
@@ -502,3 +506,12 @@ casePreservesScientificPrecision = do
502506 -- results, because of <https://github.com/bos/text/issues/34>.
503507 D.decodeEither "x: 9.78159610558926e-5" @?= Right (object
504508 [ "x" .= D.Number (read "9.78159610558926e-5") ])
509+
510+caseTruncatesFiles :: Assertion
511+caseTruncatesFiles = withSystemTempFile "truncate.yaml" $ \fp h -> do
512+ replicateM_ 500 $ B8.hPut h "HELLO WORLD!!!!!\n"
513+ hClose h
514+ let val = object ["hello" .= ("world" :: String)]
515+ D.encodeFile fp val
516+ res <- D.decodeFileEither fp
517+ either (Left . show) Right res `shouldBe` Right val