Documentation
¶
Index ¶
Examples ¶
Constants ¶
const MaxUnicode = '\U0010ffff'
MaxUnicode is the maximum Unicode character that can be generated.
const VERSION = "0.1.3"
Variables ¶
var ErrVerificationFailed = fmt.Errorf("verification failed")
Functions ¶
This section is empty.
Types ¶
type Chooser ¶
Chooser defines an interface that allows to make choices.
func NewBytesChooser ¶
NewBytesChooser uses buf as a source of information for decision. This makes the exploration of all possible strings perfectily deterministic. Using a chooser to make a decision "consumes" the available information. When all information is "consumed", defaults or first choices will always be the one chosen.
func NewRandChooser ¶
func NewRandChooser() Chooser
NewRandChooser uses random as the source for decision. It is guaranteed that no string has a zero probability, but longer strings have a much lower chance of appearing.
func NewRandChooserSeed ¶
NewRandChooserSeed uses random as the source for decision. It is guaranteed that no string has a zero probability, but longer strings have a much lower chance of appearing. Setting the seed allows for reproductibility in tests.
type Gen ¶
type Gen struct {
// contains filtered or unexported fields
}
Gen can generate deterministic or random strings that match a given regexp. Gen is thread safe.
func NewGen ¶
NewGen creates a new generator. It will panic if the regexp provided is not syntaxicaly correct. Use POSIX syntax. No implicit parse tree simplification.
Example ¶
pattern := "a(b|c)a?" generator := NewGen(pattern) entropy := NewRandChooserSeed(42) // or use NewRandInter() for real randomness ... // Generate 5 strings that match "a(b|c)a?" for i := 0; i < 5; i++ { result := generator.Next(entropy) fmt.Println(result) // Verify each generated string actually matches ? if err := generator.Verify(result); err != nil { fmt.Println("Verification failed with error : ", err) } }
Output: aca ab aca ac aba
func NewGenSimpl ¶
Same as NewGen, but in addition, the tree is simplified.