0

test.check has a built in generator gen/string-alphanumeric but it does not have a gen/string-alpha. How do I make a generator that will make strings only composed of letters and no numbers?

triplej
  • 269
  • 4
  • 9

2 Answers2

0

You can use gen/char-alpha with gen/fmap to make a string.

(gen/fmap clojure.string/join (gen/vector gen/char-alpha))

If you need to use this a lot, I recommend binding it. Example:

(def gen-string-alpha
  (gen/fmap clojure.string/join (gen/vector gen/char-alpha)))
triplej
  • 269
  • 4
  • 9
0

test.chuck has a generator, string-from-regex that will prove useful in generating strings that match any desired regular expression.

dpassen
  • 1,276
  • 1
  • 10
  • 14