summaryrefslogtreecommitdiff
path: root/libraries/ghc-compact/tests/compact_simple.hs
diff options
context:
space:
mode:
authorEdward Z. Yang <ezyang@cs.stanford.edu>2017-02-23 13:46:02 -0800
committerEdward Z. Yang <ezyang@cs.stanford.edu>2017-02-26 01:23:35 -0800
commita0b4a2ac5015e9accd4fb71290a68ce1a1d3d630 (patch)
treea7c762f501bc072c81d27c71e0640f9490a36819 /libraries/ghc-compact/tests/compact_simple.hs
parent8f20844d3435094583db92a30550ca319d2be863 (diff)
downloadhaskell-a0b4a2ac5015e9accd4fb71290a68ce1a1d3d630.tar.gz
Rename compact to ghc-compact.
Summary: The plan is to release a separate library, 'compact', which gives a friendly user-facing interface. This library is just enough so that we can make sure the functionality is working in GHC. Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu> Test Plan: validate Reviewers: bgamari, dfeuer, austin, simonmar, hvr Subscribers: thomie, erikd, snowleopard Differential Revision: https://phabricator.haskell.org/D3206
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