Added unit tests

This commit is contained in:
Simon Brooke 2019-06-15 14:18:56 +01:00
parent d71cc7a121
commit c85093d6ac
3 changed files with 50 additions and 10 deletions

View file

@ -6,4 +6,18 @@
:dependencies [[org.clojure/clojure "1.8.0"] :dependencies [[org.clojure/clojure "1.8.0"]
[hiccup "1.0.5"] [hiccup "1.0.5"]
[markdown-clj "0.9.99" :exclusions [com.keminglabs/cljx]] [markdown-clj "0.9.99" :exclusions [com.keminglabs/cljx]]
[net.sf.cssbox/swingbox "1.0"]]) [net.sf.cssbox/swingbox "1.0"]]
:plugins [[lein-codox "0.10.3"]
[lein-kibit "0.1.6"]
[lein-release "1.0.5"]]
:release-tasks [["vcs" "assert-committed"]
["change" "version" "leiningen.release/bump-version" "release"]
["vcs" "commit"]
["clean"]
["test"]
["codox"]
["jar"]
;; ["deploy" "clojars"]
["change" "version" "leiningen.release/bump-version"]
["vcs" "commit"]]
)

View file

@ -44,7 +44,8 @@
* literally anything else. * literally anything else.
Returns the `window`." Returns the `window`."
[window content] [window content]
(if (window? window) (if
(window? window)
(let [browser (:browser window) (let [browser (:browser window)
url (try (.toURL (URI/create (str content))) (catch Exception _ nil)) url (try (.toURL (URI/create (str content))) (catch Exception _ nil))
html (try (html content) (catch Exception _ nil))] html (try (html content) (catch Exception _ nil))]
@ -58,14 +59,16 @@
java.lang.String (.setText browser content) java.lang.String (.setText browser content)
clojure.lang.PersistentVector (.setText browser (html content)) clojure.lang.PersistentVector (.setText browser (html content))
java.io.File (.setPage browser (.toURL content)) java.io.File (.setPage browser (.toURL content))
(.setText browser (str content)))) (.setText browser (str content))))))
window))) window)
(defn set-content-markdown (defn set-content-markdown
"Set the content of this `window` to the markdown read from this `filename`. "Set the content of this `window` to the markdown read from this `filename`.
Return the `window`." Return the `window`."
[window filename] [window filename]
(set-content window (md/md-to-html-string (slurp filename))) (if
(window? window)
(set-content window (md/md-to-html-string (slurp filename))))
window) window)
(defn set-visible (defn set-visible
@ -87,5 +90,3 @@
[title content] [title content]
(set-visible (set-content (create-window title) content))) (set-visible (set-content (create-window title) content)))

View file

@ -2,6 +2,31 @@
(:require [clojure.test :refer :all] (:require [clojure.test :refer :all]
[swingbox-clj.core :refer :all])) [swingbox-clj.core :refer :all]))
(deftest a-test (deftest create-window-test
(testing "FIXME, I fail." (testing "Creating a window"
(is (= 0 1)))) (let [expected true
actual (window? (create-window))] ;; no title
(is (= actual expected)))
(let [expected true
actual (window? (create-window "With title"))]
(is (= actual expected)))
))
(deftest is-window-test
(testing "window?"
(let [expected false
actual (window? {:foo :bar})]
(is (= actual expected) "Wrong keys"))
(let [expected false
actual (window? nil)]
(is (= actual expected) "Not a map at all"))
(let [expected false
actual (window? {:frame 7 :browser "Bingo"})]
(is (= actual expected) "Wrong values for right keys"))
(let [expected true
actual (window? (create-window))]
(is (= actual expected) "Right keys"))
(let [expected true
actual (window? (assoc (create-window) :foo "bar"))]
(is (= actual expected) "Additional keys are tolerated"))))