#include <list> #include "RegExpOptimizeTest.h" #include "regexp/unbounded/UnboundedRegExp.h" #include "regexp/simplify/RegExpOptimize.h" #include <factory/StringDataFactory.hpp> #define CPPUNIT_IMPLY(x, y) CPPUNIT_ASSERT(!(x) || (y)) #define CPPUNIT_EXCLUSIVE_OR(x, y) CPPUNIT_ASSERT((!(x) && (y)) || ((x) && !(y))) CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RegExpOptimizeTest, "regexp" ); CPPUNIT_TEST_SUITE_REGISTRATION( RegExpOptimizeTest ); void RegExpOptimizeTest::setUp() { } void RegExpOptimizeTest::tearDown() { } void RegExpOptimizeTest::testOptimize() { { std::string input = "a+a"; regexp::UnboundedRegExp < > regexp( static_cast<const regexp::UnboundedRegExp < > &>( alib::StringDataFactory::fromString<regexp::RegExp>(input).getData() ) ); regexp::UnboundedRegExp < > res = regexp::simplify::RegExpOptimize::optimize(regexp); std::string inputRes = "a"; regexp::UnboundedRegExp < > regexpRes( static_cast<const regexp::UnboundedRegExp < > &>( alib::StringDataFactory::fromString<regexp::RegExp>(inputRes).getData() ) ); std::cout << res << std::endl; std::cout << regexpRes << std::endl; CPPUNIT_ASSERT ( regexpRes == res ); } { std::string input = "(a+a)b + (#0 b + (#0 a + (#0 b + a)))"; regexp::UnboundedRegExp < > regexp( static_cast<const regexp::UnboundedRegExp < > &>( alib::StringDataFactory::fromString<regexp::RegExp>(input).getData() ) ); regexp::UnboundedRegExp < > res = regexp::simplify::RegExpOptimize::optimize(regexp); std::string inputRes = "a + ab"; regexp::UnboundedRegExp < > regexpRes( static_cast<const regexp::UnboundedRegExp < > &>( alib::StringDataFactory::fromString<regexp::RegExp>(inputRes).getData() ) ); std::cout << res << std::endl; std::cout << regexpRes << std::endl; CPPUNIT_ASSERT ( regexpRes == res ); } { std::string input = "a z + a b* b z"; regexp::UnboundedRegExp < > regexp( static_cast<const regexp::UnboundedRegExp < > &>( alib::StringDataFactory::fromString<regexp::RegExp>(input).getData() ) ); regexp::UnboundedRegExp < > res = regexp::simplify::RegExpOptimize::optimize(regexp); std::string inputRes = "a b* z"; regexp::UnboundedRegExp < > regexpRes( static_cast<const regexp::UnboundedRegExp < > &>( alib::StringDataFactory::fromString<regexp::RegExp>(inputRes).getData() ) ); std::cout << res << std::endl; std::cout << regexpRes << std::endl; CPPUNIT_ASSERT ( regexpRes == res ); } }