|
4 | 4 | [clojure.string :as str]
|
5 | 5 | [clojure.test :refer [deftest is testing]]
|
6 | 6 | [orchard.misc :as misc]
|
7 |
| - [orchard.namespace :as n])) |
| 7 | + [orchard.namespace :as sut])) |
8 | 8 |
|
9 | 9 | (deftest project-namespaces-test
|
10 |
| - (is (contains? (into #{} (n/project-namespaces)) |
| 10 | + (is (contains? (into #{} (sut/project-namespaces)) |
11 | 11 | 'orchard.namespace)))
|
12 | 12 |
|
13 | 13 | (deftest loaded-namespaces-test
|
14 | 14 | ;; If we don't pass the second arg, some cider ns will be returned
|
15 |
| - (is (some #(re-find #".*orchard" %) (n/loaded-namespaces))) |
| 15 | + (is (some #(re-find #".*orchard" %) (sut/loaded-namespaces))) |
16 | 16 | ;; Shouldn't return any orchard namespaces
|
17 | 17 | (is (not-any? #(re-find #".*orchard" %)
|
18 |
| - (n/loaded-namespaces [".*orchard"])))) |
| 18 | + (sut/loaded-namespaces [".*orchard"])))) |
19 | 19 |
|
20 | 20 | (defn- change-case
|
21 | 21 | "Utility fn to change the case of a URL path, to help with case sensitivity
|
|
28 | 28 | (if (= string lower) upper lower))))
|
29 | 29 |
|
30 | 30 | (deftest project-nses-ignore-case-on-windows-test
|
31 |
| - (let [orig-project-root n/project-root] |
| 31 | + (let [orig-project-root sut/project-root] |
32 | 32 | (testing "Project nses is case sensitive on non Windows oses"
|
33 | 33 | (with-redefs [misc/os-windows? (constantly false)
|
34 |
| - n/project-root (change-case orig-project-root)] |
35 |
| - (is (not (seq (n/project-namespaces)))))) |
| 34 | + sut/project-root (change-case orig-project-root)] |
| 35 | + (is (not (seq (sut/project-namespaces)))))) |
36 | 36 | (testing "Project nses ignore cases on Windows oses"
|
37 | 37 | (with-redefs [misc/os-windows? (constantly true)
|
38 |
| - n/project-root (change-case orig-project-root)] |
39 |
| - (is (seq (n/project-namespaces))))))) |
| 38 | + sut/project-root (change-case orig-project-root)] |
| 39 | + (is (seq (sut/project-namespaces))))))) |
40 | 40 |
|
41 | 41 | (deftest has-tests-errors
|
42 |
| - (is (n/has-tests? (find-ns 'orchard.namespace-test)))) |
| 42 | + (is (sut/has-tests? (find-ns 'orchard.namespace-test)))) |
43 | 43 |
|
44 |
| -(deftest namespace-parsing |
| 44 | +(deftest read-namespace-test |
45 | 45 | (testing "Namespace parsing"
|
46 | 46 | (let [url (-> (System/getProperty "java.io.tmpdir")
|
47 | 47 | (io/file "orchard.namespace-test.txt")
|
48 | 48 | (io/as-url))
|
49 | 49 | uri (.toURI url)]
|
50 | 50 | (testing "of an empty file"
|
51 | 51 | (spit url "")
|
52 |
| - (is (nil? (n/read-namespace uri)))) |
| 52 | + (is (nil? (sut/read-namespace uri)))) |
53 | 53 | (testing "of an unparsable file"
|
54 | 54 | (spit url "(]$@(")
|
55 |
| - (is (nil? (n/read-namespace uri)))) |
| 55 | + (is (nil? (sut/read-namespace uri)))) |
56 | 56 | (testing "of non-list tokens"
|
57 | 57 | (spit url "these are (still) tokens")
|
58 |
| - (is (nil? (n/read-namespace uri)))) |
| 58 | + (is (nil? (sut/read-namespace uri)))) |
59 | 59 | (testing "when tokens precede the ns form"
|
60 | 60 | (spit url "there [is a] (ns here) after all")
|
61 |
| - (is (= (n/read-namespace uri) 'here))) |
| 61 | + (is (= 'here (sut/read-namespace uri)))) |
62 | 62 | (testing "when multiple ns forms are present"
|
63 | 63 | (spit url "(ns ns1) (ns ns2) (ns ns3)")
|
64 |
| - (is (= (n/read-namespace uri) 'ns1))) |
| 64 | + (is (= 'ns1 (sut/read-namespace uri)))) |
65 | 65 | (testing "of top-level forms only"
|
66 | 66 | (spit url "(comment (ns ns1)) (ns ns2) (ns ns3)")
|
67 |
| - (is (= (n/read-namespace uri) 'ns2))) |
| 67 | + (is (= 'ns2 (sut/read-namespace uri)))) |
| 68 | + (testing "of namespace with read conditionals in its `ns` form" |
| 69 | + (is (= 'orchard.test-ns (-> "orchard/test_ns.cljc" |
| 70 | + io/resource |
| 71 | + io/as-url |
| 72 | + sut/read-namespace)))) |
68 | 73 | (io/delete-file url))))
|
69 | 74 |
|
70 | 75 | (deftest namespace-resolution
|
|
76 | 81 | orchard.namespace
|
77 | 82 | orchard.cljs.test-canonical-source]]
|
78 | 83 | (testing "namespace symbols to source files"
|
79 |
| - (is (every? identity (map n/canonical-source nses)))) |
| 84 | + (is (every? identity (map sut/canonical-source nses)))) |
80 | 85 | (testing "source files to namespace symbols"
|
81 |
| - (is (= nses (map (comp n/read-namespace ; src -> ns |
82 |
| - n/canonical-source) ; ns -> src |
| 86 | + (is (= nses (map (comp sut/read-namespace ; src -> ns |
| 87 | + sut/canonical-source) ; ns -> src |
83 | 88 | nses)))))))
|
0 commit comments