A feature I would like to see standardized in the
StarUnit frameworks is a way to test whether a result matches a specified
RegularExpression pattern. Examples:
string ssnPattern = "^\\d{3}-\\d{2}-\\d{4}$";
assertMatch("Should match SSN pattern", ssnPattern, "123-45-6789");
assertNotMatch("Should not match SSN pattern", ssnPattern, "867-5309");
Unfortunately, it may not be easy to add this feature to
TestingFrameworks for programming languages and environments that don't have built-in support for regular expressions.
For CeePlusPlus[Language], BoostLibraries should give a boost...
An implementation of this for
NunitFramework V2.0 is available here:
http://kristopherjohnson.net/RegexTestFramework/RegexAssertion.cs
MiniRubyWiki uses this technique relentlessly, using
RubyTestUnit's
assert_match.
PerlUnit has that pattern too (natch).
For a big collection of useful
PerlLanguage RegularExpressions, take a look at the Regexp::Common module on the CPAN (
http://search.cpan.org/author/ABIGAIL/Regexp-Common/). --
GregBacon
However, one should not test a parsible language with Regexps. One should parse it with its native parser, and build this into an assertion. The assertion should then forgive anything in the target that's not in the assertion. See
AssertXhtml.
CategoryRegularExpressions CategoryAssertions