How to use the regex for our test?

i have a question regarding making the test. lets say i want to make a test where its testing if its allowed to use number for the scheme. It’s pretty dumb to check (“1://”) and so on, because its just imposible to cover all number possibility. how do i use regex for this case?

1 Like

RegEx (a derivation of regular expressions) are for matching, finding, and describing patterns.
They are not that helpful for tests as you want to do the opposite: Instead of parsing you want to generate inputs. ^1

As you said, you can and should not cover all possible inputs.
By the very nature of testing, it is incomplete.
Tests only can tell you bugs not prove correctness (except for certain interesting areas of testing and problem descriptions ).

Your goal is to write tests that cover all interesting kinds of inputs.
You should cover each case of the specification, all edge and corner cases, some normal inputs, and maybe one or two extreme inputs (not too extreme).

If you have tests on the number bounds (0, 255, 256, 4294967295), on some number in between (3, 5, 42, 126), and some outside the bounds (357, -5), you can assume that the program works on all numbers.
One usually does not encounter bugs that cause the program to work on 4 but not on 7 (when those numbers have no special meaning).

Note ^1:
RegEx could be used for structure/grammar-guided fuzzing approaches.
But one should be careful to preselect the fuzzed cases to eliminate randomness, restrict it to a sensible amount of cases, and add more handcrafted cases as fuzzing often misses semantics and edge cases.

1 Like