unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
blob e352dd165f3b45f62828c50483cd856a526f01e1 2958 bytes (raw)
name: test/lisp/emacs-lisp/memory-report-tests.el 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
 
;;; memory-report-tests.el --- tests for memory-report.el -*- lexical-binding: t -*-

;; Copyright (C) 2020-2021 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 ()
  ;; Set the sizes on things based on a 64-bit architecture.  (We're
  ;; hard-coding this to be able to write simple tests that'll work on
  ;; all architectures.)
  (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 (list 1 2)) 32))
  (should (equal (memory-report-object-size (list 1)) 16))

  (should (equal (memory-report-object-size (list 'foo)) 16))

  (should (equal (memory-report-object-size (vector 1 2 3)) 64))
  (should (equal (memory-report-object-size (vector 1 2 3 4)) 80))

  (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))
                 81)))

(ert-deftest memory-report-sizes-vectors ()
  (should (= (memory-report--object-size
              (make-hash-table :test #'eq)
              ["long string that should be at least 40 bytes"])
             108))
  (let ((string "long string that should be at least 40 bytes"))
    (should (= (memory-report--object-size
                (make-hash-table :test #'eq)
                (vector string))
               108))
    (should (= (memory-report--object-size
                (make-hash-table :test #'eq)
                (vector string string))
               124))))

(ert-deftest memory-report-sizes-structs ()
  (cl-defstruct memory-report-test-struct
    (item0 nil)
    (item1 nil))
  (let ((s (make-memory-report-test-struct :item0 "hello" :item1 "world")))
    (should (= (memory-report-object-size s)
               90))))

(provide 'memory-report-tests)

;;; memory-report-tests.el ends here

debug log:

solving e352dd165f ...
found e352dd165f in https://git.savannah.gnu.org/cgit/emacs.git

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).