Avoid failing tests for Emacs without lexical binding.
[gnus] / lisp / registry.el
index 6933725..3c402cb 100644 (file)
@@ -1,22 +1,24 @@
 ;;; registry.el --- Track and remember data items by various fields
 
-;; Copyright (C) 2011  Teodor Zlatanov
+;; Copyright (C) 2011  Free Software Foundation, Inc.
 
 ;; Author: Teodor Zlatanov <tzz@lifelogs.com>
 ;; Keywords: data
 
-;; This program is free software; you can redistribute it and/or modify
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
 ;; the Free Software Foundation, either version 3 of the License, or
 ;; (at your option) any later version.
 
-;; This program is distributed in the hope that it will be useful,
+;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
 
 ;;; Code:
 
-(eval-when-compile (require 'ert))
+(eval-when-compile
+  (when (null (ignore-errors (require 'ert)))
+    (defmacro* ert-deftest (name () &body docstring-keys-and-body))))
+
+(ignore-errors
+  (require 'ert))
+
 (eval-when-compile (require 'cl))
 (eval-and-compile
   (or (ignore-errors (progn
             :custom float
             :documentation "The registry version.")
    (max-hard :initarg :max-hard
+             :initform 5000000
              :type integer
              :custom integer
              :documentation "Never accept more than this many elements.")
    (max-soft :initarg :max-soft
+             :initform 50000
              :type integer
              :custom integer
              :documentation "Prune as much as possible to get to this size.")
    (tracked :initarg :tracked
+            :initform nil
             :type t
             :documentation "The tracked (indexed) fields, a list of symbols.")
    (precious :initarg :precious
+             :initform nil
              :type t
              :documentation "The precious fields, a list of symbols.")
    (tracker :initarg :tracker
          :type hash-table
          :documentation "The data hashtable.")))
 
-(defmethod initialize-instance :after ((this registry-db) slots)
+(defmethod initialize-instance :AFTER ((this registry-db) slots)
   "Set value of data slot of THIS after initialization."
-  ;; 'data' will already be set if read from file, so don't overwrite it.
-  (with-slots (data tracker tracked precious max-soft max-hard) this
+  (with-slots (data tracker) this
     (unless (member :data slots)
       (setq data (make-hash-table :size 10000 :rehash-size 2.0 :test 'equal)))
     (unless (member :tracker slots)
-      (setq tracker (make-hash-table :size 100 :rehash-size 2.0)))
-    (unless (member :max-soft slots)
-      (setq max-soft 50000))
-    (unless (member :max-hard slots)
-      (setq max-hard 5000000))
-    (unless (member :tracked slots)
-      (setq tracked nil))
-    (unless (member :precious slots)
-      (setq precious nil))))
+      (setq tracker (make-hash-table :size 100 :rehash-size 2.0)))))
 
 (defmethod registry-lookup ((db registry-db) keys)
   "Search for KEYS in the registry-db THIS.
@@ -354,12 +357,13 @@ Removes only entries without the :precious keys."
     (should (= 58 (caadr (registry-lookup db '(1 58 99)))))
     (message "Grouped individual lookup")
     (should (= 3 (length (registry-lookup db '(1 58 99)))))
-    (message "Individual lookup (breaks before lexbind)")
-    (should (= 58
-               (caadr (registry-lookup-breaks-before-lexbind db '(1 58 99)))))
-    (message "Grouped individual lookup (breaks before lexbind)")
-    (should (= 3
-               (length (registry-lookup-breaks-before-lexbind db '(1 58 99)))))
+    (when (boundp 'lexical-binding)
+      (message "Individual lookup (breaks before lexbind)")
+      (should (= 58
+                (caadr (registry-lookup-breaks-before-lexbind db '(1 58 99)))))
+      (message "Grouped individual lookup (breaks before lexbind)")
+      (should (= 3
+                (length (registry-lookup-breaks-before-lexbind db '(1 58 99))))))
     (message "Search")
     (should (= n (length (registry-search db :all t))))
     (should (= n (length (registry-search db :member '((sender "me"))))))