Skip to content

Commit

Permalink
fix parsing of large numbers. (closes #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick Scherer committed Jan 20, 2015
1 parent dbecc59 commit 250177b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/cljx/version_clj/split.cljx
Expand Up @@ -26,8 +26,11 @@
[#+clj ^String x
#+cljs ^js/String x]
(if (re-matches #"\d+" x)
#+clj (Integer/parseInt x)
#+cljs (js/parseInt x)
#+clj (try
(Long/parseLong x)
(catch NumberFormatException _
(bigint x)))
#+cljs (js/parseFloat x)
(.toLowerCase x)))

(defmethod normalize-element :seq
Expand Down
11 changes: 9 additions & 2 deletions test/cljx/version_clj/split_test.cljx
@@ -1,6 +1,6 @@
(ns version-clj.split-test
(:require #+clj [clojure.test :refer [deftest are]]
#+cljs [cemerick.cljs.test :refer-macros [deftest are]]
(:require #+clj [clojure.test :refer [deftest are is]]
#+cljs [cemerick.cljs.test :refer-macros [deftest are is]]
[version-clj.split :refer [version->seq]]))

(deftest t-split
Expand All @@ -14,3 +14,10 @@
"1.0.1-alpha2" [[1 0 1] ["alpha" 2]]
"11.2.0.3.0" [[11 2 0 3 0]]
"1.0-1-0.2-RC" [[1 [0 1 0] 2] ["rc"]]))

(deftest t-split-with-large-number
(is (= (version->seq "0.0.1-20141002100138")
[[0 0 1] [20141002100138]]))
#+clj
(let [v (str Long/MAX_VALUE "12345")]
(is (= (version->seq v) [[(bigint v)]]))))

0 comments on commit 250177b

Please sign in to comment.