|
| 1 | +;;; inf-clojure-tests.el --- Tests for Inf-Clojure -*- lexical-binding: t; -*- |
| 2 | +;; |
| 3 | +;; Copyright © 2014-2018 Bozhidar Batsov |
| 4 | + |
| 5 | +;; Authors: Bozhidar Batsov <bozhidar@batsov.com> |
| 6 | +;; Andrea Richiardi <a.richiardi.work@gmail.com> |
| 7 | +;; URL: http://github.com/clojure-emacs/inf-clojure |
| 8 | +;; Keywords: processes, clojure |
| 9 | +;; Package-Requires: ((emacs "24.4") (clojure-mode "5.3")) |
| 10 | + |
| 11 | +;; This file is part of GNU Emacs. |
| 12 | + |
| 13 | +;; GNU Emacs is free software: you can redistribute it and/or modify |
| 14 | +;; it under the terms of the GNU General Public License as published by |
| 15 | +;; the Free Software Foundation, either version 3 of the License, or |
| 16 | +;; (at your option) any later version. |
| 17 | + |
| 18 | +;; GNU Emacs is distributed in the hope that it will be useful, |
| 19 | +;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | +;; GNU General Public License for more details. |
| 22 | + |
| 23 | +;; You should have received a copy of the GNU General Public License |
| 24 | +;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
| 25 | + |
| 26 | +;;; Commentary: |
| 27 | +;; |
| 28 | +;; Code completion using alexander-yakushev/compliment. |
| 29 | + |
| 30 | +;;; Code: |
| 31 | + |
| 32 | +;; Tests for inf-clojure.el |
| 33 | + |
| 34 | +(message "Running tests on Emacs %s" emacs-version) |
| 35 | + |
| 36 | +(require 'buttercup) |
| 37 | +(require 'assess) |
| 38 | +(require 'inf-clojure) |
| 39 | + |
| 40 | +(cl-defmacro ict-with-assess-buffers ((&rest varlist) &body body) |
| 41 | + `(assess-with-temp-buffers (,@varlist) |
| 42 | + (clojure-mode) |
| 43 | + (inf-clojure-minor-mode) |
| 44 | + ,@body)) |
| 45 | + |
| 46 | +(defun ict-bounds-string (bounds) |
| 47 | + (buffer-substring (car bounds) (cdr bounds))) |
| 48 | + |
| 49 | +(describe "inf-clojure--kw-to-symbol" |
| 50 | + (it "returns symbol form of the given keyword" |
| 51 | + (expect (inf-clojure--kw-to-symbol "symbol") :to-equal "symbol") |
| 52 | + (expect (inf-clojure--kw-to-symbol ":clj.core/str") :to-equal "clj.core/str") |
| 53 | + (expect (inf-clojure--kw-to-symbol "::keyword") :to-equal "keyword") |
| 54 | + (expect (inf-clojure--kw-to-symbol nil) :to-equal nil))) |
| 55 | + |
| 56 | +(describe "completion bounds at point" () |
| 57 | + (it "computes bounds for plain-text" |
| 58 | + (ict-with-assess-buffers |
| 59 | + ((a (insert "plain-text"))) |
| 60 | + (with-current-buffer a |
| 61 | + (expect (ict-bounds-string (inf-clojure-completion-bounds-of-expr-at-point)) |
| 62 | + :to-equal "plain-text")))) |
| 63 | + |
| 64 | + (it "computes bounds for @deref" |
| 65 | + (ict-with-assess-buffers |
| 66 | + ((a (insert "@deref"))) |
| 67 | + (with-current-buffer a |
| 68 | + (expect (ict-bounds-string (inf-clojure-completion-bounds-of-expr-at-point)) |
| 69 | + :to-equal "deref")))) |
| 70 | + |
| 71 | + (it "computes bounds for ^:keyword" |
| 72 | + (ict-with-assess-buffers |
| 73 | + ((a (insert "^:keyword"))) |
| 74 | + (with-current-buffer a |
| 75 | + (expect (ict-bounds-string (inf-clojure-completion-bounds-of-expr-at-point)) |
| 76 | + :to-equal ":keyword")))) |
| 77 | + |
| 78 | + (it "computes bounds for ::keyword" |
| 79 | + (ict-with-assess-buffers |
| 80 | + ((a (insert "::keyword"))) |
| 81 | + (with-current-buffer a |
| 82 | + (expect (ict-bounds-string (inf-clojure-completion-bounds-of-expr-at-point)) |
| 83 | + :to-equal "::keyword")))) |
| 84 | + |
| 85 | + (it "computes bounds for [^:keyword (combined break chars and keyword)" |
| 86 | + (ict-with-assess-buffers |
| 87 | + ((a (insert "[^:keyword"))) |
| 88 | + (with-current-buffer a |
| 89 | + (expect (ict-bounds-string (inf-clojure-completion-bounds-of-expr-at-point)) |
| 90 | + :to-equal ":keyword")))) |
| 91 | + |
| 92 | + (it "computes no bounds for point directly after a break expression" |
| 93 | + (ict-with-assess-buffers |
| 94 | + ((a (insert "@"))) |
| 95 | + (with-current-buffer a |
| 96 | + (expect |
| 97 | + (ict-bounds-string (inf-clojure-completion-bounds-of-expr-at-point)) |
| 98 | + :not :to-be nil)))) |
| 99 | + |
| 100 | + (it "computes bounds for [symbol" |
| 101 | + (ict-with-assess-buffers |
| 102 | + ((a (insert "[symbol"))) |
| 103 | + (with-current-buffer a |
| 104 | + (expect (ict-bounds-string (inf-clojure-completion-bounds-of-expr-at-point)) |
| 105 | + :to-equal "symbol")))) |
| 106 | + |
| 107 | + (it "computes bounds for (@deref (multiple break chars)" |
| 108 | + (ict-with-assess-buffers |
| 109 | + ((a (insert "(@deref"))) |
| 110 | + (with-current-buffer a |
| 111 | + (expect (ict-bounds-string (inf-clojure-completion-bounds-of-expr-at-point)) |
| 112 | + :to-equal "deref"))))) |
| 113 | + |
| 114 | +;;; inf-clojure-tests.el ends here |
0 commit comments