Generating sample data from a regular expression to validate input strings by focusing on the boundary cases defined in the regular expression

There are several ways to create sample data for a given regular expression. Some of them include:

However, although they may be enough to sow a data set, this does not help significantly validate code that depends on the regular expression itself, such as validation.

Suppose you have a code generator that generates a model with a property. The user sets a regular expression to validate the property. Suppose now that the code generator is trying to generate tests to verify that the verification completed successfully and is not performed properly. It seems reasonable that the tool focus on boundary cases in regular expression to avoid generating unnecessary data.

For example, consider a regular expression ^([a-z]{3,6})$, then boundary cases include:

  • any string consisting only of [az] length equal to 2 (reject)
  • any string consisting only of [az] length equal to 3 (success)
  • any string consisting only of [az] of length 4 (success)
  • any string consisting only of [az] length equal to 5 (success)
  • any string consisting only of [az] length equal to 6 (success)
  • , [a-z], 7 ()
  • , [a-z] ()
  • , [a-z], [a-z] ()
  • , [a-z], [a-z] ()

, , , , [a-z] 6, , . 7, 8, 9 () .

, , .

/, . , .

+5
1

, , .

? - , , ?

, . , . , :

(?<=\G\d{0,3})(?>[a-z]+)(?<=(?<foo>foo)|)(?(foo)(?!))

, (/ ):

abc123def456ghi789jkl123foo456pqr789stu123vwx456yz

:

  • ""
  • "DEF"
  • ""
  • "JKL"

? - ( ) . - , , . , , :

, . \d{0,3} \G , ( ). (?<=(?<foo>foo)) ( , ).

, :

1

, , .

, , , P v NP . , .

+1

All Articles