[Git][clojure-team/potemkin-clojure][upstream] New upstream version 0.4.5
Louis-Philippe Véronneau
gitlab at salsa.debian.org
Thu Dec 3 18:18:26 GMT 2020
Louis-Philippe Véronneau pushed to branch upstream at Debian Clojure Maintainers / potemkin-clojure
Commits:
0f5ab800 by Louis-Philippe Véronneau at 2020-12-03T11:15:02-05:00
New upstream version 0.4.5
- - - - -
12 changed files:
- .travis.yml
- README.md
- project.clj
- src/potemkin/collections.clj
- src/potemkin/namespaces.clj
- src/potemkin/types.clj
- src/potemkin/utils.clj
- src/potemkin/walk.clj
- test/potemkin/collections_test.clj
- test/potemkin/namespaces_test.clj
- test/potemkin/types_test.clj
- test/potemkin/utils_test.clj
Changes:
=====================================
.travis.yml
=====================================
@@ -1,6 +1,5 @@
language: clojure
-lein: lein2
-script: lein2 do clean, test
+script: lein do clean, test
sudo: false
jdk:
- openjdk7
=====================================
README.md
=====================================
@@ -5,7 +5,7 @@ Potemkin is a collection of facades and workarounds for things that are more dif
[![Build Status](https://travis-ci.org/ztellman/potemkin.png?branch=master)](https://travis-ci.org/ztellman/potemkin)
```clj
-[potemkin "0.4.3"]
+[potemkin "0.4.5"]
```
### `import-vars`
=====================================
project.clj
=====================================
@@ -1,4 +1,4 @@
-(defproject potemkin "0.4.3"
+(defproject potemkin "0.4.5"
:license {:name "MIT License"}
:description "Some useful facades."
:dependencies [[clj-tuple "0.2.2"]
=====================================
src/potemkin/collections.clj
=====================================
@@ -62,11 +62,18 @@
clojure.lang.IPersistentCollection
(equiv [this x]
- (and (map? x) (= x (into {} this))))
+ (and (or (instance? java.util.Map x) (map? x))
+ (= x (into {} this))))
(cons [this o]
- (if (map? o)
+ (cond
+ (map? o)
(reduce #(apply assoc %1 %2) this o)
+
+ (instance? java.util.Map o)
+ (reduce #(apply assoc %1 %2) this (into {} o))
+
+ :else
(if-let [[k v] (seq o)]
(assoc this k v)
this)))
@@ -118,14 +125,15 @@
(hashCode [this]
(reduce
(fn [acc [k v]]
- (unchecked-add acc (bit-xor (.hashCode k) (.hashCode v))))
+ (unchecked-add acc (bit-xor (clojure.lang.Util/hash k)
+ (clojure.lang.Util/hash v))))
0
(seq this)))
(equals [this x]
(or (identical? this x)
(and
- (map? x)
+ (or (instance? java.util.Map x) (map? x))
(= x (into {} this)))))
(toString [this]
=====================================
src/potemkin/namespaces.clj
=====================================
@@ -96,6 +96,7 @@
(let [vr (resolve sym)
m (meta vr)]
(cond
+ (nil? vr) `(throw (ex-info (format "`%s` does not exist" '~sym) {}))
(:macro m) `(import-macro ~sym)
(:arglists m) `(import-fn ~sym)
:else `(import-def ~sym))))
=====================================
src/potemkin/types.clj
=====================================
@@ -173,7 +173,8 @@
"A protocol that won't evaluate if an equivalent protocol with the same name already exists."
[name & body]
(let [prev-body (-> name resolve meta :potemkin/body)]
- (when-not (equivalent? prev-body body)
+ (when (or (not (equivalent? prev-body body))
+ (-> name resolve nil?))
`(let [p# (defprotocol ~name ~@body)]
(alter-meta! (resolve p#) assoc :potemkin/body '~(r/macroexpand-all body))
p#))))
=====================================
src/potemkin/utils.clj
=====================================
@@ -99,7 +99,7 @@
(if-not (nil? v#)
(re-nil v#)
(let [v# (de-nil (~f ~@args))]
- (or (.putIfAbsent ~m k# v#) v#))))))
+ (re-nil (or (.putIfAbsent ~m k# v#) v#)))))))
(defn fast-memoize
"A version of `memoize` which has equivalent behavior, but is faster."
=====================================
src/potemkin/walk.clj
=====================================
@@ -9,6 +9,8 @@
(list? form) (outer (apply list (map inner form)))
(instance? clojure.lang.IMapEntry form) (outer (vec (map inner form)))
(seq? form) (outer (doall (map inner form)))
+ (instance? clojure.lang.IRecord form)
+ (outer (reduce (fn [r x] (conj r (inner x))) form form))
(coll? form) (outer (into (empty form) (map inner form)))
:else (outer form))]
(if (instance? clojure.lang.IObj x)
=====================================
test/potemkin/collections_test.clj
=====================================
@@ -21,6 +21,9 @@
(dissoc [_ k] (simple-map (dissoc m k) mta))
(keys [_] (keys m))))
+(deftest test-simple-map-equiv
+ (is (= (java.util.HashMap.) (simple-map {} {}))))
+
(def-derived-map SimpleDerivedMap [])
(def-derived-map DerivedMap [^String s]
@@ -38,7 +41,10 @@
"value")))
(test-basic-map-functionality (->SimpleDerivedMap))
(test-basic-map-functionality (simple-map {} {}))
- (is (= [:one "two"] (find (->SimpleMap {:one "two" :three "four"} {}) :one))))
+ (is (= [:one "two"] (find (->SimpleMap {:one "two" :three "four"} {}) :one)))
+ (is (= {:old 1 :new 2} (conj (->SimpleMap {:old 1} {}) {:new 2})))
+ (is (= {:old 1 :new 2} (conj (->SimpleMap {:old 1} {}) (doto (java.util.HashMap.)
+ (.put :new 2))))))
(defn test-derived-map [f]
(let [m (f "AbC")]
=====================================
test/potemkin/namespaces_test.clj
=====================================
@@ -16,6 +16,7 @@
(import-fn i/inlined-fn)
(import-def i/some-value)
+
(defn drop-lines [n s]
(->> s str/split-lines (drop n) (interpose "\n") (apply str)))
@@ -44,3 +45,10 @@
(is (= 1 some-value))
(require 'potemkin.imports-test :reload)
(is (= 1 some-value)))
+
+(deftest import-vars-throws-if-missing-var
+ (try
+ (import-vars [clojure.set union onion-misspelled])
+ (is false "`import-vars` should have thrown an exception")
+ (catch Exception ex
+ (is "`clojure.set/onion-misspelled` does not exist" (.getMessage ex)))))
=====================================
test/potemkin/types_test.clj
=====================================
@@ -18,6 +18,12 @@
(is (= nil (eval '(potemkin/defprotocol+ BarP (bar [x y])))))
(is (not= nil (eval '(potemkin/defprotocol+ BarP (bar [x y z]))))))
+(deftest test-empty-defprotocol+-body
+ (let [prot-sym (gensym)]
+ (binding [*ns* (the-ns 'potemkin.types-test)]
+ (eval (list 'potemkin/defprotocol+ prot-sym))
+ (is (resolve prot-sym)))))
+
(deftest test-definterface+
(is (not= nil (eval '(potemkin/definterface+ IBar (bar-baz [x y])))))
(is (= nil (eval '(potemkin/definterface+ IBar (bar-baz [x y])))))
=====================================
test/potemkin/utils_test.clj
=====================================
@@ -15,6 +15,18 @@
(deftest test-try*
)
+(deftest fast-memoize-test
+ (testing "returns nil on first call"
+ (let [f (fn [x] nil)
+ f' (fast-memoize f)]
+ (is (nil? (f' 1)))))
+
+ (testing "memoizes"
+ (let [f' (fast-memoize +)]
+ (is (= 5 (f' 2 3)))
+ (is (= 5 (f' 2 3)))
+ (is (= 6 (f' 2 3 1))))))
+
(deftest ^:benchmark benchmark-fast-memoize
(let [f (memoize +)
f' (fast-memoize +)]
View it on GitLab: https://salsa.debian.org/clojure-team/potemkin-clojure/-/commit/0f5ab800d9415e9b3be02d8546ce356491af3ea4
--
View it on GitLab: https://salsa.debian.org/clojure-team/potemkin-clojure/-/commit/0f5ab800d9415e9b3be02d8546ce356491af3ea4
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20201203/6077e458/attachment.html>
More information about the pkg-java-commits
mailing list