8000 Add tests for destructuring in protocol fns, refs #141 · clojure/clojurescript@2e1f902 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2e1f902

Browse files
michalmarczykswannodette
authored andcommitted
Add tests for destructuring in protocol fns, refs #141
1 parent 8ba4849 commit 2e1f902

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/cljs/cljs/core_test.cljs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,5 +985,35 @@
985985
(assert (= (hash {:start 133 :end 134})
986986
(hash (apply hash-map [:start 133 :end 134]))))
987987

988+
(defprotocol IHasFirst
989+
(-get-first [this]))
990+
991+
(defprotocol IFindsFirst
992+
(-find-first [this other]))
993+
994+
(deftype First [xs]
995+
ISeqable
996+
(-seq [this] (seq xs))
997+
IIndexed
998+
(-nth [this i] (nth xs i))
999+
(-nth [this i not-found] (nth xs i not-found))
1000+
IFn
1001+
(-invoke [[x]] x)
1002+
Object
1003+
(toString [[x]] (str x))
1004+
IHasFirst
1005+
(-get-first [[x]] x)
1006+
IFindsFirst
1007+
(-find-first [_ [x]] x))
1008+
1009+
(let [fv (First. [1 2 3])
1010+
fs (First. "asdf")]
1011+
(assert (= (fv) 1))
1012+
(assert (= (fs) \a))
1013+
(assert (= (str fs) \a))
1014+
(assert (= (-get-first fv) 1))
1015+
(assert (= (-get-first fs) \a))
1016+
(assert (= (-find-first fv [1]) 1)))
1017+
9881018
:ok
9891019
)

0 commit comments

Comments
 (0)
0