Permalink
Browse files

make sure map works with no query

  • Loading branch information...
nicferrier committed Oct 29, 2012
1 parent 0b7c77e commit e25e77b351712bddca4e1cc3a5a01b05b3c8a998
Showing with 26 additions and 1 deletion.
  1. +3 −1 db.el
  2. +23 −0 tests.el
View
4 db.el
@@ -176,7 +176,9 @@ This is very useful for testing.")
The QUERY is ignored. We never filter."
(let* ((equal-fn (plist-get db :query-equal))
- (filterfn (kvquery->func query :equal-func equal-fn)))
+ (filterfn (if query
+ (kvquery->func query :equal-func equal-fn)
+ 'identity)))
(maphash
(lambda (key value)
(when (funcall filterfn value)
View
@@ -44,6 +44,29 @@
("surname" . "Test")))
(db-query db '(= "username" "test001"))))))
+(ert-deftest db-map ()
+ "Test the mapping."
+ (let (collected
+ (db (db-make '(db-hash :query-equal kvdotassoc=)))
+ (data '(("test001"
+ ("username" . "test001")
+ ("title" . "Miss")
+ ("surname" . "Test"))
+ ("test002"
+ ("username" . "test002")
+ ("title" . "Mr")
+ ("surname" . "Test")))))
+ (loop for (key . value) in data
+ do (db-put key value db))
+ (db-map (lambda (key value)
+ (setq
+ collected
+ (acons key value collected))) db)
+ (should
+ (equal
+ (kvalist-sort collected 'kvcmp)
+ (kvalist-sort data 'kvcmp)))))
+
(ert-deftest db-query-deep ()
"Test the query interface with a dotted query."
(let ((db (db-make '(db-hash :query-equal kvdotassoc=))))

0 comments on commit e25e77b

Please sign in to comment.