Add version comparison stuff to utils. Now test tagged-literals when Clojure version is sufficient.

This commit is contained in:
Peter Taoussanis 2012-07-21 18:05:17 +07:00
parent d566ef1231
commit 1bcab7ede2
2 changed files with 52 additions and 38 deletions

View file

@ -255,48 +255,50 @@
(def stress-data
"Reference data used for tests & benchmarks."
{;; Breaks reader, roundtrip equality
:bytes (byte-array [(byte 1) (byte 2) (byte 3)])
(let [support-tagged-literals?
(utils/version-sufficient? (clojure-version) "1.4.0")]
:nil nil
:boolean true
{;; Breaks reader, roundtrip equality
:bytes (byte-array [(byte 1) (byte 2) (byte 3)])
:char-utf8 \ಬ
:string-utf8 "ಬಾ ಇಲ್ಲಿ ಸಂಭವಿಸ"
:string-long (apply str (range 1000))
:keyword :keyword
:keyword-ns ::keyword
:nil nil
:boolean true
:list (list 1 2 3 4 5 (list 6 7 8 (list 9 10)))
:list-quoted '(1 2 3 4 5 (6 7 8 (9 10)))
:list-empty (list)
:vector [1 2 3 4 5 [6 7 8 [9 10]]]
:vector-empty []
:map {:a 1 :b 2 :c 3 :d {:e 4 :f {:g 5 :h 6 :i 7}}}
:map-empty {}
:set #{1 2 3 4 5 #{6 7 8 #{9 10}}}
:set-empty #{}
:meta (with-meta {:a :A} {:metakey :metaval})
:char-utf8 \ಬ
:string-utf8 "ಬಾ ಇಲ್ಲಿ ಸಂಭವಿಸ"
:string-long (apply str (range 1000))
:keyword :keyword
:keyword-ns ::keyword
;; Breaks reader
:queue (-> (PersistentQueue/EMPTY) (conj :a :b :c :d :e :f :g))
:queue-empty (PersistentQueue/EMPTY)
:list (list 1 2 3 4 5 (list 6 7 8 (list 9 10)))
:list-quoted '(1 2 3 4 5 (6 7 8 (9 10)))
:list-empty (list)
:vector [1 2 3 4 5 [6 7 8 [9 10]]]
:vector-empty []
:map {:a 1 :b 2 :c 3 :d {:e 4 :f {:g 5 :h 6 :i 7}}}
:map-empty {}
:set #{1 2 3 4 5 #{6 7 8 #{9 10}}}
:set-empty #{}
:meta (with-meta {:a :A} {:metakey :metaval})
:coll (repeatedly 1000 rand)
;; Breaks reader
:queue (-> (PersistentQueue/EMPTY) (conj :a :b :c :d :e :f :g))
:queue-empty (PersistentQueue/EMPTY)
:byte (byte 16)
:short (short 42)
:integer (int 3)
:long (long 3)
:bigint (bigint 31415926535897932384626433832795)
:coll (repeatedly 1000 rand)
:float (float 3.14)
:double (double 3.14)
:bigdec (bigdec 3.1415926535897932384626433832795)
:byte (byte 16)
:short (short 42)
:integer (int 3)
:long (long 3)
:bigint (bigint 31415926535897932384626433832795)
:ratio 22/7
:float (float 3.14)
:double (double 3.14)
:bigdec (bigdec 3.1415926535897932384626433832795)
;; Clojure 1.4+
;; :tagged-uuid (java.util.UUID/randomUUID)
;; :tagged-date (java.util.Date.)
})
:ratio 22/7
;; Clojure 1.4+
:tagged-uuid (when support-tagged-literals? (java.util.UUID/randomUUID))
:tagged-date (when support-tagged-literals? (java.util.Date.))}))

View file

@ -1,5 +1,6 @@
(ns taoensso.nippy.utils
{:author "Peter Taoussanis"})
{:author "Peter Taoussanis"}
(:require [clojure.string :as str]))
(defmacro case-eval
"Like `case` but evaluates test constants for their compile-time value."
@ -36,3 +37,14 @@
dorun))))]
(if ~as-ms? (Math/round (/ nanosecs# 1000000.0)) nanosecs#))
(catch Exception e# (str "DNF: " (.getMessage e#)))))
(defn version-compare
"Comparator for version strings like x.y.z, etc."
[x y]
(let [vals (fn [s] (vec (map #(Integer/parseInt %) (str/split s #"\."))))]
(compare (vals x) (vals y))))
(defn version-sufficient?
[version-str min-version-str]
(try (>= (version-compare version-str min-version-str) 0)
(catch Exception _ false)))