Nikhil Marathe avatar Nikhil Marathe committed 59b1ba8

Added more comprehensive tests. Yet the list, sets and sorted sets haven't been tested

Comments (0)

Files changed (1)

     (let ((assertion-string (join (list "Assertion failed: " (string expr)) "")))
         (unless (true? (eval expr)) (throw-error assertion-string))))
 
+(define-macro (assert-false expr)
+    (let ((assertion-string (join (list "Assertion false failed: " (string expr)) "")))
+        (if (true? (eval expr)) (throw-error assertion-string))))
+
 (define-macro (assert-equals expr val)
   (letex ((e (eval expr)))
     (assert (= e val))))
 (load "redis.lsp")
 (setf conn (redis))
 
-(if (nil? conn)
-  (throw-error "Could not connect to Redis!")
-  true)
+(constant 'TEST_DB 15)
+(constant 'MOVE_DB 14)
 
-(assert-equals (:select conn 14) "OK")
+(assert (:select conn MOVE_DB))
+(assert (:flushdb conn))
+(assert (:select conn TEST_DB))
+(assert (:flushdb conn))
 
-;; If you have authentication enabled
-;; uncomment this
-;; (assert-equals (:auth conn "foobared") "OK")
+(let (info (:info conn))
+  (assert (lookup "redis_version" info))
+  (assert (lookup "connected_clients" info))
+  (assert (int (lookup "uptime_in_seconds" info)))
+  (assert (int (lookup "connected_clients" info))))
 
-(assert-equals (:ping conn) "PONG")
-(assert-equals (:bgsave conn) "Background saving started")
+;
+; SET
+;
+(assert (:set conn "crap" "bag"))
+(assert (:set conn "foo" "bar"))
+(assert (:set conn "count" 0))
 
-(println "Database size is " (:dbsize conn))
+(assert-equals (:setnx conn "foo" "baz") 0)
+(assert-equals (:setnx conn "boo" "unset") 1)
 
-(println "Keys are " (:keys conn "*"))
+;
+; GET
+; 
+(assert-equals (:get conn "foo") "bar")
+(assert-equals (:get conn "boo") "unset")
 
-(println "Set abcd to 42 => " (:set conn "abcd" 42))
-(println "INCR abcd => " (:incr conn "abcd"))
-(println "INCRBY 5 => " (:incrby conn "abcd" 5))
+(let (rep (:mget conn "foo" "boo"))
+  (assert-equals (rep 0) "bar")
+  (assert-equals (rep 1) "unset"))
 
-(dolist (x (:keys conn "abcd"))
-  (println x " --> " (:get conn x)))
+(assert-equals (:getset conn "foo" "crackle") "bar")
 
-(assert-equals (:getset conn "abcd" 666) "48")
-(assert-equals (:get conn "abcd") "666")
+;(let (uni (string "�" "�" (char 937)))
+;  (assert (:set conn "unicode" uni))
+;  (assert-equals (:get conn "unicode") uni))
 
-(assert-equals (:setnx conn "abcd" 90) 0)
+;
+; INCR
+;
+(assert-equals (:incr conn "count") 1)
+(assert-equals (:incr conn "count") 2)
 
-(dotimes (x 5)
-    (:sadd conn "testset" (rand 100)))
+(assert-equals (:incrby conn "count" 4) 6)
+(assert-equals (:incrby conn "count" -2) 4)
 
-(println (:smembers conn "testset"))
-(:close conn)
+(assert-equals (:decr conn "count") 3)
 
-(println "All tests OK")
+(assert-equals (:decrby conn "count" 6) -3)
+
+;
+; EXISTS
+;
+(assert (:exists conn "count"))
+(assert (:exists conn "foo"))
+(assert-false (:exists conn "counta"))
+
+(assert (:del conn "count"))
+(assert-false (:exists conn "count"))
+
+;
+; KEYS
+;
+(assert (:set conn "foo2" "value"))
+
+(let (keys (:keys conn "foo*"))
+  (assert-equals (length keys) 2))
+
+(let (keys (:keys conn "*"))
+  (assert-equals (length keys) 4))
+
+(let (keys (:keys conn "?oo"))
+  (assert-equals (length keys) 2)
+  (assert (member "boo" keys))
+  (assert (member "foo" keys)))
+
+(dotimes (x 20)
+  (assert (member (:randomkey conn) '("boo" "foo" "count" "crap" "foo2"))))
+
+
+
+(println "All tests...OK")
 (exit)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.