Thread overview
test coverage for std.regexp
Dec 12, 2006
Don Clugston
Dec 13, 2006
Walter Bright
Dec 13, 2006
Don Clugston
Dec 14, 2006
Walter Bright
December 12, 2006
std.regexp currently has very poor test coverage (about 50%). The code below greatly increases the coverage (to over 80%), but they are not actual tests, other than exercising the parsing code. Perhaps someone with some spare time might add some asserts and more sensible test strings to turn them into actual tests so that they can be added to Phobos?

-------
unittest {
// TODO: Actually check the return values of these searches!
    auto m = regexp.search("aBC r s", `bc\x20r[\40]s`, "i");
    assert(m.pre=="a");
    assert(m.match(0)=="BC r s");
    auto m2 = regexp.search("7xxyxxx", `^\d([a-z]{2})\D\1`);
    assert(m2.match(0)=="7xxyxx");
    // Just check the parsing.
    auto m3 = regexp.search("dcbxx", `ca|b[\d\]\D\s\S\w-\W]`);
    auto m4 = regexp.search("xy", `[^\ca-\xFa\r\n\b\f\t\v\0123]{2,485}$`);
    auto m5 = regexp.search("xxx", `^^\r\n\b{13,}\f{4}\t\v\u02aF3a\w\W`);
    auto m6 = regexp.search("xxy", `.*y`);
    assert(m6.match(0)=="xxy");
    auto m7 = regexp.search("QWDEfGH", "(ca|b|defg)+", "i");
    assert(m7.match(0)=="DEfG");
    auto m8 = regexp.search("dcbxx", `a?\B\s\S`);
    auto m9 = regexp.search("dcbxx", `[-w]`);
    auto m10 = regexp.search("dcbsfd", `aB[c-fW]dB|\d|\D|\u012356|\w|\W|\s|\S`, "i");
    auto m11 = regexp.search("dcbsfd", `[]a-]`);
    m.replaceOld(`a&b\1c`);
    m.replace(`a$&b$'$1c`);
}
December 13, 2006
Don Clugston wrote:
> std.regexp currently has very poor test coverage (about 50%).

I actually have a separate test suite for regexp, but it's under license and so I cannot add it in to std.regexp. But with your permission, I can add yours!
December 13, 2006
Walter Bright wrote:
> Don Clugston wrote:
>> std.regexp currently has very poor test coverage (about 50%).
> 
> I actually have a separate test suite for regexp, but it's under license and so I cannot add it in to std.regexp. But with your permission, I can add yours!

No problem. I hereby donate the code below to the public domain.

unittest {
    auto m = regexp.search("aBC r s", `bc\x20r[\40]s`, "i");
    assert(m.pre=="a");
    assert(m.match(0)=="BC r s");
    auto m2 = regexp.search("7xxyxxx", `^\d([a-z]{2})\D\1`);
    assert(m2.match(0)=="7xxyxx");
    // Just check the parsing.
    auto m3 = regexp.search("dcbxx", `ca|b[\d\]\D\s\S\w-\W]`);
    auto m4 = regexp.search("xy", `[^\ca-\xFa\r\n\b\f\t\v\0123]{2,485}$`);
    auto m5 = regexp.search("xxx", `^^\r\n\b{13,}\f{4}\t\v\u02aF3a\w\W`);
    auto m6 = regexp.search("xxy", `.*y`);
    assert(m6.match(0)=="xxy");
    auto m7 = regexp.search("QWDEfGH", "(ca|b|defg)+", "i");
    assert(m7.match(0)=="DEfG");
    auto m8 = regexp.search("dcbxx", `a?\B\s\S`);
    auto m9 = regexp.search("dcbxx", `[-w]`);
    auto m10 = regexp.search("dcbsfd", `aB[c-fW]dB|\d|\D|\u012356|\w|\W|\s|\S`, "i");
    auto m11 = regexp.search("dcbsfd", `[]a-]`);
    m.replaceOld(`a&b\1c`);
    m.replace(`a$&b$'$1c`);
}
December 14, 2006
Don Clugston wrote:
> No problem. I hereby donate the code below to the public domain.

Thank you. It's part of std.regexp now!