on 73e7201 help sign in
typerep-map/test/Test/TypeRep/TypeRepMap.hs
53 lines 1.9 kB history raw
1module Test.TypeRep.TypeRepMap
2 ( typeRepMapSpec
3 ) where
5import Prelude hiding (lookup)
7import Data.Functor.Identity (Identity (..))
8import GHC.Exts (fromList)
9import Test.Hspec (Spec, describe, it, shouldBe)
11import Data.TMap (TMap, empty, insert, lookup, one, size, union)
12import Data.TypeRepMap.Internal (WrapTypeable (..))
15-- Simple test for 'lookup', 'insert' and 'size' functions.
16typeRepMapSpec :: Spec
17typeRepMapSpec = describe "TypeRepMap" $ do
18 describe "Lookup Test" $ do
19 it "returns the inserted element" $
20 lookup (fromList [WrapTypeable $ Identity 'a']) `shouldBe` Just 'a'
21 it "returns the second inserted value of the same type" $
22 lookup (fromList [WrapTypeable (Identity 'b'), WrapTypeable (Identity 'a')]) `shouldBe` Just 'b'
24 describe "Size Test" $ do
25 it "is empty" $
26 size empty `shouldBe` 0
27 it "is of size 1 when 1 element inserted" $
28 size (one 'a') `shouldBe` 1
29 it "doesn't increase size when element of the same type is added" $
30 size (insert 'b' $ insert 'a' empty) `shouldBe` 1
31 it "returns 10 when 10 different types are inserted" $
32 size mapOf10 `shouldBe` 10
34 describe "Union test" $ do
35 let m = fromList [WrapTypeable $ Identity 'a', WrapTypeable $ Identity True] `union`
36 fromList [WrapTypeable $ Identity 'b']
37 it "lookup works on union as expected" $ do
38 lookup m `shouldBe` Just 'a'
39 lookup m `shouldBe` Just True
40 lookup @Int m `shouldBe` Nothing
43mapOf10 :: TMap
44mapOf10 = insert True
45 $ insert [True, False]
46 $ insert (Just True)
47 $ insert (Just ())
48 $ insert [()]
49 $ insert ()
50 $ insert @String "aaa"
51 $ insert (Just 'a')
52 $ insert 'a'
53 $ insert (11 :: Int) empty