How do I write a generator to make an alpha string using test.check?

121 Views Asked by At

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?

2

There are 2 best solutions below

0
On BEST ANSWER

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)))
0
On

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