Skip to content

Commit

Permalink
Add cider-docstring-tests.el
Browse files Browse the repository at this point in the history
  • Loading branch information
vemv committed Sep 23, 2023
1 parent c030370 commit 6e74eca
Show file tree
Hide file tree
Showing 8 changed files with 8,484 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cider-completion-context.el
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ the current symbol at point."
(_ (beginning-of-defun-raw))
(expr-start (point))
(_ (if (derived-mode-p 'cider-repl-mode)
(end-of-buffer)
(goto-char (point-max))
(end-of-defun)))
(expr-end (point)))
(string-remove-suffix "\n"
Expand Down
2 changes: 1 addition & 1 deletion cider-util.el
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ instead."
(save-excursion
(save-match-data
(if (derived-mode-p 'cider-repl-mode)
(end-of-buffer) ;; in repls, end-of-defun won't work, so we perform the closest reasonable thing
(goto-char (point-max)) ;; in repls, end-of-defun won't work, so we perform the closest reasonable thing
(end-of-defun))
(let ((end (point)))
(clojure-backward-logical-sexp 1)
Expand Down
2 changes: 1 addition & 1 deletion doc/modules/ROOT/pages/usage/code_completion.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ you can add this to your config:
(global-set-key (kbd "TAB") #'company-indent-or-complete-common)
----

Company's documention mechanism and CIDER's documentation facilities are integrated.
Company's documentation mechanism and CIDER's documentation facilities are integrated.

While a completion is being offered to you, you can hit (kbd:[F1])
(the default `company-show-doc-buffer` key binding) for displaying documentation
Expand Down
2,282 changes: 2,282 additions & 0 deletions test/File.edn

Large diffs are not rendered by default.

560 changes: 560 additions & 0 deletions test/Object.edn

Large diffs are not rendered by default.

3,812 changes: 3,812 additions & 0 deletions test/String.edn

Large diffs are not rendered by default.

1,749 changes: 1,749 additions & 0 deletions test/Thread.edn

Large diffs are not rendered by default.

78 changes: 78 additions & 0 deletions test/cider-docstring-tests.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
;; -*- lexical-binding: t; -*-
;;; cider-docstring-tests.el

;; Copyright © 2012-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-docstring)

;; Please, for each `describe', ensure there's an `it' block, so that its execution is visible in CI.

(defun cider-render-docstring-test--convert-fragments (fs)
(mapcar (lambda (x)
(nrepl-dict "type" (gethash :type x)
"content" (gethash :content x)))
fs))

(describe "cider--render-docstring"
(it "A large corpus of fragments (as produced by Orchard) can be rendered using `shr' without raising errors"
(dolist (class '("Thread" "Object" "File" "String"))
(let* ((filename (concat default-directory
"test/"
class
".edn"))
(_ (assert (file-exists-p filename) t))
(class-contents (with-temp-buffer
(insert-file-contents filename)
(parseedn-read-str (buffer-string)))))
(assert (> (length class-contents) 0)
t)
(dotimes (i (length class-contents))
(let* ((member (aref class-contents i)))
(assert (> (hash-table-count member) 0)
t)
(gethash :doc-fragments member)
(let* ((doc-first-sentence-fragments (cider-render-docstring-test--convert-fragments
(gethash :doc-first-sentence-fragments member)))
(eldoc-info (list "doc-fragments" (cider-render-docstring-test--convert-fragments
(gethash :doc-fragments member))
"doc-first-sentence-fragments" doc-first-sentence-fragments
"doc-block-tags-fragments" (cider-render-docstring-test--convert-fragments
(gethash :doc-block-tags-fragments member))))
(result (cider--render-docstring eldoc-info)))
(assert (stringp result) t (prin1-to-string eldoc-info))
(expect (stringp result)
:to-be-truthy)
(expect (> (length result) 0)
:to-be-truthy)
(when (> (length doc-first-sentence-fragments)
0)
(let ((result (cider--render-docstring (list "doc-first-sentence-fragments" doc-first-sentence-fragments))))
(assert (stringp result) t (prin1-to-string doc-first-sentence-fragments))
(expect (stringp result)
:to-be-truthy)
(expect (> (length result) 0)
:to-be-truthy))))))))))

0 comments on commit 6e74eca

Please sign in to comment.