_评论者是:m0smith_
以下是如何使用-to-string方法来模拟制表符分隔的文件中的行示例
(def gen-char-upper (gen/fmap char (gen/choose \A \Z)))
(def gen-char-lower (gen/fmap char (gen/choose \a \z)))
(def gen-char-digit (gen/fmap char (gen/choose \0 \9)))
(def gen-char-postal-format (gen/fmap char (gen/one-of [(gen/return \#)
(gen/return \@)
gen-char-upper])))
(def gen-iso-2 (gen/to-string gen-char-upper {:num-elements 2}))
(def gen-iso-3 (gen/to-string gen-char-upper {:num-elements 3}))
(def gen-iso-numeric (gen/to-string gen-char-digit {:num-elements 3}))
(def gen-fips (gen/to-string gen-char-upper {:num-elements 2}))
(def gen-country gen/string)
(def gen-capital gen/string)
(def gen-area (gen/large-integer* {:min 100 :max 999999999}))
(def gen-population (gen/large-integer* {:min 100 :max 999999999}))
(def gen-continent (gen/elements ["AS" "NA" "SA" "EU" "OC" "AF"]))
(def gen-tld (gen/to-string gen-char-lower {:num-elements 2 :prefix "."}))
(def gen-currency-code (gen/to-string gen-char-upper {:num-elements 3}))
(def gen-currency-name gen/string)
(def gen-phone (gen/large-integer* {:min 1 :max 999}))
(def gen-simple-language (gen/to-string gen-char-lower {:num-elements 2}))
(def gen-language (gen/one-of [gen-simple-language
(gen/to-string [gen-simple-language (gen/return "-") gen-iso-2])]))
(def gen-languages (gen/to-string gen-language {:sep ","}))
(def gen-geonameid (gen/large-integer* {:min 1 :max 999999999}))
(def gen-neighbors (gen/to-string gen-iso-2 {:sep ","}))
(def gen-equivilent-fips (gen/to-string gen-char-upper {:num-elements 2}))
(defn to-postal-regex [postal-format]
(str "^" (clojure.string/join (map #(cond (= \# %) "\\d" (= \@ %) "[A-Z]" :default %) postal-format)) "$"))
(def gen-country-line
(gen/let [postal-format (gen/to-string gen-char-postal-format {:min-elements 2 :max-element 9})]
(gen/to-string [gen-iso-2 gen-iso-3 gen-iso-numeric gen-fips
gen-country gen-capital gen-area gen-population gen-continent
gen-tld gen-currency-code gen-currency-name gen-phone
(gen/return postal-format) (gen/return (to-postal-regex postal-format))
gen-languages gen-geonameid gen-neighbors gen-equivilent-fips
] {:sep \tab})))