Newer
Older
#include "RegExpTest.h"
#include "sax/SaxComposeInterface.h"
#include "regexp/unbounded/UnboundedRegExp.h"
#include <regexp/RegExp.h>
#include "regexp/glushkov/GlushkovFollow.h"
#include "regexp/glushkov/GlushkovIndexate.h"
#include "regexp/glushkov/GlushkovFirst.h"
#include "regexp/glushkov/GlushkovLast.h"
#include <factory/StringDataFactory.hpp>
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ( RegExpTest, "regexp" );
CPPUNIT_TEST_SUITE_REGISTRATION ( RegExpTest );
{
std::string input = "#E* #0*";
regexp::UnboundedRegExp < > regexp = alib::StringDataFactory::fromString ( input );
regexp::UnboundedRegExp < ext::pair < DefaultSymbolType, int > > indexedRegExp = regexp::GlushkovIndexate::index ( regexp );
ext::set < regexp::UnboundedRegExpSymbol < ext::pair < DefaultSymbolType, int > > > first = regexp::GlushkovFirst::first ( indexedRegExp );
}
{
std::string input = "#E* a";
regexp::UnboundedRegExp < > regexp = alib::StringDataFactory::fromString ( input );
regexp::UnboundedRegExp < ext::pair < DefaultSymbolType, int > > indexedRegExp = regexp::GlushkovIndexate::index ( regexp );
ext::set < regexp::UnboundedRegExpSymbol < ext::pair < DefaultSymbolType, int > > > first = regexp::GlushkovFirst::first ( indexedRegExp );
{
std::string input = "a+a";
regexp::UnboundedRegExp < > regexp = alib::StringDataFactory::fromString ( input );
regexp::UnboundedRegExp < ext::pair < DefaultSymbolType, int > > indexedRegExp = regexp::GlushkovIndexate::index ( regexp );
ext::set < regexp::UnboundedRegExpSymbol < ext::pair < DefaultSymbolType, int > > > last = regexp::GlushkovLast::last ( indexedRegExp );
}
{
std::string input = "(a+a)b";
regexp::UnboundedRegExp < > regexp = alib::StringDataFactory::fromString ( input );
regexp::UnboundedRegExp < ext::pair < DefaultSymbolType, int > > indexedRegExp = regexp::GlushkovIndexate::index ( regexp );
ext::set < regexp::UnboundedRegExpSymbol < ext::pair < DefaultSymbolType, int > > > last = regexp::GlushkovLast::last ( indexedRegExp );
{
std::string input = "(a+a)b";
regexp::UnboundedRegExp < > regexp = alib::StringDataFactory::fromString ( input );
regexp::UnboundedRegExp < ext::pair < DefaultSymbolType, int > > indexedRegExp = regexp::GlushkovIndexate::index ( regexp );
auto symbolsIter = indexedRegExp.getAlphabet ( ).begin ( );
ext::set < regexp::UnboundedRegExpSymbol < ext::pair < DefaultSymbolType, int > > > follow1 = regexp::GlushkovFollow::follow ( indexedRegExp, regexp::UnboundedRegExpSymbol < ext::pair < DefaultSymbolType, int > > ( * symbolsIter ) );
CPPUNIT_ASSERT ( follow1.size ( ) == 1 );
ext::set < regexp::UnboundedRegExpSymbol < ext::pair < DefaultSymbolType, int > > > follow2 = regexp::GlushkovFollow::follow ( indexedRegExp, regexp::UnboundedRegExpSymbol < ext::pair < DefaultSymbolType, int > > ( * symbolsIter ) );
CPPUNIT_ASSERT ( follow2.size ( ) == 1 );
ext::set < regexp::UnboundedRegExpSymbol < ext::pair < DefaultSymbolType, int > > > follow3 = regexp::GlushkovFollow::follow ( indexedRegExp, regexp::UnboundedRegExpSymbol < ext::pair < DefaultSymbolType, int > > ( * symbolsIter ) );
CPPUNIT_ASSERT ( follow3.size ( ) == 0 );
}
{
std::string input = "a+a* (b+a)* c";
regexp::UnboundedRegExp < > regexp = alib::StringDataFactory::fromString ( input );
regexp::UnboundedRegExp < ext::pair < DefaultSymbolType, int > > indexedRegExp = regexp::GlushkovIndexate::index ( regexp );
auto symbolsIter = indexedRegExp.getAlphabet ( ).begin ( );
ext::set < regexp::UnboundedRegExpSymbol < ext::pair < DefaultSymbolType, int > > > follow1 = regexp::GlushkovFollow::follow ( indexedRegExp, regexp::UnboundedRegExpSymbol < ext::pair < DefaultSymbolType, int > > ( * symbolsIter ) );
CPPUNIT_ASSERT ( follow1.size ( ) == 0 );
ext::set < regexp::UnboundedRegExpSymbol < ext::pair < DefaultSymbolType, int > > > follow2 = regexp::GlushkovFollow::follow ( indexedRegExp, regexp::UnboundedRegExpSymbol < ext::pair < DefaultSymbolType, int > > ( * symbolsIter ) );
CPPUNIT_ASSERT ( follow2.size ( ) == 4 );
ext::set < regexp::UnboundedRegExpSymbol < ext::pair < DefaultSymbolType, int > > > follow3 = regexp::GlushkovFollow::follow ( indexedRegExp, regexp::UnboundedRegExpSymbol < ext::pair < DefaultSymbolType, int > > ( * symbolsIter ) );
CPPUNIT_ASSERT ( follow3.size ( ) == 3 );
ext::set < regexp::UnboundedRegExpSymbol < ext::pair < DefaultSymbolType, int > > > follow4 = regexp::GlushkovFollow::follow ( indexedRegExp, regexp::UnboundedRegExpSymbol < ext::pair < DefaultSymbolType, int > > ( * symbolsIter ) );
CPPUNIT_ASSERT ( follow4.size ( ) == 3 );
ext::set < regexp::UnboundedRegExpSymbol < ext::pair < DefaultSymbolType, int > > > follow5 = regexp::GlushkovFollow::follow ( indexedRegExp, regexp::UnboundedRegExpSymbol < ext::pair < DefaultSymbolType, int > > ( * symbolsIter ) );
CPPUNIT_ASSERT ( follow5.size ( ) == 0 );