-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
70 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
(ns fast-edn.buf-test | ||
(:refer-clojure :exclude [rand-int]) | ||
(:require | ||
[clojure.edn] | ||
[clojure.data.generators :as gen] | ||
[clojure.string :as str] | ||
[clojure.test :refer [deftest is are testing]] | ||
[clojure.test.generative :refer [defspec]] | ||
[clojure.test.generative.runner :as runner] | ||
[fast-edn.core :as edn] | ||
[fast-edn.generators :as cgen])) | ||
|
||
(defn rand-int | ||
([n] | ||
(rand-int 0 n)) | ||
([min max] | ||
(+ min (clojure.core/rand-int (- max min))))) | ||
|
||
(defn rand-coll [] | ||
(let [coll (distinct | ||
(repeatedly (* (rand-int 0 10) 2) #(gen/one-of cgen/ednable-scalar)))] | ||
(if (odd? (count coll)) | ||
(recur) | ||
coll))) | ||
|
||
(defn stringify [coll] | ||
(let [[open close] (rand-nth [["[" "]"] | ||
["(" ")"] | ||
["{" "}"] | ||
["#{" "}"]])] | ||
(str/join | ||
(interleave | ||
(concat ["" open] (map pr-str coll) [close]) | ||
(repeatedly #(str/join (repeat (rand-int 1 25) " "))))))) | ||
|
||
(defn rand-str [] | ||
(stringify (rand-coll))) | ||
|
||
(defspec reader-should-not-break | ||
(fn [str] | ||
(edn/read-string {:buffer 10} str)) | ||
[^{:tag fast-edn.buf-test/rand-str} str] | ||
(when-not (= (clojure.edn/read-string str) %) | ||
(throw (ex-info "Value cannot roundtrip, see ex-data" {:printed str :read %})))) | ||
|
||
(def cpus | ||
8) | ||
|
||
(def time-ms | ||
10000) | ||
|
||
(deftest buf-test | ||
(runner/run cpus time-ms #'reader-should-not-break)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters