Skip to content

Commit

Permalink
added some compiler tests
Browse files Browse the repository at this point in the history
  • Loading branch information
onionpancakes committed Feb 19, 2024
1 parent 1702564 commit ed8e7f7
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions dev/user.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(:require [dev.onionpancakes.chassis.core :as c]
[dev.onionpancakes.chassis.compiler :as cc]
[dev.onionpancakes.chassis.tests.test-core :as t]
[dev.onionpancakes.chassis.tests.test-compiler :as tc]
[criterium.core :refer [bench quick-bench]]
[hiccup2.core :as hiccup]
[hiccup.page :as hiccup.page]
Expand Down
60 changes: 60 additions & 0 deletions test/dev/onionpancakes/chassis/tests/test_compiler.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
(ns dev.onionpancakes.chassis.tests.test-compiler
(:require [dev.onionpancakes.chassis.core :as c]
[dev.onionpancakes.chassis.compiler :as cc]
[clojure.test :refer [deftest are is]]))

(def example-deref
(delay "foobar"))

(defn example-fn []
"foobar")

(def example-attrs
{:foo "bar"})

(defn example-elem-fn
[arg]
[:p arg])

(defmacro example-elem-macro
[arg]
[:p arg])

(defmethod c/resolve-alias ::Foo
[_ _ attrs content]
[:p.alias attrs content])

(deftest test-compile
(are [node] (= (c/html (cc/compile node)) (c/html node))
nil
0
0.0
""
"foobar"
{}
#{}
'()
[]
[:div]
[:div "foo"]
[:div#foo "foo"]
[:div.123 "foo"]
[:div#foo.123 "foo"]
[:div [:p 123] [:p 456]]
[:div example-deref]
[:div example-fn]
[:div nil]
[:div {:foo "bar"}]
[:div {:foo "bar"} "baz"]
[:div example-attrs]
[:div (example-elem-fn "foo")]
[:div (example-elem-macro "foo")]
[:div (for [i (range 4)]
[:p i])]
(map inc (range 5))
[:div (map inc (range 5))]
[:div nil (map inc (range 5))]
[::Foo]
[::Foo nil]
[::Foo nil "foobar"]
[::Foo nil "foo" [::Foo "bar"]]))

0 comments on commit ed8e7f7

Please sign in to comment.