Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad default type converter #93

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/fn_fx/render_core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@
(if (keyword? value)
(do (register-keyword-conv tp)
(convert-value value tp))
(assert (.isAssignableFrom tp (type value)) (str "Can't convert " (pr-str value) " of type " (type value) " to " tp))))
value)
(assert (.isAssignableFrom tp (type value)) (str "Can't convert " (pr-str value) " of type " (type value) " to " tp)))
value))

(defmethod convert-value
[java.lang.Long Double/TYPE]
Expand Down Expand Up @@ -417,6 +417,14 @@
[v _]
(int v))

(defmethod convert-value [Long Integer/TYPE]
[v _]
(int v))

(defmethod convert-value [Integer Integer/TYPE]
[v _]
(int v))

(defmethod convert-value [Double Double/TYPE]
[v _]
(double v))
Expand Down
19 changes: 19 additions & 0 deletions test/fn_fx/fx_dom_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,26 @@
(Thread/sleep 100)
(is (= (get-prop @root :title) "Hello"))))

(deftest test-primitive-type-conversions
(let [default-count (-> :javafx.animation.TranslateTransition
(component {}) dom/app :root)
long-count (-> :javafx.animation.TranslateTransition
(component {:cycle-count 22}) dom/app :root)
integer-count
(-> :javafx.animation.TranslateTransition
(component {:cycle-count javafx.animation.Animation/INDEFINITE})
dom/app :root)]
(Thread/sleep 100)
(is (= 1 (get-prop @default-count :cycle-count)))
(is (= 22 (get-prop @long-count :cycle-count)))
(is (= -1 (get-prop @integer-count :cycle-count)))))

(deftest test-keyword-type-conversions
(let [interpolator (-> :javafx.animation.TranslateTransition
(component {:interpolator :linear}) dom/app :root)]
(Thread/sleep 100)
(is (= javafx.animation.Interpolator/LINEAR
(get-prop @interpolator :interpolator)))))

(defn gen-list [cnt]
(let [items (vec (for [x (range cnt)]
Expand Down