summaryrefslogtreecommitdiff
path: root/libraries/ghc-compact/tests/compact_simple.hs
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/ghc-compact/tests/compact_simple.hs')
-rw-r--r--libraries/ghc-compact/tests/compact_simple.hs37
1 files changed, 37 insertions, 0 deletions
diff --git a/libraries/ghc-compact/tests/compact_simple.hs b/libraries/ghc-compact/tests/compact_simple.hs
new file mode 100644
index 0000000000..28575d20d0
--- /dev/null
+++ b/libraries/ghc-compact/tests/compact_simple.hs
@@ -0,0 +1,37 @@
+module Main where
+
+import Control.Exception
+import System.Mem
+
+import GHC.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)
+
+-- test :: (Word -> a -> IO (Maybe (Compact a))) -> IO ()
+test func = do
+ let val = ("hello", 1, 42, 42, Just 42) ::
+ (String, Int, Int, Integer, Maybe Int)
+ str <- func val
+
+ -- check that val is still good
+ assertEquals ("hello", 1, 42, 42, Just 42) val
+ -- check the value in the compact
+ assertEquals ("hello", 1, 42, 42, Just 42) (getCompact str)
+ performMajorGC
+ -- check again val
+ assertEquals ("hello", 1, 42, 42, Just 42) val
+ -- check again the value in the compact
+ assertEquals ("hello", 1, 42, 42, Just 42) (getCompact str)
+
+ print =<< compactSize str
+
+main = do
+ test compactWithSharing
+ test compact