File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 21
21
(let [v ((or (-> x meta ::datafy ) -datafy) x)]
22
22
(if (identical? v x)
23
23
v
24
- (if (object? v)
24
+ (if (implements? IWithMeta v)
25
25
(vary-meta v assoc ::obj x)
26
26
v))))
27
27
Original file line number Diff line number Diff line change
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)))))))
Original file line number Diff line number Diff line change 22
22
[cljs.ns-test]
23
23
[clojure.string-test]
24
24
[clojure.data-test]
25
+ [clojure.datafy-test]
25
26
[clojure.walk-test]
26
27
[cljs.macro-test]
27
28
[cljs.letfn-test]
67
68
'cljs.reader-test
68
69
'clojure.string-test
69
70
'clojure.data-test
71
+ 'clojure.datafy-test
70
72
'clojure.walk-test
71
73
'cljs.letfn-test
72
74
'cljs.reducers-test
You can’t perform that action at this time.
0 commit comments