Skip to content

Commit

Permalink
Add :default cases to multi-methods (closes weavejester#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
arichiardi committed Feb 19, 2017
1 parent 7b57ec8 commit 3d1aae2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/resauce/core.clj
Expand Up @@ -38,6 +38,9 @@
entry (.getEntry jar (add-ending-slash path))]
(and entry (.isDirectory entry))))

(defmethod directory? :default [url]
false)

(defmulti url-dir
"Return a list of URLs contained by this URL, if the protocol supports it."
{:arglists '([url])}
Expand All @@ -56,6 +59,9 @@
(filter-dir-paths path)
(map (partial build-url url path)))))

(defmethod url-dir nil [url]
nil)

(defn- default-loader []
(.getContextClassLoader (Thread/currentThread)))

Expand Down
5 changes: 4 additions & 1 deletion test/resauce/core_test.clj
Expand Up @@ -7,7 +7,8 @@
(is (directory? (io/resource "resauce")))
(is (directory? (io/resource "clojure")))
(is (not (directory? (io/resource "resauce/core.clj"))))
(is (not (directory? (io/resource "clojure/core.clj")))))
(is (not (directory? (io/resource "clojure/core.clj"))))
(is (not (directory? nil))))

(deftest test-resources
(let [rs (sort (map str (resources "resauce")))]
Expand All @@ -16,6 +17,8 @@
(is (re-find #"test/resauce$" (second rs)))))

(deftest test-url-dir
(is (nil? (url-dir nil)))
(is (thrown? java.lang.IllegalArgumentException (url-dir (io/as-url "http://www.example.com/docs/resource1.html"))))
(testing "file URL"
(let [rs (url-dir (io/as-url (io/file "src/resauce")))]
(is (= (count rs) 1))
Expand Down

0 comments on commit 3d1aae2

Please sign in to comment.