[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/assess f3416dadb1 18/95: Indentation test functions.
From: |
ELPA Syncer |
Subject: |
[elpa] externals/assess f3416dadb1 18/95: Indentation test functions. |
Date: |
Tue, 19 Jul 2022 15:57:29 -0400 (EDT) |
branch: externals/assess
commit f3416dadb11f87a723f5efefec2fdd46cf2ab830
Author: Phillip Lord <phillip.lord@russet.org.uk>
Commit: Phillip Lord <phillip.lord@russet.org.uk>
Indentation test functions.
---
sisyphus.el | 126 ++++++++++++++++++++++++++++++++++----------------
test/sisyphus-test.el | 38 ++++++++++++++-
2 files changed, 121 insertions(+), 43 deletions(-)
diff --git a/sisyphus.el b/sisyphus.el
index 60b84be10a..ec61515286 100644
--- a/sisyphus.el
+++ b/sisyphus.el
@@ -48,6 +48,7 @@
(require 'pp)
(require 'ert)
(require 'm-buffer-at)
+(require 'm-buffer)
(require 'dash)
;; #+end_src
@@ -107,8 +108,12 @@
;; error condition
(_ (error "Type not recognised"))))
+(defun sisyphus-buffer (b)
+ "Add type data to the string B marking it as a buffer."
+ `(:buffer b))
+
(defun sisyphus-file (f)
- "Add type data to F marking it as a file."
+ "Add type data to the string F marking it as a file."
`(:file ,f))
;; #+end_src
@@ -126,43 +131,42 @@ print any messages!"
(defun sisyphus--explainer-diff-string= (a b)
"Compare strings using diff output."
- (let* ((diff
- (executable-find "diff"))
- (a-buffer
- (generate-new-buffer "a"))
- (b-buffer
- (generate-new-buffer "b"))
- (a-file
- (make-temp-file
- (buffer-name a-buffer)))
- (b-file
- (make-temp-file
- (buffer-name b-buffer))))
- (with-current-buffer
- a-buffer
- (insert a)
- (sisyphus--write-file-silently a-file))
- (with-current-buffer
- b-buffer
- (insert b)
- (sisyphus--write-file-silently b-file))
- (prog1
- (format "Strings:\n%s\nand\n%s\nDiffer at:%s\n"
- a b
- (with-temp-buffer
- (call-process
- diff
- ;; no infile
- nil
- ;; dump to current buffer
- t
- nil
- "-c"
- a-file
- b-file)
- (buffer-string)))
- (kill-buffer a-buffer)
- (kill-buffer b-buffer))))
+ (sisyphus-with-preserved-buffer-list
+ (let* ((diff
+ (executable-find "diff"))
+ (a-buffer
+ (generate-new-buffer "a"))
+ (b-buffer
+ (generate-new-buffer "b"))
+ (a-file
+ (make-temp-file
+ (buffer-name a-buffer)))
+ (b-file
+ (make-temp-file
+ (buffer-name b-buffer))))
+ (with-current-buffer
+ a-buffer
+ (insert a)
+ (sisyphus--write-file-silently a-file))
+ (with-current-buffer
+ b-buffer
+ (insert b)
+ (sisyphus--write-file-silently b-file))
+ (prog1
+ (format "Strings:\n%s\nand\n%s\nDiffer at:%s\n"
+ a b
+ (with-temp-buffer
+ (call-process
+ diff
+ ;; no infile
+ nil
+ ;; dump to current buffer
+ t
+ nil
+ "-c"
+ a-file
+ b-file)
+ (buffer-string)))))))
(defun sisyphus--explainer-simple-string= (a b)
"Compare strings for first difference."
@@ -198,9 +202,6 @@ See `sisyphus=' for more information."
;; ** create buffers
-
-
-
(defmacro sisyphus-with-preserved-buffer-list (&rest body)
"Evaluate BODY, but delete any buffers that have been created."
(declare (debug t))
@@ -249,6 +250,49 @@ killed at the end of the form."
;; ** Indentation functions
+;; This is largely a re--implementation of `indent-region' but without the
+;; noise.
+(defun sisyphus--indent-buffer ()
+ (cond
+ ;; if indent-region-function is set, use it, and hope that it is not
+ ;; noisy.
+ (indent-region-function
+ (funcall indent-region-function (point-min) (point-max)))
+ (t
+ (-map
+ (lambda (m)
+ (goto-char m)
+ (indent-according-to-mode))
+ (m-buffer-match-line-start (current-buffer))))))
+
+(defun sisyphus--indent-in-mode (mode unindented)
+ (with-temp-buffer
+ (insert
+ (sisyphus-to-string unindented))
+ (funcall mode)
+ (sisyphus--indent-buffer)
+ (buffer-string)))
+
+(defun sisyphus-indentation= (mode unindented indented)
+ "Return non-nil if UNINDENTED indents in MODE to INDENTED.
+Both UNINDENTED and INDENTED can be any value usable by
+`sisyphus-to-string'. Indentation is performed using
+`indent-region'."
+ (sisyphus=
+ (sisyphus--indent-in-mode
+ mode
+ unindented)
+ indented))
+
+(defun sisyphus-explain-indentation= (mode unindented indented)
+ (sisyphus-explain=
+ (sisyphus--indent-in-mode
+ mode
+ unindented)
+ indented))
+
+(put 'sisyphus-indentation= 'ert-explainer 'sisyphus-explain-indentation=)
+
;; Set mode, indent normally, then compare
;; ** Font-lock support functions
diff --git a/test/sisyphus-test.el b/test/sisyphus-test.el
index 75611eb165..e65b9fa99e 100644
--- a/test/sisyphus-test.el
+++ b/test/sisyphus-test.el
@@ -154,8 +154,6 @@ This also tests the advice on string=."
(sisyphus=
a b)))))))
-
-
(ert-deftest file-string= ()
(should
(sisyphus=
@@ -221,3 +219,39 @@ This also tests the advice on string=."
(progn
(sisyphus-with-temp-buffers (a b))
(length (buffer-list))))))
+
+(ert-deftest sisyphus--test-indent-in-mode ()
+ (should
+ (sisyphus=
+ "(
+ (
+ (
+ (
+ ))))"
+ (sisyphus--indent-in-mode
+ 'emacs-lisp-mode
+ "(\n(\n(\n(\n))))"))))
+
+(ert-deftest sisyphus--test-indentation= ()
+ (should
+ (sisyphus-indentation=
+ 'emacs-lisp-mode
+ "(\n(\n(\n(\n))))"
+ "(
+ (
+ (
+ (
+ ))))"))
+ (should-not
+ (sisyphus-indentation=
+ 'emacs-lisp-mode
+ "hello"
+ "goodbye"))
+ (should
+ (sisyphus-test--explanation
+ (lambda ()
+ (should
+ (sisyphus-indentation=
+ 'emacs-lisp-mode
+ "hello"
+ "goodbye"))))))
- [elpa] externals/assess c0bdc94e49 41/95: Remove erroneous debug statement., (continued)
- [elpa] externals/assess c0bdc94e49 41/95: Remove erroneous debug statement., ELPA Syncer, 2022/07/19
- [elpa] externals/assess 2db9834e4e 44/95: Rework Makefile for update to cask, ELPA Syncer, 2022/07/19
- [elpa] externals/assess e820ccf163 05/95: Emacs 24.4 or later., ELPA Syncer, 2022/07/19
- [elpa] externals/assess 3f89d8601f 15/95: Port tests to sisyphus with-temp-buffers., ELPA Syncer, 2022/07/19
- [elpa] externals/assess acb460e26c 16/95: All git-snapshot., ELPA Syncer, 2022/07/19
- [elpa] externals/assess 2e42c93191 06/95: Remove debug statement., ELPA Syncer, 2022/07/19
- [elpa] externals/assess eb56d9627d 07/95: String diff file save is now silent., ELPA Syncer, 2022/07/19
- [elpa] externals/assess a459abe966 11/95: New macro `sisyphus-with-preserved-buffer-list'., ELPA Syncer, 2022/07/19
- [elpa] externals/assess 33b6c3c390 12/95: New macro `sisyphus-with-temp-buffers'., ELPA Syncer, 2022/07/19
- [elpa] externals/assess 890906bfcb 17/95: Interface written as single overloaded function., ELPA Syncer, 2022/07/19
- [elpa] externals/assess f3416dadb1 18/95: Indentation test functions.,
ELPA Syncer <=
- [elpa] externals/assess 1b01542ccd 20/95: Fontification testing., ELPA Syncer, 2022/07/19
- [elpa] externals/assess 2e556a62ae 22/95: Add new test file., ELPA Syncer, 2022/07/19
- [elpa] externals/assess 32a00524a8 24/95: Fix unused variable issues, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 3cf57afcaf 26/95: Merge pull request #1 from syohex/fix, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 00c794a516 29/95: Add package support., ELPA Syncer, 2022/07/19
- [elpa] externals/assess f490f18a18 32/95: Merge branch 'master' of github.com:phillord/sisyphus, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 0d079db1a7 34/95: Completed documentation., ELPA Syncer, 2022/07/19
- [elpa] externals/assess cab9fea7b8 28/95: Documentation for everything, ELPA Syncer, 2022/07/19
- [elpa] externals/assess f521db4101 36/95: Add sisyphus-discover, ELPA Syncer, 2022/07/19
- [elpa] externals/assess 46290f163d 37/95: Add tests for discover., ELPA Syncer, 2022/07/19