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

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

[elpa] externals/objed 58af659 068/216: Start adding tests


From: Stefan Monnier
Subject: [elpa] externals/objed 58af659 068/216: Start adding tests
Date: Tue, 8 Jan 2019 12:29:13 -0500 (EST)

branch: externals/objed
commit 58af659445bbcdd61b89b8bef5b33498b3bead1d
Author: Clemera <address@hidden>
Commit: Clemera <address@hidden>

    Start adding tests
---
 .gitignore           |   2 +
 Makefile             |  13 +++++
 test/elpa.el         |   4 ++
 test/make-compile.el |   8 +++
 test/make-test.el    |  14 +++++
 test/make-update.el  |  28 ++++++++++
 test/tests.el        | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 211 insertions(+)

diff --git a/.gitignore b/.gitignore
index 1c17549..97632b4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
 # Compiled
 *.elc
+# deps
+.elpa/
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..9cbb963
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,13 @@
+update:
+       emacs -batch -l test/make-update.el
+
+compile: clean
+       emacs -batch -l test/elpa.el -l test/make-compile.el
+
+test:
+       emacs -batch -l test/elpa.el -l test/make-test.el
+
+clean:
+       rm -f *.elc
+
+.PHONY: update compile test clean
diff --git a/test/elpa.el b/test/elpa.el
new file mode 100644
index 0000000..f501af1
--- /dev/null
+++ b/test/elpa.el
@@ -0,0 +1,4 @@
+(setq package-user-dir
+      (expand-file-name (format ".elpa/%s/elpa" emacs-version)))
+(package-initialize)
+(add-to-list 'load-path default-directory)
diff --git a/test/make-compile.el b/test/make-compile.el
new file mode 100644
index 0000000..6f876b6
--- /dev/null
+++ b/test/make-compile.el
@@ -0,0 +1,8 @@
+;;  bail out on compilation warnings and errors
+(setq byte-compile-error-on-warn t)
+(setq byte-compile--use-old-handlers nil)
+
+;; compile *.el files
+(dolist (file (file-expand-wildcards "*.el"))
+  (unless (byte-compile-file file)
+    (kill-emacs 1)))
diff --git a/test/make-test.el b/test/make-test.el
new file mode 100644
index 0000000..34751c5
--- /dev/null
+++ b/test/make-test.el
@@ -0,0 +1,14 @@
+(let* ((project-tests-file "tests.el")
+       (current-directory (file-name-directory load-file-name))
+       (project-test-path (expand-file-name "." current-directory))
+       (project-root-path (expand-file-name ".." current-directory)))
+
+  ;; add the package being tested to 'load-path so it can be 'require-d
+  (add-to-list 'load-path project-root-path)
+  (add-to-list 'load-path project-test-path)
+
+  ;; load the file with tests
+  (load (expand-file-name project-tests-file project-test-path))
+
+  ;; run the tests
+  (ert-run-tests-batch-and-exit))
diff --git a/test/make-update.el b/test/make-update.el
new file mode 100644
index 0000000..bbc6094
--- /dev/null
+++ b/test/make-update.el
@@ -0,0 +1,28 @@
+;; list of the all the dependencies, including the dev dependencies
+(defvar dev-packages '())
+
+;; initialize package.el
+(setq package-user-dir
+      (expand-file-name (format ".elpa/%s/elpa" emacs-version)))
+(message "installing in %s ...\n" package-user-dir)
+(package-initialize)
+(setq package-archives
+      '(("melpa" . "http://melpa.org/packages/";)
+        ("gnu" . "http://elpa.gnu.org/packages/";)))
+(package-refresh-contents)
+
+;; install dependencies
+(dolist (package dev-packages)
+  (unless (package-installed-p package)
+    (ignore-errors
+      (package-install package))))
+
+;; upgrade dependencies
+(save-window-excursion
+  (package-list-packages t)
+  (condition-case nil
+      (progn
+        (package-menu-mark-upgrades)
+        (package-menu-execute t))
+    (error
+     (message "All packages up to date"))))
diff --git a/test/tests.el b/test/tests.el
new file mode 100644
index 0000000..9d55f1d
--- /dev/null
+++ b/test/tests.el
@@ -0,0 +1,142 @@
+(require 'ert)
+(require 'objed)
+(require 'objed-objects)
+(require 'cl-lib)
+
+
+;; from `lispy-with'
+
+
+(defun objed-decode-keysequence (str)
+  "Decode STR from e.g. \"23ab5c\" to '(23 \"a\" \"b\" 5 \"c\")"
+  (let ((table (copy-sequence (syntax-table))))
+    (cl-loop for i from ?0 to ?9 do
+             (modify-syntax-entry i "." table))
+    (cl-loop for i from ? to ? do
+             (modify-syntax-entry i "w" table))
+    (cl-loop for i in '(? ?\( ?\) ?\[ ?\] ?{ ?} ?\" ?\' ?\ )
+             do (modify-syntax-entry i "w" table))
+    (cl-mapcan (lambda (x)
+                 (let ((y (ignore-errors (read x))))
+                   (if (numberp y)
+                       (list y)
+                     (mapcar #'string x))))
+               (with-syntax-table table
+                 (split-string str "\\b" t)))))
+
+(defun objed-unalias (seq)
+  "Emulate pressing keys decoded from SEQ."
+  (if (vectorp seq)
+      (objed--unalias-key seq)
+    (let ((lkeys (objed-decode-keysequence seq))
+          key)
+      (while (setq key (pop lkeys))
+        (if (numberp key)
+            (let ((current-prefix-arg (list key)))
+              (when lkeys
+                (objed--unalias-key (pop lkeys))))
+          (objed--unalias-key key))))))
+
+(defun objed--unalias-key (key)
+    "Call command that corresponds to KEY.
+Insert KEY if there's no command."
+    (let ((cmd (key-binding key)))
+      (if (not cmd)
+          (insert key)
+        (setq last-command-event (aref key 0))
+        (call-interactively cmd)
+        (setq last-command cmd))))
+
+
+(ert-deftest objed-decode-keysequence ()
+  (should (equal (objed-decode-keysequence "23ab50c")
+                 '(23 "a" "b" 50 "c")))
+  (should (equal (objed-decode-keysequence "3\C-d")
+                 '(3 "")))
+  (should (equal (objed-decode-keysequence "3\C-?")
+                 '(3 ""))))
+
+;; adapated from `lispy-with'
+(defmacro objed-with (in &rest body)
+  `(let ((temp-buffer (generate-new-buffer " *temp*")))
+     (save-window-excursion
+       (unwind-protect
+           (progn
+             (switch-to-buffer temp-buffer)
+             (emacs-lisp-mode)
+             (transient-mark-mode 1)
+             ;; activate objed
+             (objed-mode 1)
+             (set-transient-map objed-map #'objed--keep-transient-p)
+             (insert ,in)
+             (goto-char (point-min))
+             (when (search-forward "~" nil t)
+               (backward-delete-char 1)
+               (set-mark (point)))
+             (goto-char (point-max))
+             (search-backward "|")
+             (delete-char 1)
+             (objed--init 'char)
+             (setq current-prefix-arg nil)
+             ;; execute command
+             ,@(mapcar (lambda (x)
+                         (cond ((equal x '(kbd "C-u"))
+                                `(setq current-prefix-arg (list 4)))
+                               ((or (stringp x)
+                                    (and (listp x)
+                                         (eq (car x) 'kbd)))
+                                `(objed-unalias ,x))
+                               (t x)))
+                       body)
+             (let ((npos (point-marker)))
+               (when objed--current-obj
+                 (goto-char (objed--end))
+                 (insert ">")
+                 (goto-char (objed--beg))
+                 (insert "<"))
+               (goto-char npos)
+               (skip-chars-backward "<" (1- (point)))
+               (skip-chars-forward ">" (1+ (point)))
+               (insert "|")
+               (when (region-active-p)
+                 (exchange-point-and-mark)
+                 (insert "~")))
+             (buffer-substring-no-properties
+              (point-min)
+              (point-max)))
+         (objed--exit-objed)
+         (and (buffer-name temp-buffer)
+              (kill-buffer temp-buffer))))))
+
+
+(ert-deftest objed-next-line ()
+  (should (string= (objed-with ";; this is a| test\n;; this is the next line" 
"n")
+                   ";; this is a test\n<;; this is t|he next line>")))
+
+(ert-deftest objed-previous-line ()
+  (should (string= (objed-with ";; this is the previous line\n;; this is| the 
current line" "p")
+                   "<;; this is| the previous line\n>;; this is the current 
line")))
+
+(ert-deftest objed-forward-char ()
+  (should (string= (objed-with "Tes|ting line" "fff")
+                   "Testin|<g> line")))
+
+(ert-deftest objed-backward-char ()
+  (should (string= (objed-with "Tes|ting line" "bb")
+                   "T|<e>sting line")))
+
+(ert-deftest objed-forward-word ()
+  (should (string= (objed-with "Tes|ting line here" "ss")
+                   "Testing <line>| here")))
+
+
+(ert-deftest objed-backward-word ()
+  (should (string= (objed-with "Testing line he|re" "rr")
+                   "Testing |<line> here")))
+
+(ert-deftest objed-basic-movment ()
+  (should (string= (objed-with "Testing |line here\nFollowing line here" 
"npsrfb")
+                   "Testing |<l>ine here\nFollowing line here")))
+
+
+(provide 'tests)



reply via email to

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