module Database.Redis.List.Tests ( tests ) where ------------------------------------------------------------------------------ import Test.Framework (Test) import Test.Framework.Providers.HUnit -- import Test.Framework.Providers.QuickCheck2 import qualified Test.HUnit as H -- import Test.QuickCheck -- import Test.QuickCheck.Monadic import Database.Redis ------------------------------------------------------------------------------ -- N.B. These aren't proper tests yet, just checks ------------------------------------------------------------------------------ tests :: [Test] tests = [ testCase "redis-link listRightPush" listRightPushTest , testCase "redis-link listLeftPush" listLeftPushTest , testCase "redis-link listIndex" listIndexTest , testCase "redis-link listLength" listLengthTest , testCase "redis-link listRange" listRangeTest ] ------------------------------------------------------------------------------ listRightPushTest :: H.Assertion listRightPushTest = do con <- connect localhost defaultPort _ <- select con 0 returning <- listRightPush con "thelist" "theitem" _ <- keyDelete con ["thelist"] disconnect con H.assertBool "listRightPush" $ case returning of Just (RedisInteger _) -> True _ -> False ------------------------------------------------------------------------------ listLeftPushTest :: H.Assertion listLeftPushTest = do con <- connect localhost defaultPort _ <- select con 0 returning <- listLeftPush con "leftlist" "anitem" _ <- keyDelete con ["leftlist"] disconnect con H.assertBool "listLeftPush" $ case returning of Just (RedisInteger _) -> True _ -> False ------------------------------------------------------------------------------ listLengthTest :: H.Assertion listLengthTest = do con <- connect localhost defaultPort _ <- select con 0 _ <- listRightPush con "lengthlist" "anitem" _ <- listRightPush con "lengthlist" "anitem" returning <- listLength con "lengthlist" _ <- keyDelete con ["lengthlist"] disconnect con H.assertEqual "listLeftPush" (Just $ RedisInteger 2) returning ------------------------------------------------------------------------------ listIndexTest :: H.Assertion listIndexTest = do con <- connect localhost defaultPort _ <- select con 0 _ <- listRightPush con "indexlist" "theitem" returning <- listIndex con "indexlist" 0 _ <- keyDelete con ["indexlist"] disconnect con H.assertEqual "listIndex" (Just $ RedisBulk [Just (RedisSingle $ toUTF8 "theitem")]) returning ------------------------------------------------------------------------------ listRangeTest :: H.Assertion listRangeTest = do con <- connect localhost defaultPort _ <- select con 0 _ <- listRightPush con "alist" "value0" _ <- listRightPush con "alist" "value1" returning <- listRange con "alist" 0 1 _ <- keyDelete con ["alist"] disconnect con H.assertEqual "listRange" (Just (RedisBulk [Just (RedisBulk [Just (RedisSingle $ toUTF8 "value0")]) ,Just (RedisBulk [Just (RedisSingle $ toUTF8 "value1")]) ,Nothing])) returning