Skip to content

Commit f9758bc

Browse files
expezkommen
authored andcommitted
[Fix #310,#311] clojure-expected-ns with src/cljc
When the source path is src/clj{,c,s,x} instead of just src/ clojure-expected ns would create namespaces like clj.my-project.my-ns whereas what's wanted is my-project.my-ns. Reading boot.clj or project.clj to find out the user's src dirs is out of scope for clojure-mode, so we use the simply heuristic that no namespace should start with clj, cljc or cljs because these are the idiomatic source directories in multi-source projects. When improving clojure-expected-ns I extracted out two utilities, clojure-project-dir and clojure-project-relative-path. These utilities already exist in clj-refactor so I opted to make them public rather than private, as they are generally useful.
1 parent 289e683 commit f9758bc

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

clojure-mode-util-test.el

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
;;; clojure-mode-util-test.el --- Clojure Mode: util test suite -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2014-2015 Bozhidar Batsov <[email protected]>
4+
5+
;; This file is not part of GNU Emacs.
6+
7+
;; This program is free software; you can redistribute it and/or modify
8+
;; it under the terms of the GNU General Public License as published by
9+
;; the Free Software Foundation, either version 3 of the License, or
10+
;; (at your option) any later version.
11+
12+
;; This program is distributed in the hope that it will be useful,
13+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
;; GNU General Public License for more details.
16+
17+
;; You should have received a copy of the GNU General Public License
18+
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
20+
;;; Commentary:
21+
22+
;; The unit test suite of Clojure Mode
23+
24+
;;; Code:
25+
(require 'clojure-mode)
26+
(require 'cl-lib)
27+
(require 'ert)
28+
29+
(let ((project-dir "/home/user/projects/my-project/")
30+
(clj-file-path "/home/user/projects/my-project/src/clj/my_project/my_ns/my_file.clj")
31+
(project-relative-clj-file-path "src/clj/my_project/my_ns/my_file.clj")
32+
(clj-file-ns "my-project.my-ns.my-file"))
33+
34+
(ert-deftest project-relative-path ()
35+
:tags '(utils)
36+
(cl-letf (((symbol-function 'clojure-project-dir) (lambda () project-dir)))
37+
(should (string= (clojure-project-relative-path clj-file-path)
38+
project-relative-clj-file-path))))
39+
40+
(ert-deftest expected-ns ()
41+
:tags '(utils)
42+
(cl-letf (((symbol-function 'clojure-project-relative-path)
43+
(lambda (&optional current-buffer-file-name)
44+
project-relative-clj-file-path)))
45+
(should (string= (clojure-expected-ns clj-file-path) clj-file-ns)))))
46+
47+
(provide 'clojure-mode-util-test)
48+
49+
;; Local Variables:
50+
;; indent-tabs-mode: nil
51+
;; End:
52+
53+
;;; clojure-mode-util-test.el ends here

0 commit comments

Comments
 (0)