Skip to content

Commit 803a419

Browse files
arichiardibbatsov
authored andcommitted
Add test harness (finally?)
This patch add ert test harness and some tests around the inf-clojure-completion-bounds-of-expr-at-point function.
1 parent 94f440e commit 803a419

File tree

4 files changed

+154
-0
lines changed

4 files changed

+154
-0
lines changed

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*~
2+
*\#*\#
3+
*.\#*
4+
*.elc
5+
.cask
6+
elpa*
7+
.depend
8+
TAGS
9+
.DS_STORE
10+
dist
11+
.vagrant/
12+
.dir-locals?.el

.travis.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
language: generic
2+
sudo: false
3+
before_install:
4+
- curl -fsSkL https://gist.github.com/rejeep/ebcd57c3af83b049833b/raw > x.sh && source ./x.sh
5+
- evm install $EVM_EMACS --use --skip
6+
- cask
7+
env:
8+
- EVM_EMACS=emacs-24.3-travis
9+
- EVM_EMACS=emacs-24.4-travis
10+
- EVM_EMACS=emacs-24.5-travis
11+
- EVM_EMACS=emacs-25.1-travis
12+
- EVM_EMACS=emacs-25.2-travis
13+
- EVM_EMACS=emacs-25.3-travis
14+
script:
15+
- emacs --version
16+
- cask install
17+
- cask exec buttercup -L .

Cask

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(source gnu)
2+
(source melpa)
3+
4+
(package-file "inf-clojure.el")
5+
6+
(files "*.el" (:exclude ".dir-locals.el"))
7+
8+
(development
9+
(depends-on "clojure-mode")
10+
(depends-on "buttercup")
11+
(depends-on "assess"))

test/inf-clojure-tests.el

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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

Comments
 (0)