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 listRightPush" listRightPushTest , testCase "redis listRightPushB" listRightPushBTest , testCase "redis listLeftPush" listLeftPushTest , testCase "redis listLeftPushB" listLeftPushBTest , testCase "redis listIndex" listIndexTest , testCase "redis listIndexB" listIndexBTest , testCase "redis listLength" listLengthTest , testCase "redis listLengthB" listLengthBTest , testCase "redis listRange" listRangeTest , testCase "redis listRangeB" listRangeBTest , testCase "redis listRemove" listRemoveTest ] ------------------------------------------------------------------------------ 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 ------------------------------------------------------------------------------ listRightPushBTest :: H.Assertion listRightPushBTest = do con <- connect localhost defaultPort _ <- select con 0 returning <- listRightPushB con (toUTF8 "anotherlist") (toUTF8 "theitem") _ <- keyDeleteB con $ map toUTF8 ["anotherlist"] disconnect con H.assertBool "listRightPushB" $ 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 ------------------------------------------------------------------------------ listLeftPushBTest :: H.Assertion listLeftPushBTest = do con <- connect localhost defaultPort _ <- select con 0 returning <- listLeftPushB con (toUTF8 "leftblist") (toUTF8 "anotheritem") _ <- keyDelete con ["leftblist"] 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 "listLength" (Just $ RedisInteger 2) returning ------------------------------------------------------------------------------ listLengthBTest :: H.Assertion listLengthBTest = do con <- connect localhost defaultPort _ <- select con 0 _ <- listRightPush con "lengthBlist" "anitem" _ <- listRightPush con "lengthBlist" "anitem" returning <- listLengthB con (toUTF8 "lengthBlist") _ <- keyDelete con ["lengthBlist"] disconnect con H.assertEqual "listLengthB" (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 ------------------------------------------------------------------------------ listIndexBTest :: H.Assertion listIndexBTest = do con <- connect localhost defaultPort _ <- select con 0 _ <- listRightPush con "indexblist" "theitem" returning <- listIndexB con (toUTF8 "indexblist") 0 _ <- keyDelete con ["indexblist"] disconnect con H.assertEqual "listIndexB" (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 ------------------------------------------------------------------------------ listRangeBTest :: H.Assertion listRangeBTest = do con <- connect localhost defaultPort _ <- select con 0 _ <- listRightPush con "ablist" "value0" _ <- listRightPush con "ablist" "value1" returning <- listRangeB con (toUTF8 "ablist") 0 1 _ <- keyDelete con ["ablist"] disconnect con H.assertEqual "listRange" (Just (RedisBulk [Just (RedisBulk [Just (RedisSingle $ toUTF8 "value0")]) ,Just (RedisBulk [Just (RedisSingle $ toUTF8 "value1")]) ,Nothing])) returning ------------------------------------------------------------------------------ listRemoveTest :: H.Assertion listRemoveTest = do con <- connect localhost defaultPort _ <- select con 0 _ <- listRightPush con "rlist" "value" _ <- listRightPush con "rlist" "value" returning <- listRemove con "rlist" (-1) "value" _ <- keyDelete con ["rlist"] disconnect con H.assertEqual "listLeftPush" (Just $ RedisInteger 1) returning