Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
vemv committed Aug 4, 2023
1 parent 154f050 commit c23b452
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
16 changes: 12 additions & 4 deletions cider-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,14 @@ 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 a newline.
Ignores any newlines at the end of the string."
(when (stringp input-string)
(let ((trimmed-string (replace-regexp-in-string "\n\\'" "" input-string)))
(and (string-match-p "\n" trimmed-string)
t))))

(defun cider-test-render-assertion (buffer test)
"Emit into BUFFER report detail for the TEST assertion."
(with-current-buffer buffer
Expand Down Expand Up @@ -427,10 +435,10 @@ With the actual value, the outermost '(not ...)' s-expression is removed."
(when expected
(insert-label "expected")
(insert-rect expected)
;; insert a newline between expected and actual only when both values are large enough
;; to justify the readability improvement.
;; our heuristic for a 'large enough' object is the presence of diffs:
(when diffs
;; 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)
Expand Down
43 changes: 43 additions & 0 deletions test/cider-test-tests.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
;;; 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 World")
:to-equal
nil)
(expect (cider-test--string-contains-newline "Hello World\n")
:to-equal
nil)
(expect (cider-test--string-contains-newline "Hello\nWorld")
:to-equal
t)
(expect (cider-test--string-contains-newline "Hello\nWorld\n")
:to-equal
t))

0 comments on commit c23b452

Please sign in to comment.