[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/cider 1dc2c80293 3/3: `cider-test`: don't render a newline
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/cider 1dc2c80293 3/3: `cider-test`: don't render a newline between expected and actual (#3375) |
Date: |
Fri, 4 Aug 2023 03:59:27 -0400 (EDT) |
branch: elpa/cider
commit 1dc2c80293877ce90bb954f2558aa494d411893e
Author: vemv <vemv@users.noreply.github.com>
Commit: GitHub <noreply@github.com>
`cider-test`: don't render a newline between expected and actual (#3375)
---
CHANGELOG.md | 1 +
cider-test.el | 13 ++++++++++++-
test/cider-test-tests.el | 37 +++++++++++++++++++++++++++++++++++++
3 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3238753fe4..098f033356 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,7 @@
- Bump the injected `cider-nrepl` to
[0.34](https://github.com/clojure-emacs/cider-nrepl/blob/v0.34.0/CHANGELOG.md#0340-2023-08-03).
- Improve `nrepl-dict` error reporting.
- Preserve the `:cljs-repl-type` more reliably.
+- [#3375](https://github.com/clojure-emacs/cider/pull/3375): `cider-test`:
don't render a newline between expected and actual, most times.
## 1.7.0 (2023-03-23)
diff --git a/cider-test.el b/cider-test.el
index ef57144169..7c083c3e20 100644
--- a/cider-test.el
+++ b/cider-test.el
@@ -400,6 +400,12 @@ With the actual value, the outermost '(not ...)'
s-expression is removed."
(cider-insert "t" 'font-lock-constant-face t))
(insert "\n\n"))))
+(defun cider-test--string-contains-newline (input-string)
+ "Returns whether INPUT-STRING contains an escaped newline."
+ (when (stringp input-string)
+ (and (string-match-p "\\n" input-string)
+ t)))
+
(defun cider-test-render-assertion (buffer test)
"Emit into BUFFER report detail for the TEST assertion."
(with-current-buffer buffer
@@ -427,12 +433,17 @@ With the actual value, the outermost '(not ...)'
s-expression is removed."
(when expected
(insert-label "expected")
(insert-rect expected)
- (insert "\n"))
+ ;; Only place a newline between expected and actual when the
values are deemed 'dense',
+ ;; otherwise favor compact output:
+ (when (or (cider-test--string-contains-newline expected)
+ (cider-test--string-contains-newline actual))
+ (insert "\n")))
(if diffs
(dolist (d diffs)
(cl-destructuring-bind (actual (removed added)) d
(insert-label "actual")
(insert-rect actual)
+ (insert "\n")
(insert-label "diff")
(insert "- ")
(insert-rect removed)
diff --git a/test/cider-test-tests.el b/test/cider-test-tests.el
new file mode 100644
index 0000000000..3531c67395
--- /dev/null
+++ b/test/cider-test-tests.el
@@ -0,0 +1,37 @@
+;;; cider-test-tests.el -*- lexical-binding: t; -*-
+
+;; Copyright © 2023 Bozhidar Batsov
+
+;; Author: Bozhidar Batsov <bozhidar@batsov.dev>
+
+;; This file is NOT part of GNU Emacs.
+
+;; 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:
+
+;; This file is part of CIDER
+
+;;; Code:
+
+(require 'buttercup)
+(require 'cider-test)
+
+(describe "cider-test--string-contains-newline"
+ (expect (cider-test--string-contains-newline "Hello\nWorld")
+ :to-equal
+ nil)
+ (expect (cider-test--string-contains-newline "Hello\\nWorld")
+ :to-equal
+ t))