emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/inspector 4066d7b441 13/39: Starting some tree-inspecto


From: ELPA Syncer
Subject: [elpa] externals/inspector 4066d7b441 13/39: Starting some tree-inspector tests
Date: Sat, 10 Sep 2022 17:57:47 -0400 (EDT)

branch: externals/inspector
commit 4066d7b44175222e085e02dd9ee2d1b570344c09
Author: Mariano Montone <marianomontone@gmail.com>
Commit: Mariano Montone <marianomontone@gmail.com>

    Starting some tree-inspector tests
---
 tree-inspector-tests.el | 281 ++++++++++++++++++++++++++++++++++++++++++++++++
 tree-inspector.el       |   5 +-
 2 files changed, 284 insertions(+), 2 deletions(-)

diff --git a/tree-inspector-tests.el b/tree-inspector-tests.el
index 4c3f313ba8..a258f32f08 100644
--- a/tree-inspector-tests.el
+++ b/tree-inspector-tests.el
@@ -1,3 +1,35 @@
+;; tree-inspector-tests.el --- Tests for Emacs tree-inspector  -*- 
lexical-binding: t; -*-
+
+;; Copyright (C) 2022 Free Software Foundation, Inc.
+
+;; Author: Mariano Montone <marianomontone@gmail.com>
+;; URL: https://github.com/mmontone/emacs-inspector
+;; Keywords: debugging, tool, emacs-lisp, development
+;; Version: 0.2
+;; Package-Requires: ((emacs "25"))
+
+;; This program 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,
+;; 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/>.
+
+;;; Commentary:
+
+;; Tests for tree-inspector package
+
+;;; Code:
+
+(require 'tree-inspector)
+(require 'ert)
+
 ;; (tree-inspector-inspect 2)
 ;; (tree-inspector-inspect (list 1 2 3))
 ;; (tree-inspector-inspect (list 1 2 3 (list "lala" "sf")))
@@ -12,3 +44,252 @@
 ;;  :success
 ;;  (lambda (&rest args)
 ;;    (tree-inspector-inspect (json-read-from-string (getf args :data)))))
+
+(defmacro tree-inspector-tests--with-tree-inspector-contents
+    (var-and-object &rest body)
+  "Bind VAR to the contents of the buffer, resulting of inspecting OBJECT with 
the tree-inspector."
+  (let ((buffer (gensym "buffer")))
+    `(let ((,buffer (tree-inspector-inspect ,(car (last var-and-object)))))
+       (with-current-buffer ,buffer
+        (let ((,(car var-and-object) (buffer-string)))
+          (kill-current-buffer)
+          ,@body)))))
+
+(defun tree-inspector-tests-run ()
+  "Run tree-inspector tests."
+  (ert "tree-inspector-tests.*"))
+
+(ert-deftest tree-inspector-tests--inspect-integer-test ()
+  (tree-inspector-tests--with-tree-inspector-contents
+   (buffer-string 22)
+   (should (cl-search "22" buffer-string))
+   ;;(should (cl-search "integer" buffer-string))
+   ))
+
+(ert-deftest tree-inspector-tests--inspect-float-test ()
+  (tree-inspector-tests--with-tree-inspector-contents
+   (buffer-string 2.22)
+   (should (cl-search "2.22" buffer-string))
+   ;;(should (cl-search "float" buffer-string))
+   ))
+
+(ert-deftest inspector-tests--inspect-character-test ()
+  (inspector-inspect ?a)
+  (let ((buffer-string (buffer-string)))
+    (should (cl-search "character" buffer-string))
+    (should (cl-search "97" buffer-string))
+    (inspector-quit)))
+
+(ert-deftest inspector-tests--inspect-symbol-test ()
+  (inspector-inspect 'abcd)
+  (let ((buffer-string (buffer-string)))
+    (should (cl-search "abcd" buffer-string))
+    (should (cl-search "symbol" buffer-string))
+    (inspector-quit))
+
+  (inspector-inspect :abcd)
+  (let ((buffer-string (buffer-string)))
+    (should (cl-search "abcd" buffer-string))
+    (should (cl-search "symbol" buffer-string))
+    (inspector-quit)))
+
+(ert-deftest inspector-tests--inspect-list-test ()
+  (inspector-inspect '(1 2 3))
+  (let ((buffer-string (buffer-string)))
+    (should (cl-search "list" buffer-string))
+    (should (cl-search "1" buffer-string))
+    (should (cl-search "2" buffer-string))
+    (should (cl-search "3" buffer-string))
+    (inspector-quit)))
+
+(ert-deftest inspector-tests--inspect-vector-test ()
+  (inspector-inspect [1 "two" (three)])
+  (let ((buffer-string (buffer-string)))
+    (should (cl-search "vector" buffer-string))
+    (should (cl-search "1" buffer-string))
+    (should (cl-search "two" buffer-string))
+    (should (cl-search "three" buffer-string))
+    (inspector-quit)))
+
+;; Long lists are to be sliced:
+(ert-deftest inspector-tests--inspect-long-list-test ()
+  (inspector-inspect (cl-loop for i from 1 to 3000 collect i))
+  (let ((buffer-string (buffer-string)))
+    (should (cl-search "more" buffer-string))
+    (should (< (count-lines (point-min) (point-max)) 120)))
+  (inspector-quit))
+
+;; Char tables
+;; 
https://www.gnu.org/software/emacs/manual/html_node/elisp/Char_002dTable-Type.html
+(ert-deftest inspector-tests--inspect-char-table-test ()
+  (inspector-inspect ascii-case-table)
+  (let ((buffer-string (buffer-string)))
+    (should (cl-search "char-table" buffer-string))
+    (inspector-quit))
+
+  (inspector-inspect (make-display-table))
+  (let ((buffer-string (buffer-string)))
+    (should (cl-search "char-table" buffer-string))
+    (inspector-quit))
+
+  (inspector-inspect (standard-syntax-table))
+  (let ((buffer-string (buffer-string)))
+    (should (cl-search "char-table" buffer-string))
+    (inspector-quit)))
+
+(ert-deftest inspector-tests--inspect-bool-vector-test ()
+  (inspector-inspect (make-category-set "al"))
+  (let ((buffer-string (buffer-string)))
+    (should (cl-search "bool-vector" buffer-string))
+    (inspector-quit)))
+
+(ert-deftest inspector-tests--inspect-nil-test ()
+  (inspector-inspect nil)
+  (let ((buffer-string (buffer-string)))
+    (should (cl-search "nil" buffer-string))
+    (inspector-quit)))
+
+(ert-deftest inspector-tests--inspect-cons-test ()
+  (inspector-inspect (cons 1 2))
+  (let ((buffer-string (buffer-string)))
+    (should (cl-search "cons" buffer-string))
+    (should (cl-search "1" buffer-string))
+    (should (cl-search "2" buffer-string))
+    (inspector-quit)))
+
+(ert-deftest inspector-tests--inspect-alist-test ()
+  (inspector-inspect '((a . 33) (b . 44)))
+  (let ((buffer-string (buffer-string)))
+    (when inspector-use-specialized-inspectors-for-lists
+      (should (cl-search "association list" buffer-string)))
+    (should (cl-search "a" buffer-string))
+    (should (cl-search "b" buffer-string))
+    (should (cl-search "33" buffer-string))
+    (should (cl-search "44" buffer-string))
+    (inspector-quit)))
+
+(ert-deftest inspector-tests--inspect-plist-test ()
+  (inspector-inspect '(:a 33 :b 44))
+  (let ((buffer-string (buffer-string)))
+    (when inspector-use-specialized-inspectors-for-lists
+      (should (cl-search "property list" buffer-string)))
+    (should (cl-search "a" buffer-string))
+    (should (cl-search "b" buffer-string))
+    (should (cl-search "33" buffer-string))
+    (should (cl-search "44" buffer-string))
+    (inspector-quit))
+
+  (inspector-inspect '(a 33 b 44))
+  (let ((buffer-string (buffer-string)))
+    (when inspector-use-specialized-inspectors-for-lists
+      (should (cl-search "property list" buffer-string)))
+    (should (cl-search "a" buffer-string))
+    (should (cl-search "b" buffer-string))
+    (should (cl-search "33" buffer-string))
+    (should (cl-search "44" buffer-string))
+    (inspector-quit)))
+
+(ert-deftest inspector-tests--inspect-hash-table-test ()
+  (inspector-inspect (let ((table (make-hash-table)))
+                       (puthash :a 22 table)
+                       (puthash :b "foo" table)
+                       table))
+  (let ((buffer-string (buffer-string)))
+    (should (cl-search "hash-table" buffer-string))
+    (should (cl-search "a" buffer-string))
+    (should (cl-search "22" buffer-string))
+    (should (cl-search "b" buffer-string))
+    (should (cl-search "foo" buffer-string)))
+  (inspector-quit))
+
+(ert-deftest inspector-tests--inspect-function-test ()
+  (inspector-inspect (symbol-function 'car))
+  (let ((buffer-string (buffer-string)))
+    (should (cl-search "function" buffer-string))
+    (should (cl-search "car" buffer-string)))
+  (inspector-quit))
+
+(defun inspector-tests--factorial (integer)
+  "Compute factorial of INTEGER."
+  (if (= 1 integer) 1
+    (* integer (inspector-tests--factorial (1- integer)))))
+
+(ert-deftest inspector-tests--inspect-compiled-function-test ()
+  (inspector-inspect (byte-compile 'inspector-tests--factorial))
+  (let ((buffer-string (buffer-string)))
+    (should (cl-search "function" buffer-string)))
+  (inspector-quit))
+
+(ert-deftest inspector-tests--inspect-record-test ()
+  (inspector-inspect (record 'foo 23 [bar baz] "rats"))
+  (let ((buffer-string (buffer-string)))
+    (should (cl-search "record" buffer-string))
+    (should (cl-search "foo" buffer-string))
+    (should (cl-search "23" buffer-string))
+    (should (cl-search "rats" buffer-string)))
+  (inspector-quit))
+
+(ert-deftest inspector-tests--inspect-finalizer-test ()
+  (inspector-inspect (make-finalizer #'print)))
+
+(ert-deftest inspector-tests--overlays-test ()
+  (inspector-inspect (make-button 0 10))
+  (let ((buffer-string (buffer-string)))
+    (should (cl-search "overlay" buffer-string)))
+  (inspector-quit)
+  (inspector-inspect (make-overlay 0 10))
+  (let ((buffer-string (buffer-string)))
+    (should (cl-search "overlay" buffer-string)))
+  (inspector-quit))
+
+(defclass inspector-tests--person ()
+  ((name :initform "John")
+   (age :initform 40)))
+
+(ert-deftest inspector-tests--inspect-class-test ()
+  (inspector-inspect (make-instance 'inspector-tests--person))
+  (let ((buffer-string (buffer-string)))
+    (should (cl-search "name" buffer-string))
+    (should (cl-search "John" buffer-string))
+    (should (cl-search "age" buffer-string))
+    (should (cl-search "40" buffer-string))
+    (inspector-quit)))
+
+
+(cl-defstruct inspector-tests--rectangle
+  x y)
+
+(ert-deftest inspector-tests--inspect-struct-test ()
+  (inspector-inspect (make-inspector-tests--rectangle :x 30 :y 40))
+  (let ((buffer-string (buffer-string)))
+    (should (cl-search "x" buffer-string))
+    (should (cl-search "y" buffer-string))
+    (should (cl-search "30" buffer-string))
+    (should (cl-search "40" buffer-string))
+    (inspector-quit)))
+
+(ert-deftest inspector-tests--slices-test ()
+  (let ((inspector-slice-size 10))
+    (inspector-inspect (cl-loop for i from 1 to 400 collect i))
+    (should (< (count-lines (point-min) (point-max)) 20))
+    (inspector-quit))
+
+  (let ((inspector-slice-size 100))
+    (inspector-inspect (cl-loop for i from 1 to 400 collect (cons i (1+ i))))
+    (should (< (count-lines (point-min) (point-max)) 120))
+    (inspector-quit))
+
+  ;; property lists are not sliced for now ...
+  ;; (let ((inspector-slice-size 100))
+  ;;   (inspector-inspect (cl-loop for i from 1 to 400 collect (gensym) 
collect i))
+  ;;   (should (< (count-lines (point-min) (point-max)) 120))
+  ;;   (inspector-quit))
+
+  (let ((inspector-slice-size 100))
+    (inspector-inspect (apply #'vector (cl-loop for i from 1 to 1000 collect 
i)))
+    (should (< (count-lines (point-min) (point-max)) 120))
+    (inspector-quit)))
+
+(provide 'tree-inspector-tests)
+
+;;; tree-inspector-tests.el ends here
diff --git a/tree-inspector.el b/tree-inspector.el
index 11afcb948d..96b781771c 100644
--- a/tree-inspector.el
+++ b/tree-inspector.el
@@ -1,6 +1,6 @@
 ;; tree-inspector.el --- Inspector tool for Emacs Lisp object that uses a 
treeview  -*- lexical-binding: t; -*-
 
-;; Copyright (C) 2021-2022 Free Software Foundation, Inc.
+;; Copyright (C) 2022 Free Software Foundation, Inc.
 
 ;; Author: Mariano Montone <marianomontone@gmail.com>
 ;; URL: https://github.com/mmontone/emacs-inspector
@@ -335,6 +335,7 @@ in a format understood by `kbd'.  Commands a names of Lisp 
functions."
       (treeview-display-node (tree-inspector--make-node data))
       (setq buffer-read-only t)
       (local-set-key (kbd "q") #'kill-current-buffer)
-      (switch-to-buffer buffer))))
+      (switch-to-buffer buffer)
+      buffer)))
 
 (provide 'tree-inspector)



reply via email to

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