emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

scratch/memrep e2d5c1d: Add some tests


From: Lars Ingebrigtsen
Subject: scratch/memrep e2d5c1d: Add some tests
Date: Thu, 10 Dec 2020 21:07:57 -0500 (EST)

branch: scratch/memrep
commit e2d5c1d5d16a8c6df38035e1e63b436edfe15d10
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Add some tests
---
 lisp/emacs-lisp/memory-report.el            | 12 +++++++-
 test/lisp/emacs-lisp/memory-report-tests.el | 48 +++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/lisp/emacs-lisp/memory-report.el b/lisp/emacs-lisp/memory-report.el
index c2fa28a..3dc0a53 100644
--- a/lisp/emacs-lisp/memory-report.el
+++ b/lisp/emacs-lisp/memory-report.el
@@ -64,7 +64,9 @@
 
 (defun memory-report-object-size (object)
   "Return the size of OBJECT in bytes."
-  (memory-report--object-size (make-hash-table #'eq) object))
+  (unless memory-report--type-size
+    (memory-report--garbage-collect))
+  (memory-report--object-size (make-hash-table :test #'eq) object))
 
 (defvar memory-report--type-size (make-hash-table))
 
@@ -189,6 +191,14 @@
              (cl-incf total (memory-report--object-size counted elem)))
     total))
 
+(cl-defmethod memory-report--object-size-1 (counted (value integer))
+  ;; There's no context an integer takes up more space?
+  0)
+
+(cl-defmethod memory-report--object-size-1 (counted (value float))
+  ;; There's no context a float takes up more space?
+  0)
+
 (cl-defmethod memory-report--object-size-1 (counted (value hash-table))
   (let ((total (+ (memory-report--size 'vector)
                   (* (memory-report--size 'object) (hash-table-size value)))))
diff --git a/test/lisp/emacs-lisp/memory-report-tests.el 
b/test/lisp/emacs-lisp/memory-report-tests.el
new file mode 100644
index 0000000..146800f
--- /dev/null
+++ b/test/lisp/emacs-lisp/memory-report-tests.el
@@ -0,0 +1,48 @@
+;;; memory-report-tests.el --- tests for memory-report.el              -*- 
lexical-binding: t -*-
+
+;; Copyright (C) 2016-2020 Free Software Foundation, Inc.
+
+;; 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.
+
+;; 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 GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+(require 'ert)
+(require 'memory-report)
+
+(defun setup-memory-report-tests ()
+  (memory-report--set-size
+   '((conses 16 499173 99889)
+     (symbols 48 22244 3)
+     (strings 32 92719 4559)
+     (string-bytes 1 40402011)
+     (vectors 16 31919)
+     (vector-slots 8 385148 149240)
+     (floats 8 434 4519)
+     (intervals 56 24499 997)
+     (buffers 984 33))))
+
+(ert-deftest memory-report-sizes ()
+  (setup-memory-report-tests)
+  (should (equal (memory-report-object-size (cons nil nil)) 16))
+  (should (equal (memory-report-object-size (cons 1 2)) 16))
+
+  (should (equal (memory-report-object-size "") 32))
+  (should (equal (memory-report-object-size "a") 33))
+  (should (equal (memory-report-object-size (propertize "a" 'face 'foo))
+                 ;; Possibly?
+                 161)))
+
+(provide 'memory-report-tests)
+
+;;; memory-report-tests.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]