pax_global_header00006660000000000000000000000064130772223420014514gustar00rootroot0000000000000052 comment=aa64e3815e0b8280e0085bbcb1c9cd709bec63c3 medley-1.0.0/000077500000000000000000000000001307722234200127715ustar00rootroot00000000000000medley-1.0.0/.gitignore000066400000000000000000000001331307722234200147560ustar00rootroot00000000000000/target /classes /checkouts /codox pom.xml pom.xml.asc *.jar *.class /.lein-* /.nrepl-port medley-1.0.0/.travis.yml000066400000000000000000000000501307722234200150750ustar00rootroot00000000000000language: clojure script: lein test-all medley-1.0.0/README.md000066400000000000000000000025531307722234200142550ustar00rootroot00000000000000# Medley [![Build Status](https://img.shields.io/circleci/project/weavejester/medley/master.svg)](https://circleci.com/gh/weavejester/medley/tree/master) Medley is a lightweight Clojure/ClojureScript library of useful, *mostly* pure functions that are "missing" from clojure.core. Medley has a tighter focus than [flatland/useful][] or [Plumbing][], and limits itself to a small set of general-purpose functions. [flatland/useful]: https://github.com/flatland/useful [plumbing]: https://github.com/plumatic/plumbing ## Installation To install, add the following to your project `:dependencies`: [medley "1.0.0"] ## Breaking Changes In 0.7.0 the minimum Clojure version was changed from 1.5.1 to 1.7.0 to take advantage of [reader conditionals][]. The `update` function has also been removed, as it is now present in `clojure.core`. In 0.6.0 the type signature of `greatest` and `least` was changed to be more like `max` and `min` in Clojure core. If you're upgrading from a version prior to 0.6.0, please update your usage of `greatest` and `least`. [reader conditionals]: http://dev.clojure.org/display/design/Reader+Conditionals ## Documentation * [API Docs](http://weavejester.github.io/medley/medley.core.html) ## License Copyright © 2017 James Reeves Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version. medley-1.0.0/circle.yml000066400000000000000000000001301307722234200147470ustar00rootroot00000000000000general: branches: ignore: - gh-pages test: override: - lein test-all medley-1.0.0/project.clj000066400000000000000000000025361307722234200151370ustar00rootroot00000000000000(defproject medley "1.0.0" :description "A lightweight library of useful, mostly pure functions" :url "https://github.com/weavejester/medley" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.7.0"]] :plugins [[lein-codox "0.10.3"] [lein-cljsbuild "1.1.2"] [lein-doo "0.1.6"]] :codox {:output-path "codox" :metadata {:doc/format :markdown} :source-uri "http://github.com/weavejester/medley/blob/{version}/{filepath}#L{line}"} :cljsbuild {:builds {:test {:source-paths ["src" "test"] :compiler {:output-to "target/main.js" :output-dir "target" :main medley.test-runner :optimizations :simple}}}} :doo {:paths {:rhino "lein run -m org.mozilla.javascript.tools.shell.Main"}} :aliases {"test-cljs" ["doo" "rhino" "test" "once"] "test-clj" ["with-profile" "default:+1.8:+1.9" "test"] "test-all" ["do" ["test-clj"] ["test-cljs"]]} :profiles {:provided {:dependencies [[org.clojure/clojurescript "1.7.228"]]} :test {:dependencies [[org.mozilla/rhino "1.7.7"]]} :dev {:dependencies [[criterium "0.4.3"]] :jvm-opts ^:replace {}} :1.8 {:dependencies [[org.clojure/clojure "1.8.0"]]} :1.9 {:dependencies [[org.clojure/clojure "1.9.0-alpha15"]]}}) medley-1.0.0/src/000077500000000000000000000000001307722234200135605ustar00rootroot00000000000000medley-1.0.0/src/medley/000077500000000000000000000000001307722234200150375ustar00rootroot00000000000000medley-1.0.0/src/medley/core.cljc000066400000000000000000000243061307722234200166310ustar00rootroot00000000000000(ns medley.core "A small collection of useful, mostly pure functions that might not look out of place in the clojure.core namespace." (:refer-clojure :exclude [boolean? ex-cause ex-message uuid uuid? random-uuid])) (defn find-first "Finds the first item in a collection that matches a predicate." ([pred] (fn [rf] (fn ([] (rf)) ([result] (rf result)) ([result x] (if (pred x) (ensure-reduced (rf result x)) result))))) ([pred coll] (reduce (fn [_ x] (if (pred x) (reduced x))) nil coll))) (defn dissoc-in "Dissociate a value in a nested assocative structure, identified by a sequence of keys. Any collections left empty by the operation will be dissociated from their containing structures." [m ks] (if-let [[k & ks] (seq ks)] (if (seq ks) (let [v (dissoc-in (get m k) ks)] (if (empty? v) (dissoc m k) (assoc m k v))) (dissoc m k)) m)) (defn assoc-some "Associates a key with a value in a map, if and only if the value is not nil." ([m k v] (if (nil? v) m (assoc m k v))) ([m k v & kvs] (reduce (fn [m [k v]] (assoc-some m k v)) (assoc-some m k v) (partition 2 kvs)))) (defn- editable? [coll] #?(:clj (instance? clojure.lang.IEditableCollection coll) :cljs (satisfies? cljs.core.IEditableCollection coll))) (defn- reduce-map [f coll] (if (editable? coll) (persistent! (reduce-kv (f assoc!) (transient (empty coll)) coll)) (reduce-kv (f assoc) (empty coll) coll))) (defn map-entry "Create a map entry for a key and value pair." [k v] #?(:clj (clojure.lang.MapEntry. k v) :cljs [k v])) (defn map-kv "Maps a function over the key/value pairs of an associate collection. Expects a function that takes two arguments, the key and value, and returns the new key and value as a collection of two elements." [f coll] (reduce-map (fn [xf] (fn [m k v] (let [[k v] (f k v)] (xf m k v)))) coll)) (defn map-keys "Maps a function over the keys of an associative collection." [f coll] (reduce-map (fn [xf] (fn [m k v] (xf m (f k) v))) coll)) (defn map-vals "Maps a function over the values of an associative collection." [f coll] (reduce-map (fn [xf] (fn [m k v] (xf m k (f v)))) coll)) (defn filter-kv "Returns a new associative collection of the items in coll for which `(pred (key item) (val item))` returns true." [pred coll] (reduce-map (fn [xf] (fn [m k v] (if (pred k v) (xf m k v) m))) coll)) (defn filter-keys "Returns a new associative collection of the items in coll for which `(pred (key item))` returns true." [pred coll] (reduce-map (fn [xf] (fn [m k v] (if (pred k) (xf m k v) m))) coll)) (defn filter-vals "Returns a new associative collection of the items in coll for which `(pred (val item))` returns true." [pred coll] (reduce-map (fn [xf] (fn [m k v] (if (pred v) (xf m k v) m))) coll)) (defn remove-kv "Returns a new associative collection of the items in coll for which `(pred (key item) (val item))` returns false." [pred coll] (filter-kv (complement pred) coll)) (defn remove-keys "Returns a new associative collection of the items in coll for which `(pred (key item))` returns false." [pred coll] (filter-keys (complement pred) coll)) (defn remove-vals "Returns a new associative collection of the items in coll for which `(pred (val item))` returns false." [pred coll] (filter-vals (complement pred) coll)) (defn queue "Creates an empty persistent queue, or one populated with a collection." ([] #?(:clj clojure.lang.PersistentQueue/EMPTY :cljs cljs.core.PersistentQueue.EMPTY)) ([coll] (into (queue) coll))) (defn queue? "Returns true if x implements clojure.lang.PersistentQueue." [x] (instance? #?(:clj clojure.lang.PersistentQueue :cljs cljs.core.PersistentQueue) x)) (defn boolean? "Returns true if x is a boolean." [x] #?(:clj (instance? Boolean x) :cljs (or (true? x) (false? x)))) (defn least "Return the least argument (as defined by the compare function) in O(n) time." {:arglists '([& xs])} ([] nil) ([a] a) ([a b] (if (neg? (compare a b)) a b)) ([a b & more] (reduce least (least a b) more))) (defn greatest "Find the greatest argument (as defined by the compare function) in O(n) time." {:arglists '([& xs])} ([] nil) ([a] a) ([a b] (if (pos? (compare a b)) a b)) ([a b & more] (reduce greatest (greatest a b) more))) (defn mapply "Applies a function f to the argument list formed by concatenating everything but the last element of args with the last element of args. This is useful for applying a function that accepts keyword arguments to a map." {:arglists '([f & args])} ([f m] (apply f (apply concat m))) ([f a & args] (apply f a (apply concat (butlast args) (last args))))) (defn interleave-all "Returns a lazy seq of the first item in each coll, then the second, etc. Unlike `clojure.core/interleave`, the returned seq contains all items in the supplied collections, even if the collections are different sizes." {:arglists '([& colls])} ([] ()) ([c1] (lazy-seq c1)) ([c1 c2] (lazy-seq (let [s1 (seq c1), s2 (seq c2)] (if (and s1 s2) (cons (first s1) (cons (first s2) (interleave-all (rest s1) (rest s2)))) (or s1 s2))))) ([c1 c2 & colls] (lazy-seq (let [ss (remove nil? (map seq (conj colls c2 c1)))] (if (seq ss) (concat (map first ss) (apply interleave-all (map rest ss)))))))) (defn distinct-by "Returns a lazy sequence of the elements of coll, removing any elements that return duplicate values when passed to a function f." ([f] (fn [rf] (let [seen (volatile! #{})] (fn ([] (rf)) ([result] (rf result)) ([result x] (let [fx (f x)] (if (contains? @seen fx) result (do (vswap! seen conj fx) (rf result x))))))))) ([f coll] (let [step (fn step [xs seen] (lazy-seq ((fn [[x :as xs] seen] (when-let [s (seq xs)] (let [fx (f x)] (if (contains? seen fx) (recur (rest s) seen) (cons x (step (rest s) (conj seen fx))))))) xs seen)))] (step coll #{})))) (defn dedupe-by "Returns a lazy sequence of the elements of coll, removing any **consecutive** elements that return duplicate values when passed to a function f." ([f] (fn [rf] (let [pv (volatile! ::none)] (fn ([] (rf)) ([result] (rf result)) ([result x] (let [prior @pv fx (f x)] (vreset! pv fx) (if (= prior fx) result (rf result x)))))))) ([f coll] (sequence (dedupe-by f) coll))) (defn take-upto "Returns a lazy sequence of successive items from coll up to and including the first item for which `(pred item)` returns true." ([pred] (fn [rf] (fn ([] (rf)) ([result] (rf result)) ([result x] (let [result (rf result x)] (if (pred x) (ensure-reduced result) result)))))) ([pred coll] (lazy-seq (when-let [s (seq coll)] (let [x (first s)] (cons x (if-not (pred x) (take-upto pred (rest s))))))))) (defn drop-upto "Returns a lazy sequence of the items in coll starting *after* the first item for which `(pred item)` returns true." ([pred] (fn [rf] (let [dv (volatile! true)] (fn ([] (rf)) ([result] (rf result)) ([result x] (if @dv (do (when (pred x) (vreset! dv false)) result) (rf result x))))))) ([pred coll] (rest (drop-while (complement pred) coll)))) (defn indexed "Returns an ordered, lazy sequence of vectors `[index item]`, where item is a value in coll, and index its position starting from zero." ([] (fn [rf] (let [i (volatile! -1)] (fn ([] (rf)) ([result] (rf result)) ([result x] (rf result [(vswap! i inc) x])))))) ([coll] (map-indexed vector coll))) (defn abs "Returns the absolute value of a number." [x] (if (neg? x) (- x) x)) (defn deref-swap! "Atomically swaps the value of the atom to be `(apply f x args)`, where x is the current value of the atom, then returns the original value of the atom. This function therefore acts like an atomic `deref` then `swap!`." {:arglists '([atom f & args])} ([atom f] #?(:clj (loop [] (let [value @atom] (if (compare-and-set! atom value (f value)) value (recur)))) :cljs (let [value @atom] (reset! atom (f value)) value))) ([atom f & args] (deref-swap! atom #(apply f % args)))) (defn deref-reset! "Sets the value of the atom without regard for the current value, then returns the original value of the atom. See also: [[deref-swap!]]." [atom newval] (deref-swap! atom (constantly newval))) (defn ex-message "Returns the message attached to the given Error/Throwable object. For all other types returns nil. Same as `cljs.core/ex-message` except it works for Clojure as well as ClojureScript." [ex] #?(:clj (when (instance? Throwable ex) (.getMessage ^Throwable ex)) :cljs (cljs.core/ex-message ex))) (defn ex-cause "Returns the cause attached to the given ExceptionInfo/Throwable object. For all other types returns nil. Same as `cljs.core/ex-clause` except it works for Clojure as well as ClojureScript." [ex] #?(:clj (when (instance? Throwable ex) (.getCause ^Throwable ex)) :cljs (cljs.core/ex-cause ex))) (defn uuid? "Returns true if the value is a UUID." [x] (instance? #?(:clj java.util.UUID :cljs cljs.core.UUID) x)) (defn uuid "Returns a UUID generated from the supplied string. Same as `cljs.core/uuid` in ClojureScript, while in Clojure it returns a `java.util.UUID` object." [s] #?(:clj (java.util.UUID/fromString s) :cljs (cljs.core/uuid s))) (defn random-uuid "Generates a new random UUID. Same as `cljs.core/random-uuid` except it works for Clojure as well as ClojureScript." [] #?(:clj (java.util.UUID/randomUUID) :cljs (cljs.core/random-uuid))) medley-1.0.0/test/000077500000000000000000000000001307722234200137505ustar00rootroot00000000000000medley-1.0.0/test/medley/000077500000000000000000000000001307722234200152275ustar00rootroot00000000000000medley-1.0.0/test/medley/core_test.cljc000066400000000000000000000221561307722234200200610ustar00rootroot00000000000000(ns medley.core-test #?(:clj (:import [clojure.lang ArityException])) (:require #?(:clj [clojure.test :refer :all] :cljs [cljs.test :refer-macros [deftest is testing]]) [medley.core :as m])) (deftest test-find-first (testing "sequences" (is (= (m/find-first even? [7 3 3 2 8]) 2)) (is (nil? (m/find-first even? [7 3 3 7 3])))) (testing "transducers" (is (= (transduce (m/find-first even?) + 0 [7 3 3 2 8]) 2)) (is (= (transduce (m/find-first even?) + 0 [7 3 3 7 3]) 0)))) (deftest test-dissoc-in (is (= (m/dissoc-in {:a {:b {:c 1 :d 2}}} [:a :b :c]) {:a {:b {:d 2}}})) (is (= (m/dissoc-in {:a {:b {:c 1}}} [:a :b :c]) {})) (is (= (m/dissoc-in {:a {:b {:c 1} :d 2}} [:a :b :c]) {:a {:d 2}})) (is (= (m/dissoc-in {:a 1} []) {:a 1}))) (deftest test-assoc-some (is (= (m/assoc-some {:a 1} :b 2) {:a 1 :b 2})) (is (= (m/assoc-some {:a 1} :b nil) {:a 1})) (is (= (m/assoc-some {:a 1} :b 2 :c nil :d 3) {:a 1 :b 2 :d 3}))) (deftest test-map-entry (is (= (key (m/map-entry :a 1)) :a)) (is (= (val (m/map-entry :a 1)) 1)) (is (= (first (m/map-entry :a 1)) :a)) (is (= (second (m/map-entry :a 1)) 1)) (is (= (type (m/map-entry :a 1)) (type (first {:a 1}))))) (deftest test-map-kv (is (= (m/map-kv (fn [k v] [(name k) (inc v)]) {:a 1 :b 2}) {"a" 2 "b" 3})) (is (= (m/map-kv (fn [k v] [(name k) (inc v)]) (sorted-map :a 1 :b 2)) {"a" 2 "b" 3})) (is (= (m/map-kv (fn [k v] (m/map-entry (name k) (inc v))) {:a 1 :b 2}) {"a" 2 "b" 3}))) (deftest test-map-keys (is (= (m/map-keys name {:a 1 :b 2}) {"a" 1 "b" 2})) (is (= (m/map-keys name (sorted-map :a 1 :b 2)) (sorted-map "a" 1 "b" 2)))) (deftest test-map-vals (is (= (m/map-vals inc {:a 1 :b 2}) {:a 2 :b 3})) (is (= (m/map-vals inc (sorted-map :a 1 :b 2)) (sorted-map :a 2 :b 3)))) (deftest test-filter-kv (is (= (m/filter-kv (fn [k v] (and (keyword? k) (number? v))) {"a" 1 :b 2 :c "d"}) {:b 2})) (is (= (m/filter-kv (fn [k v] (= v 2)) (sorted-map "a" 1 "b" 2)) (sorted-map "b" 2)))) (deftest test-filter-keys (is (= (m/filter-keys keyword? {"a" 1 :b 2}) {:b 2})) (is (= (m/filter-keys #(re-find #"^b" %) (sorted-map "a" 1 "b" 2)) (sorted-map "b" 2)))) (deftest test-filter-vals (is (= (m/filter-vals even? {:a 1 :b 2}) {:b 2})) (is (= (m/filter-vals even? (sorted-map :a 1 :b 2)) (sorted-map :b 2)))) (deftest test-remove-kv (is (= (m/remove-kv (fn [k v] (and (keyword? k) (number? v))) {"a" 1 :b 2 :c "d"}) {"a" 1 :c "d"})) (is (= (m/remove-kv (fn [k v] (= v 2)) (sorted-map "a" 1 "b" 2)) (sorted-map "a" 1)))) (deftest test-remove-keys (is (= (m/remove-keys keyword? {"a" 1 :b 2}) {"a" 1})) (is (= (m/remove-keys #(re-find #"^b" %) (sorted-map "a" 1 "b" 2)) {"a" 1}))) (deftest test-remove-vals (is (= (m/remove-vals even? {:a 1 :b 2}) {:a 1})) (is (= (m/remove-keys #(re-find #"^b" %) (sorted-map "a" 1 "b" 2)) {"a" 1}))) (deftest test-queue (testing "empty" #?(:clj (is (instance? clojure.lang.PersistentQueue (m/queue))) :cljs (is (instance? cljs.core.PersistentQueue (m/queue)))) (is (empty? (m/queue)))) (testing "not empty" #?(:clj (is (instance? clojure.lang.PersistentQueue (m/queue [1 2 3]))) :cljs (is (instance? cljs.core.PersistentQueue (m/queue [1 2 3])))) (is (= (first (m/queue [1 2 3])) 1)))) (deftest test-queue? #?(:clj (is (m/queue? clojure.lang.PersistentQueue/EMPTY)) :cljs (is (m/queue? cljs.core.PersistentQueue.EMPTY))) (is (not (m/queue? [])))) (deftest test-boolean? (is (m/boolean? true)) (is (m/boolean? false)) (is (not (m/boolean? nil))) (is (not (m/boolean? "foo"))) (is (not (m/boolean? 1)))) (deftest test-least (is (= (m/least) nil)) (is (= (m/least "a") "a")) (is (= (m/least "a" "b") "a")) (is (= (m/least 3 2 5 -1 0 2) -1))) (deftest test-greatest (is (= (m/greatest) nil)) (is (= (m/greatest "a") "a")) (is (= (m/greatest "a" "b") "b")) (is (= (m/greatest 3 2 5 -1 0 2) 5))) (deftest test-mapply (letfn [(foo [& {:keys [bar]}] bar)] (is (= (m/mapply foo {}) nil)) (is (= (m/mapply foo {:baz 1}) nil)) (is (= (m/mapply foo {:bar 1}) 1))) (letfn [(foo [bar & {:keys [baz]}] [bar baz])] (is (= (m/mapply foo 0 {}) [0 nil])) (is (= (m/mapply foo 0 {:baz 1}) [0 1])) (is (= (m/mapply foo 0 {:spam 1}) [0 nil])) (is (= (m/mapply foo 0 nil) [0 nil])) #?@(:clj [(is (thrown? ArityException (m/mapply foo {}))) (is (thrown? IllegalArgumentException (m/mapply foo 0)))] :cljs [(is (thrown? js/Error (m/mapply foo 0)))]))) (deftest test-interleave-all (is (= (m/interleave-all []) [])) (is (= (m/interleave-all [1 2 3]) [1 2 3])) (is (= (m/interleave-all [1 2 3] [4 5 6]) [1 4 2 5 3 6])) (is (= (m/interleave-all [1 2 3] [4 5 6] [7 8 9]) [1 4 7 2 5 8 3 6 9])) (is (= (m/interleave-all [1 2] [3]) [1 3 2])) (is (= (m/interleave-all [1 2 3] [4 5]) [1 4 2 5 3])) (is (= (m/interleave-all [1] [2 3] [4 5 6]) [1 2 4 3 5 6]))) (deftest test-distinct-by (testing "sequences" (is (= (m/distinct-by count ["a" "ab" "c" "cd" "def"]) ["a" "ab" "def"])) (is (= (m/distinct-by count []) [])) (is (= (m/distinct-by first ["foo" "faa" "boom" "bar"]) ["foo" "boom"]))) (testing "transucers" (is (= (into [] (m/distinct-by count) ["a" "ab" "c" "cd" "def"]) ["a" "ab" "def"])) (is (= (into [] (m/distinct-by count) []) [])) (is (= (into [] (m/distinct-by first) ["foo" "faa" "boom" "bar"]) ["foo" "boom"])))) (deftest test-dedupe-by (testing "sequences" (is (= (m/dedupe-by count ["a" "b" "bc" "bcd" "cd"]) ["a" "bc" "bcd" "cd"])) (is (= (m/dedupe-by count []) [])) (is (= (m/dedupe-by first ["foo" "faa" "boom" "bar"]) ["foo" "boom"]))) (testing "transucers" (is (= (into [] (m/dedupe-by count) ["a" "b" "bc" "bcd" "cd"]) ["a" "bc" "bcd" "cd"])) (is (= (into [] (m/dedupe-by count) []) [])) (is (= (into [] (m/dedupe-by first) ["foo" "faa" "boom" "bar"]) ["foo" "boom"])))) (deftest test-take-upto (testing "sequences" (is (= (m/take-upto zero? [1 2 3 0 4 5 6]) [1 2 3 0])) (is (= (m/take-upto zero? [0 1 2 3 4 5 6]) [0])) (is (= (m/take-upto zero? [1 2 3 4 5 6 7]) [1 2 3 4 5 6 7]))) (testing "tranducers" (is (= (into [] (m/take-upto zero?) [1 2 3 0 4 5 6]) [1 2 3 0])) (is (= (into [] (m/take-upto zero?) [0 1 2 3 4 5 6]) [0])) (is (= (into [] (m/take-upto zero?) [1 2 3 4 5 6 7]) [1 2 3 4 5 6 7])) (is (= (transduce (m/take-upto zero?) (completing (fn [_ x] (reduced x))) nil [0 1 2]) 0)))) (deftest test-drop-upto (testing "sequences" (is (= (m/drop-upto zero? [1 2 3 0 4 5 6]) [4 5 6])) (is (= (m/drop-upto zero? [0 1 2 3 4 5 6]) [1 2 3 4 5 6])) (is (= (m/drop-upto zero? [1 2 3 4 5 6 7]) []))) (testing "transducers" (is (= (into [] (m/drop-upto zero?) [1 2 3 0 4 5 6]) [4 5 6])) (is (= (into [] (m/drop-upto zero?) [0 1 2 3 4 5 6]) [1 2 3 4 5 6])) (is (= (into [] (m/drop-upto zero?) [1 2 3 4 5 6 7]) [])))) (deftest test-indexed (testing "sequences" (is (= (m/indexed [:a :b :c :d]) [[0 :a] [1 :b] [2 :c] [3 :d]])) (is (= (m/indexed []) []))) (testing "transducers" (is (= (into [] (m/indexed) [:a :b :c :d]) [[0 :a] [1 :b] [2 :c] [3 :d]])) (is (= (into [] (m/indexed) []) [])))) (deftest test-abs (is (= (m/abs -3) 3)) (is (= (m/abs 2) 2)) (is (= (m/abs -2.1) 2.1)) (is (= (m/abs 1.8) 1.8)) #?@(:clj [(is (= (m/abs -1/3) 1/3)) (is (= (m/abs 1/2) 1/2)) (is (= (m/abs 3N) 3N)) (is (= (m/abs -4N) 4N))])) (deftest test-deref-swap! (let [a (atom 0)] (is (= (m/deref-swap! a inc) 0)) (is (= @a 1)) (is (= (m/deref-swap! a inc) 1)) (is (= @a 2)))) (deftest test-deref-reset! (let [a (atom 0)] (is (= (m/deref-reset! a 3) 0)) (is (= @a 3)) (is (= (m/deref-reset! a 1) 3)) (is (= @a 1)))) (deftest test-ex-message (is (= (m/ex-message (ex-info "foo" {})) "foo")) (is (= (m/ex-message (new #?(:clj Exception :cljs js/Error) "bar")) "bar"))) (deftest test-ex-cause (let [cause (new #?(:clj Exception :cljs js/Error) "foo")] (is (= (m/ex-cause (ex-info "foo" {} cause)) cause)) #?(:clj (is (= (m/ex-cause (Exception. "foo" cause)) cause))))) (deftest test-uuid? (let [x #uuid "d1a4adfa-d9cf-4aa5-9f05-a15365d1bfa6"] (is (m/uuid? x)) (is (not (m/uuid? 2))) (is (not (m/uuid? (str x)))) (is (not (m/uuid? nil))))) (deftest test-uuid (let [x (m/uuid "d1a4adfa-d9cf-4aa5-9f05-a15365d1bfa6")] (is (instance? #?(:clj java.util.UUID :cljs cljs.core.UUID) x)) (is (= x #uuid "d1a4adfa-d9cf-4aa5-9f05-a15365d1bfa6")))) (deftest test-random-uuid (let [x (m/random-uuid) y (m/random-uuid)] (is (instance? #?(:clj java.util.UUID :cljs cljs.core.UUID) x)) (is (instance? #?(:clj java.util.UUID :cljs cljs.core.UUID) y)) (is (not= x y)))) medley-1.0.0/test/medley/test_runner.cljs000066400000000000000000000002121307722234200204470ustar00rootroot00000000000000(ns medley.test-runner (:require [doo.runner :refer-macros [doo-tests]] [medley.core-test])) (doo-tests 'medley.core-test)