如何将生成的值作为clojure.spec中的单独参数依赖?

时间:2017-02-12 08:21:22

标签: clojure clojurescript clojure.spec

我有以下代码,我正在尝试使用path-and-subpath生成器为(s/fdef conj-set ...)创建值。

(def path (s/coll-of (s/with-gen string? #(s/gen #{"a" "b" "c" "d"}))
                     :min-count 1
                     :kind vector?
                     :into []))

(s/def ::path
  (s/with-gen
    path
    (fn [] (gen/fmap #(vec (take 5 %)) (s/gen path)))))

;; GENERATES THE TUPLES OF PATH AND SUB-PATH
(def path-and-subpath
  (->
   ::path
   s/gen
   (gen/bind
    (fn [xs]
      (gen/tuple
       (gen/return xs)
       (->> xs count inc (s/int-in 1) s/gen))))
   (gen/bind
    (fn [[xs i]]
      (gen/tuple
       (gen/return xs)
       (gen/return (subvec xs 0 i)))))))

(s/fdef conj-set
        :args (s/and
               (s/cat :path <FIRST_VALUE_IN_GENERATED_TUPLE>
                      :sub-path <SECOND_VALUE_IN_GENERTED_TUPLE>)
               #(= (-> % :args :sub-path)
                   (->> % :args :full-path (take (-> % :args :sub-path count))))))

我不知道如何将这两件事放在一起。我有一个生成元组的生成器,我有一个fdef具有我想要指定的依赖参数。如何将它们结合起来?

0 个答案:

没有答案