File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
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 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]
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
You can’t perform that action at this time.
0 commit comments