Skip to content

Commit fc7abd0

Browse files
Will Actonswannodette
authored andcommitted
CLJS-3010: Datafy does not properly check for whether the datafied value supports metadata
Datafy correctly detects if return value supports metadata
1 parent d6f8896 commit fc7abd0

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/main/cljs/clojure/datafy.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
(let [v ((or (-> x meta ::datafy) -datafy) x)]
2222
(if (identical? v x)
2323
v
24-
(if (object? v)
24+
(if (implements? IWithMeta v)
2525
(vary-meta v assoc ::obj x)
2626
v))))
2727

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
;; Copyright (c) Rich Hickey. All rights reserved.
2+
;; The use and distribution terms for this software are covered by the
3+
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4+
;; which can be found in the file epl-v10.html at the root of this distribution.
5+
;; By using this software in any fashion, you are agreeing to be bound by
6+
;; the terms of this license.
7+
;; You must not remove this notice, or any other, from this software.
8+
9+
(ns clojure.datafy-test
10+
(:require [cljs.test :as test
11+
:refer-macros [deftest is testing]]
12+
[clojure.datafy :as d]))
13+
14+
(deftest datafy-test
15+
(testing "Datafy works when datafied value is arbitrary JS objects"
16+
(let [datafied #js {}
17+
x (with-meta [1 2 3] {:clojure.datafy/datafy (fn [_] datafied)})]
18+
(is (= datafied (d/datafy x)))))
19+
(testing "Datafy adds ::obj metadata when return value != original value and supports metadata"
20+
(let [datafied [2 3 4]
21+
original [1 2 3]
22+
x (with-meta original {:clojure.datafy/datafy (fn [_] datafied)})]
23+
(is (= datafied (d/datafy x)))
24+
(is (= {:clojure.datafy/obj original} (meta (d/datafy x)))))))

src/test/cljs/test_runner.cljs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
[cljs.ns-test]
2323
[clojure.string-test]
2424
[clojure.data-test]
25+
[clojure.datafy-test]
2526
[clojure.walk-test]
2627
[cljs.macro-test]
2728
[cljs.letfn-test]
@@ -67,6 +68,7 @@
6768
'cljs.reader-test
6869
'clojure.string-test
6970
'clojure.data-test
71+
'clojure.datafy-test
7072
'clojure.walk-test
7173
'cljs.letfn-test
7274
'cljs.reducers-test

0 commit comments

Comments
 (0)