Skip to content

Commit

Permalink
Add default Clojure methods (:clojure/v0) to API tests
Browse files Browse the repository at this point in the history
  • Loading branch information
respatialized committed Jan 20, 2025
1 parent d16b345 commit b5b0cd8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/site/fabricate/prototype/source/clojure.clj
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@
forms)]
main))

(defmethod api/build [:clojure/v0 :hiccup]
(defmethod api/build [:clojure/v0 :hiccup/html]
[{source-location :site.fabricate.source/location :as entry} opts]
(let [{:keys [site.fabricate.document/title
site.fabricate.document/description]
Expand Down
2 changes: 1 addition & 1 deletion test-resources/site/fabricate/example.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
^{:kindly/kind :kind/hiccup}
(let [curr-ns *ns*
ns-meta (meta curr-ns)]
[:h1 (:site.fabricate/title ns-meta)])
[:h1 (:site.fabricate.document/title ns-meta)])

;; This file demonstrates behavior expected of Fabricate's initial clojure
;; parsing function. This particular multi-line comment block should be
Expand Down
15 changes: 15 additions & 0 deletions test/site/fabricate/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[site.fabricate.prototype.hiccup]
[site.fabricate.prototype.check]
[site.fabricate.prototype.source.clojure]
[site.fabricate.prototype.document.hiccup]
[malli.core :as m]
[malli.util :as mu]
[babashka.fs :as fs]))
Expand All @@ -24,6 +25,19 @@

(t/use-fixtures :once with-instrumentation)

(t/deftest default-multimethods
(t/testing "clojure"
(let [entries (vec (for [src-path (fs/glob "." "**/*.clj")]
{:site.fabricate.source/location (str src-path)
:site.fabricate.source/format :clojure/v0
:site.fabricate.page/location (fs/file
"test-resources/html"
(fs/file-name
src-path))}))]
(doseq [e entries]
(t/testing (:site.fabricate.source/location e)
(t/is (map? (api/build e {}))
"Arbitrary clojure sources should build without errors"))))))

(t/deftest operations
(let [tmp-dir (fs/create-temp-dir {:prefix "fabricate-test-"})
Expand Down Expand Up @@ -274,6 +288,7 @@
(not (re-find #"^site\.fabricate\.adorn" ns-str))
(not (re-find #"^site\.fabricate\.dev" ns-str))
(not (re-find #"^site\.fabricate.*test" ns-str))
(not (re-find #"^site\.fabricate.example" ns-str))
(not (re-find #"^site\.fabricate.*docs" ns-str))
(not (re-find #"^site\.fabricate.*time" ns-str))))))
(run! test-namespace))))
Expand Down
12 changes: 7 additions & 5 deletions test/site/fabricate/prototype/source/clojure_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
(let [final-entry (api/build {:site.fabricate.source/location
"test-resources/site/fabricate/example.clj"
:site.fabricate.source/format :clojure/v0
:site.fabricate.document/format :hiccup}
:site.fabricate.document/format :hiccup/html}
{})
final-hiccup (:site.fabricate.document/data final-entry)]
(t/is (vector? final-hiccup))
Expand Down Expand Up @@ -200,10 +200,12 @@

(comment
(require '[hiccup.page])
(->> "test-resources/site/fabricate/example.clj"
clj/file->forms
clj/eval-forms
clj/forms->hiccup
(->> (api/build {:site.fabricate.source/location
"test-resources/site/fabricate/example.clj"
:site.fabricate.source/format :clojure/v0
:site.fabricate.document/format :hiccup/html}
{})
:site.fabricate.document/data
hiccup.page/html5
(spit "test-resources/html/site.fabricate.example.html"))
(require '[edamame.core :as e])
Expand Down

0 comments on commit b5b0cd8

Please sign in to comment.