Commits

llibra  committed 14fee1e

Cleaned up test code.

- New naming convention.
- Moved RM and NOP callback functions to t/util.lisp.

  • Participants
  • Parent commits 0082116

Comments (0)

Files changed (3)

 
 (5am:in-suite cur)
 
-(5am:test db
+(5am:test cur/db
   (with-new-db (db)
     (let ((cur (kc.db:cursor db)))
       (5am:is (= (cffi:pointer-address db)
                  (cffi:pointer-address (kc.cur:db cur))))
       (kc.cur:delete cur))))
 
-(5am:test error
+(5am:test cur/error
   (with-new-db (db)
     (let ((cur (kc.db:cursor db)))
       (5am:signals kc.cur:error (kc.cur:error cur "An error occured."))
           (5am:is (equal "no error" (kc.err:message c)))))
       (kc.cur:delete cur))))
 
-(5am:test new/delete
+(5am:test cur/new-and-delete
   (with-new-db (db)
     (5am:finishes
       (let ((c (kc.db:cursor db)))
         (5am:is (cffi:pointerp c))
         (kc.cur:delete c)))))
 
-(5am:test accept/write
+(5am:test cur/low/accept/write
   (with-new-db (db)
     (kc.db:set db "x" "1")
     (kc.cur:with-cursor (cur db)
              (funcall fn cur new))
            (5am:is (equal new (kc.db:get db key))))))
   (let ((key "x") (old "1") (new "2"))
-    (5am:test (set-value/low/set :compile-at :definition-time)
+    (5am:test (cur/low/set-value/set :compile-at :definition-time)
       (body (lambda (cur new)
               (cffi:with-foreign-string ((buf len) new :null-terminated-p nil)
                 (kc.cur.low:set-value cur buf len)))
             key old new))
-    (5am:test (set-value/set :compile-at :definition-time)
+    (5am:test (cur/set-value/set :compile-at :definition-time)
       (body #'kc.cur:set-value key old new))))
 
-(5am:test remove
+(5am:test cur/remove
   (with-new-db (db)
     (kc.db:set db "x" "1")
     (kc.cur:with-cursor (cur db)
     (5am:signals kc.db:error (kc.db:get db "x"))
     (5am:is (zerop (kc.db:count db)))))
 
-(5am:test jump
+(5am:test cur/jump
   (with-new-db (db)
     (let ((cur (kc.db:cursor db)))
       ;; Expect to signal kc.cur:error due to no record.
       (5am:is-true (kc.cur:jump cur))
       (kc.cur:delete cur))))
 
-(5am:test with-cursor/no-record
+(5am:test cur/with-cursor/no-record
   (with-new-db (db)
     (5am:signals kc.cur:error
       (kc.cur:with-cursor (cur db) :not-evaluated))))
 
-(5am:test with-cursor/return-value
+(5am:test cur/with-cursor/return-value
   (with-new-db (db)
     (kc.db:set db "set" "but not used")
     (5am:is (zerop (kc.cur:with-cursor (cur db) 0)))))
                  (let ((s (cffi:foreign-string-to-lisp ptr)))
                    (5am:is (funcall value-pred s))))
                (5am:is (funcall len-pred len)))))))
-  (5am:test (get-key/low/value :compile-at :definition-time)
+  (5am:test (cur/low/get-key/value :compile-at :definition-time)
     (body "x" "1"
           #'kc.cur.low:get-key
           (lambda (v) (equal "x" v))
           (lambda (l) (= 1 l))))
-  (5am:test (get-value/low/value :compile-at :definition-time)
+  (5am:test (cur/low/get-value/value :compile-at :definition-time)
     (body "x" "1"
           #'kc.cur.low:get-value
           (lambda (v) (equal "1" v))
            (kc.db:set db key value)
            (kc.cur:with-cursor (cur db)
              (5am:is (funcall pred (funcall fn cur)))))))
-  (5am:test (get-key/value :compile-at :definition-time)
+  (5am:test (cur/get-key/value :compile-at :definition-time)
     (body "x" "1" #'kc.cur:get-key (lambda (v) (equal "x" v))))
-  (5am:test (get-value/value :compile-at :definition-time)
+  (5am:test (cur/get-value/value :compile-at :definition-time)
     (body "x" "1" #'kc.cur:get-value (lambda (v) (equal "1" v)))))
 
-(5am:test get/low/value
+(5am:test cur/low/get/value
   (with-new-db (db)
     (kc.db:set db "x" "1")
     (kc.cur:with-cursor (cur db)
               (5am:is (equal "x" key))
               (5am:is (equal "1" value)))))))))
 
-(5am:test get/value
+(5am:test cur/get/value
   (with-new-db (db)
     (kc.db:set db "x" "1")
     (kc.cur:with-cursor (cur db)
         (5am:is (equal "x" key))
         (5am:is (equal "1" value))))))
 
-(cffi:defcallback nop :pointer
-    ((kbuf :pointer) (ksiz kc.ffi:size_t) (vbuf :pointer) (vsiz kc.ffi:size_t)
-     (sp :pointer) (opq :pointer))
-  (declare (ignore kbuf ksiz vbuf vsiz sp opq))
-  kc.ffi:+kcvisnop+)
-
 (flet ((body (fn)
          (with-new-db (db)
            (kc.db:set db "x" "1")
              (kc.cur:jump cur)
              (5am:finishes
                (progn (funcall fn cur nil) (funcall fn cur t)))))))
-  (5am:test (accept/step :compile-at :definition-time)
+  (5am:test (cur/low/accept/step :compile-at :definition-time)
     (body (lambda (cur step)
             (kc.cur.low:accept cur (cffi:callback nop)
                                :writable nil :step step))))
-  (5am:test (set-value/low/step :compile-at :definition-time)
+  (5am:test (cur/low/set-value/step :compile-at :definition-time)
     (body (lambda (cur step)
             (cffi:with-foreign-string ((buf len) "2" :null-terminated-p nil)
               (kc.cur.low:set-value cur buf len :step step)))))
-  (5am:test (get-key/low/step :compile-at :definition-time)
+  (5am:test (cur/low/get-key/step :compile-at :definition-time)
     (body (lambda (cur step)
             (kc.ffi:kcfree (kc.cur.low:get-key cur :step step)))))
-  (5am:test (get-value/low/step :compile-at :definition-time)
+  (5am:test (cur/low/get-value/step :compile-at :definition-time)
     (body (lambda (cur step)
             (kc.ffi:kcfree (kc.cur.low:get-value cur :step step)))))
-  (5am:test (get/low/step :compile-at :definition-time)
+  (5am:test (cur/low/get/step :compile-at :definition-time)
     (body (lambda (cur step)
             (multiple-value-bind (kb kl vb vl) (kc.cur.low:get cur :step step)
               (declare (ignore kl vl))
               (kc.ffi:kcfree kb)
               (kc.ffi:kcfree vb)))))
-  (5am:test (set-value/step :compile-at :definition-time)
+  (5am:test (cur/set-value/step :compile-at :definition-time)
     (body (lambda (cur step)
             (kc.cur:set-value cur "2" :step step))))
-  (5am:test (get-key/step :compile-at :definition-time)
+  (5am:test (cur/get-key/step :compile-at :definition-time)
     (body (lambda (cur step)
             (kc.cur:get-key cur :step step))))
-  (5am:test (get-value/step :compile-at :definition-time)
+  (5am:test (cur/get-value/step :compile-at :definition-time)
     (body (lambda (cur step)
             (kc.cur:get-value cur :step step))))
-  (5am:test (get/step :compile-at :definition-time)
+  (5am:test (cur/get/step :compile-at :definition-time)
     (body (lambda (cur step)
             (kc.cur:get cur :step step)))))
 
 (5am:in-suite db)
 
-(5am:test error
+(5am:test db/error
   (with-new-db (db)
     (5am:signals kc.db:error (kc.db:error db "An error occured."))
     (5am:signals kc.db:error (kc.db:error db "With an argument. ~a" 0))))
 
 ;;; TODO: Very poor. Need refactoring.
-(5am:test set
+(5am:test db/set
   (with-new-db (db)
     (5am:finishes (kc.db:set db "John" "McCarthy"))
     (5am:finishes (kc.db:set db "ジョン" "マッカーシー"))))
 
-(5am:test get
+(5am:test db/get
   (with-new-db (db)
     (kc.db:set db "x" "1")
     (5am:is (equal "1" (kc.db:get db "x")))))
 
-(5am:test seize
+(5am:test db/seize
   (with-new-db (db)
     (flet ((test (fn)
              (kc.db:set db "x" "1")
              (5am:finishes (funcall fn))
-             (5am:signals error (kc.db:get db "x"))))
+             (5am:signals kc.db:error (kc.db:get db "x"))))
       (test (lambda () (kc.db:get db "x" :remove t)))
       (test (lambda () (kc.db:seize db "x"))))))
 
-(cffi:defcallback rm :pointer
-    ((kbuf :pointer) (ksiz kc.ffi:size_t) (vbuf :pointer) (vsiz kc.ffi:size_t)
-     (sp :pointer) (opq :pointer))
-  (declare (ignore kbuf ksiz vbuf vsiz sp opq))
-  kc.ffi:+kcvisremove+)
-
-(5am:test iterate
+(5am:test db/iterate
   (with-new-db (db)
     (kc.db:set db "x" "1")
     (kc.db:set db "y" "2")
     (kc.db:append db "x" "+")
     (5am:is (equal "+++" (kc.db:get db "x")))))
 
-(5am:test increment
+(5am:test db/increment
   (with-new-db (db)
     (5am:is (= 1 (kc.db:increment db "i" 1)))
     (5am:is (= 2 (kc.db:increment db "i" 1)))
     (5am:is (= 1.0d0 (kc.db:increment db "f" 0.5d0)))
     (5am:is (= 2.5d0 (kc.db:increment db "f" 1.5d0)))))
 
-(5am:test cas
+(5am:test db/cas
   (with-new-db (db)
     (kc.db:set db "x" "old")
     (kc.db:cas db "x" "old" "new")
     (5am:is (equal "new" (kc.db:get db "x")))))
 
-(5am:test remove
+(5am:test db/remove
   (with-new-db (db)
     (kc.db:set db "x" "1")
     (kc.db:set db "y" "2")
     (kc.db:remove db "x")
     (kc.db:remove db "y")
     (5am:is (zerop (kc.db:count db)))
-    (5am:signals error (kc.db:get db "x"))
-    (5am:signals error (kc.db:get db "y"))))
+    (5am:signals kc.db:error (kc.db:get db "x"))
+    (5am:signals kc.db:error (kc.db:get db "y"))))
 
-(5am:test clear
+(5am:test db/clear
   (with-new-db (db)
     (kc.db:set db "x" "1")
     (kc.db:set db "y" "2")
     (kc.db:clear db)
-    (5am:signals error (kc.db:get db "x"))
-    (5am:signals error (kc.db:get db "y"))
+    (5am:signals kc.db:error (kc.db:get db "x"))
+    (5am:signals kc.db:error (kc.db:get db "y"))
     (5am:is (zerop (kc.db:count db)))))
 
-(5am:test snapshot
+(5am:test db/snapshot
   (let ((dest "test.kcss"))
     (with-new-db (db)
       (kc.db:set db "x" "1")
         (5am:is (equal "2" (kc.db:get db "y")))
         (5am:is (= count (kc.db:count db)))))))
 
-(5am:test count
+(5am:test db/count
   (with-new-db (db)
     (5am:is (zerop (kc.db:count db)))
     (kc.db:set db "x" "1")
     (kc.db:set db "y" "2")
     (5am:is (= (kc.db:count db) 2))))
 
-(5am:test size
+(5am:test db/size
   (5am:is (= (with-new-db (db)
                (kc.db:size db))
              (with-open-file (s *default-db-pathname*)
                (file-length s)))))
 
-(5am:test merge
+(5am:test db/merge
   (with-new-db (src1 "src1.kch")
     (kc.db:set src1 "x" "1")
     (with-new-db (src2 "src2.kch")
         (5am:is (equal "1" (kc.db:get dest "x")))
         (5am:is (equal "2" (kc.db:get dest "y")))))))
 
-(5am:test copy
+(5am:test db/copy
   (with-new-db (src "src.kch")
     (kc.db:set src "x" "1")
     (kc.db:set src "y" "2")
     (with-db (dest "dest.kch")
       (5am:is (equal "1" (kc.db:get dest "x")))
       (5am:is (equal "2" (kc.db:get dest "y")))
-      (5am:signals error (kc.db:get dest "z"))
+      (5am:signals kc.db:error (kc.db:get dest "z"))
       (5am:is (= 2 (kc.db:count dest))))))
   (once-only (path)
     `(let ((,path (namestring (translate-logical-pathname ,path))))
        (kc.db:with-db (,var ,path :reader :writer :create :truncate) ,@body))))
+
+(cffi:defcallback rm :pointer
+    ((kbuf :pointer) (ksiz kc.ffi:size_t) (vbuf :pointer) (vsiz kc.ffi:size_t)
+     (sp :pointer) (opq :pointer))
+  (declare (ignore kbuf ksiz vbuf vsiz sp opq))
+  kc.ffi:+kcvisremove+)
+
+(cffi:defcallback nop :pointer
+    ((kbuf :pointer) (ksiz kc.ffi:size_t) (vbuf :pointer) (vsiz kc.ffi:size_t)
+     (sp :pointer) (opq :pointer))
+  (declare (ignore kbuf ksiz vbuf vsiz sp opq))
+  kc.ffi:+kcvisnop+)