#include <list> #include <variant> #include "StringTest.h" #include "sax/SaxParseInterface.h" #include "sax/SaxComposeInterface.h" #include "string/String.h" #include "string/LinearString.h" #include "string/CyclicString.h" #include "string/Epsilon.h" #include "factory/XmlDataFactory.hpp" #include "alphabet/Symbol.h" #include "alphabet/LabeledSymbol.h" #include "alphabet/BlankSymbol.h" #include <primitive/Character.h> #include <container/ObjectsSet.h> CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ( StringTest, "string" ); CPPUNIT_TEST_SUITE_REGISTRATION ( StringTest ); void StringTest::setUp ( ) { } void StringTest::tearDown ( ) { } void StringTest::testCopyConstruct ( ) { string::LinearString < > linearString; linearString.accessComponent < string::GeneralAlphabet > ( ).set( { DefaultSymbolType ( "1" ), DefaultSymbolType ( "2" ), DefaultSymbolType ( "3" ) } ); linearString.setContent ( { DefaultSymbolType ( "1" ), DefaultSymbolType ( "2" ), DefaultSymbolType ( "1" ) } ); string::String string ( linearString ); string::String string2 ( string ); CPPUNIT_ASSERT ( string == string2 ); string::String string3 ( std::move ( string ) ); CPPUNIT_ASSERT ( string2 == string3 ); } void StringTest::testXMLParser ( ) { string::LinearString < > linearString; linearString.accessComponent < string::GeneralAlphabet > ( ).set( { DefaultSymbolType ( "1" ), DefaultSymbolType ( "2" ), DefaultSymbolType ( "3" ) } ); linearString.setContent ( { DefaultSymbolType ( "1" ), DefaultSymbolType ( "2" ), DefaultSymbolType ( "1" ) } ); string::String string ( linearString ); { ext::deque < sax::Token > tokens = alib::XmlDataFactory::toTokens ( string ); std::string tmp; sax::SaxComposeInterface::printMemory ( tmp, tokens ); std::cout << tmp << std::endl; ext::deque < sax::Token > tokens2; sax::SaxParseInterface::parseMemory ( tmp, tokens2 ); string::String string2 = alib::XmlDataFactory::fromTokens ( std::move( tokens2 ) ); CPPUNIT_ASSERT ( string == string2 ); } { std::string tmp = alib::XmlDataFactory::toString ( string ); std::cout << tmp << std::endl; string::String string2 = alib::XmlDataFactory::fromString ( tmp ); CPPUNIT_ASSERT ( string == string2 ); } } void StringTest::testStringInMap ( ) { ext::map < ext::variant < string::Epsilon < >, int >, int > testMap; ext::variant < string::Epsilon < >, int > epsVar { string::Epsilon < > { } }; CPPUNIT_ASSERT ( string::Epsilon < >::EPSILON == epsVar.get < string::Epsilon < > > ( ) ); CPPUNIT_ASSERT ( epsVar.get < string::Epsilon < > > ( ) == string::Epsilon < >::EPSILON ); std::pair < ext::variant < string::Epsilon < >, int >, int > epsVarPair = std::make_pair ( epsVar, 10 ); CPPUNIT_ASSERT ( string::Epsilon < >::EPSILON == epsVarPair.first.get < string::Epsilon < > > ( ) ); CPPUNIT_ASSERT ( epsVarPair.first.get < string::Epsilon < > > ( ) == string::Epsilon < >::EPSILON ); testMap.insert ( std::make_pair ( ext::variant < string::Epsilon < >, int > { string::Epsilon < > { } }, 10 ) ); CPPUNIT_ASSERT ( testMap.find ( ext::variant < string::Epsilon < >, int > { string::Epsilon < > { } } ) != testMap.end ( ) ); for ( const auto & entry : testMap ) { CPPUNIT_ASSERT ( entry.first.is < string::Epsilon < > > ( ) ); if ( entry.first.is < string::Epsilon < > > ( ) ) CPPUNIT_ASSERT ( string::Epsilon < >::EPSILON == entry.first.get < string::Epsilon < > > ( ) ); CPPUNIT_ASSERT ( entry.first.get < string::Epsilon < > > ( ) == string::Epsilon < >::EPSILON ); } } void StringTest::testNormalize ( ) { string::LinearString < char > raw ( ext::vector < char > { 'a', 'b' } ); string::String s1 ( raw ); s1.normalize ( ); string::String s2 ( raw ); std::string tmp1 = alib::XmlDataFactory::toString ( s1 ); std::cout << tmp1 << std::endl; string::String s1x = alib::XmlDataFactory::fromString ( tmp1 ); std::string tmp2 = alib::XmlDataFactory::toString ( s2 ); std::cout << tmp2 << std::endl; string::String s2x = alib::XmlDataFactory::fromString ( tmp2 ); CPPUNIT_ASSERT ( s1x == s2x ); } void StringTest::testNormalize2 ( ) { string::LinearString < alib::Object > raw ( ext::vector < alib::Object > { alib::Object ( 'a' ), alib::Object ( 'b' ) } ); string::String s1 ( raw ); s1.normalize ( ); string::String s2 ( raw ); std::string tmp1 = alib::XmlDataFactory::toString ( s1 ); std::cout << tmp1 << std::endl; string::String s1x = alib::XmlDataFactory::fromString ( tmp1 ); std::string tmp2 = alib::XmlDataFactory::toString ( s2 ); std::cout << tmp2 << std::endl; string::String s2x = alib::XmlDataFactory::fromString ( tmp2 ); CPPUNIT_ASSERT ( s1 == s1x ); CPPUNIT_ASSERT ( s1 == s2x ); } void StringTest::testNormalize3 ( ) { string::LinearString < ext::set < char > > raw ( ext::vector < ext::set < char > > { ext::set < char > { 'a' }, ext::set < char > { 'b' } } ); string::String s1 ( raw ); s1.normalize ( ); string::String s2 ( raw ); std::string tmp1 = alib::XmlDataFactory::toString ( s1 ); std::cout << tmp1 << std::endl; string::String s1x = alib::XmlDataFactory::fromString ( tmp1 ); std::string tmp2 = alib::XmlDataFactory::toString ( s2 ); std::cout << tmp2 << std::endl; string::String s2x = alib::XmlDataFactory::fromString ( tmp2 ); CPPUNIT_ASSERT ( s1x == s2x ); string::LinearString < alib::Object > rawRef ( ext::vector < alib::Object > { alib::Object ( container::ObjectsSet < alib::Object > ( ext::set < alib::Object > { alib::Object ( primitive::Character ( 'a' ) ) } ) ), alib::Object ( container::ObjectsSet < alib::Object > ( ext::set < alib::Object > { alib::Object ( primitive::Character ( 'b' ) ) } ) ) } ); string::String ref ( rawRef ); std::cout << s1x << std::endl; std::cout << ref << std::endl; CPPUNIT_ASSERT ( s1x == ref ); }