middle of porting; unstable, don't checkout; refs #1
This commit is contained in:
63
test/regexp_test.cxx
Normal file
63
test/regexp_test.cxx
Normal file
@@ -0,0 +1,63 @@
|
||||
/** @file
|
||||
|
||||
$Id$
|
||||
|
||||
$Date$
|
||||
$Author$
|
||||
|
||||
@copy © Marc Wäckerlin
|
||||
@license LGPL, see file <a href="license.html">COPYING</a>
|
||||
|
||||
$Log$
|
||||
Revision 1.2 2004/12/16 13:09:31 marc
|
||||
possibility to evaluate and extract sub expressions
|
||||
|
||||
Revision 1.1 2004/12/14 20:20:30 marc
|
||||
initial version
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <mrw/regexp.hxx>
|
||||
#include <mrw/exception.hxx>
|
||||
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
|
||||
class RegExpTest: public CppUnit::TestFixture {
|
||||
public:
|
||||
void CheckRegExp() {
|
||||
mrw::RegExp findHalloWelt("^Hallo.*Welt$");
|
||||
CPPUNIT_ASSERT(findHalloWelt("Hallo Meine Welt"));
|
||||
CPPUNIT_ASSERT(!findHalloWelt("xxx"));
|
||||
CPPUNIT_ASSERT(!findHalloWelt(""));
|
||||
CPPUNIT_ASSERT(!findHalloWelt(" Hallo Welt "));
|
||||
CPPUNIT_ASSERT(findHalloWelt("HalloWelt"));
|
||||
mrw::RegExp extractTest("^Guten (.*) (Herr|Frau) (.*)$", true);
|
||||
CPPUNIT_ASSERT(extractTest("Guten Tag Frau Zuercher"));
|
||||
CPPUNIT_ASSERT(extractTest[1]=="Tag" &&
|
||||
extractTest[2]=="Frau" &&
|
||||
extractTest[3]=="Zuercher");
|
||||
}
|
||||
void ExceptionTest() {
|
||||
mrw::RegExp extractTest("^Guten (.*) (Herr|Frau) (.*)$", true);
|
||||
CPPUNIT_ASSERT(extractTest("Guten Tag Herr Schweizer"));
|
||||
CPPUNIT_ASSERT(extractTest[1]=="Tag" &&
|
||||
extractTest[2]=="Herr" &&
|
||||
extractTest[3]=="Schweizer");
|
||||
std::string s = extractTest[4];
|
||||
}
|
||||
CPPUNIT_TEST_SUITE(RegExpTest);
|
||||
CPPUNIT_TEST(CheckRegExp);
|
||||
CPPUNIT_TEST_EXCEPTION(ExceptionTest, mrw::invalid_argument);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
};
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(RegExpTest);
|
||||
|
||||
int main() {
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
||||
return runner.run() ? 0 : 1;
|
||||
}
|
Reference in New Issue
Block a user