diff options
Diffstat (limited to 'libraries/compact/tests/compact_autoexpand.hs')
-rw-r--r-- | libraries/compact/tests/compact_autoexpand.hs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/libraries/compact/tests/compact_autoexpand.hs b/libraries/compact/tests/compact_autoexpand.hs new file mode 100644 index 0000000000..5db0bbc55f --- /dev/null +++ b/libraries/compact/tests/compact_autoexpand.hs @@ -0,0 +1,27 @@ +module Main where + +import Control.Exception +import System.Mem + +import Data.Compact + +assertFail :: String -> IO () +assertFail msg = throwIO $ AssertionFailed msg + +assertEquals :: (Eq a, Show a) => a -> a -> IO () +assertEquals expected actual = + if expected == actual then return () + else assertFail $ "expected " ++ (show expected) + ++ ", got " ++ (show actual) + +main = do + -- create a compact large 4096 bytes (minus the size of header) + -- add a value that is 1024 cons cells, pointing to 7 INTLIKE + -- each cons cell is 1 word header, 1 word data, 1 word next + -- so total 3072 words, 12288 bytes on x86, 24576 on x86_64 + -- it should not fit in one block + let val = replicate 4096 7 :: [Int] + str <- newCompact 1 val + assertEquals val (getCompact str) + performMajorGC + assertEquals val (getCompact str) |