<commit_before>(ns akvo.lumen.specs
  (:require [clojure.spec.alpha :as s]
            [clojure.spec.gen.alpha :as gen]
            [integrant.core :as ig]
            [clojure.string :as string]
            [akvo.lumen.util :refer (squuid)]
            [clojure.tools.logging :as log]))

(defn keyname [key] (str (namespace key) "/" (name key)))

(defn sample-with-gen* [s map-gen]
  (last (map first (s/exercise s 10 (reduce-kv (fn [c k v]
                                                  (if (fn? v)
                                                    (assoc c k v)
                                                    (assoc c k #(s/gen #{v})))
                                                  ) {} map-gen)))))


(defn sample-with-gen [s map-gen amount]
  (map first (s/exercise s amount map-gen)))

(defn sample
  ([s]
   (sample s 1))
  ([s amount]
   (let [res (map first (s/exercise s amount))]
     (if (== 1 amount)
       (first res)
       res))))

(defn str-uuid? [v]
  (when (some? v)
    (try
      (uuid? (read-string (format "#uuid \"%s\"" v)))
      (catch Throwable t false))))

(def str-uuid-gen #(s/gen (reduce (fn [c _] (conj c (str (squuid)))) #{} (range 100))))

(s/def ::str-uuid
  (s/with-gen<commit_msg>[#2417] Use `UUID/fromString` instead of `read-string`<commit_after>(ns akvo.lumen.specs
  (:require [clojure.spec.alpha :as s]
            [clojure.spec.gen.alpha :as gen]
            [integrant.core :as ig]
            [clojure.string :as string]
            [akvo.lumen.util :refer (squuid)]
            [clojure.tools.logging :as log])
  (:import java.util.UUID))

(defn keyname [key] (str (namespace key) "/" (name key)))

(defn sample-with-gen* [s map-gen]
  (last (map first (s/exercise s 10 (reduce-kv (fn [c k v]
                                                  (if (fn? v)
                                                    (assoc c k v)
                                                    (assoc c k #(s/gen #{v})))
                                                  ) {} map-gen)))))


(defn sample-with-gen [s map-gen amount]
  (map first (s/exercise s amount map-gen)))

(defn sample
  ([s]
   (sample s 1))
  ([s amount]
   (let [res (map first (s/exercise s amount))]
     (if (== 1 amount)
       (first res)
       res))))

(defn str-uuid? [v]
  (when (some? v)
    (try
      (uuid? (UUID/fromString v))
      (catch Throwable t false))))

(def str-uuid-gen #(s/gen (reduce (fn [c _] (conj c (str (squuid)))) #{} (range 100))))

(s/def ::str-uuid
  (s/with-gen
{'fraction_non_alphanumeric': 0.16162420382165604, 'fraction_numerical': 0.007165605095541401, 'mean_word_length': 1.5358224016145308, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '800509', 'n_tokens_mistral': 868, 'n_tokens_neox': 838, 'n_words': 245}