Regenerate is a library to generate test cases for regular expression engines.
Here is a typical use of the library, for creating a test harness with QCheck.
let test =
(* The alphabet is [abc] *)
let alphabet = ['a'; 'b'; 'c'] in
(* Words are made of regular strings. *)
let module Word = Regenerate.Word.String in
(* Streams are made of ThunkLists. *)
let module Stream = Regenerate.Segments.ThunkList(Word) in
let generator =
Regenerate.arbitrary
(module Word)
(module Stream)
~compl:false (* Do not generate complement operators. *)
~pp:Fmt.char (* Printer for characters. *)
~samples:100 (* We want on average 100 samples for each regex. *)
alphabet
in
QCheck.Test.make generator check (* Test the [check] function. *)
Regenerate.arbitrary (module W) (module S) ~compl ~pp ~samples alpha creates a QCheck generator that generates triples containing a regex and a list of positive and negative samples.
parameterW
is a module implementing operation on words. See Word for some predefined modules.
parameterS
is a module implementing a data-structure enumerating words. See Segments for some predefined modules. We recommend Segments.ThunkList.
parameterskip
specifies how many samples should we skip on average. Default is 8.
parametercompl
specifies if we generate regex containing the complement operator.
Regenerate.parse s returns the associated regex. It recognizes the Posix Extended Regular Expression syntax plus complement (~a) and intersection (a&b). Character classes are not supported.
Regenerate.Make(W)(S)(A) is a module that implements sample generation for words implemented by the module W with the alphabet A. S describes the data structure used internally for the enumeration of words.