middle of porting; unstable, don't checkout; refs #1
This commit is contained in:
74
test/tokenizer_test.cxx
Normal file
74
test/tokenizer_test.cxx
Normal file
@@ -0,0 +1,74 @@
|
||||
/** @file
|
||||
|
||||
$Id$
|
||||
|
||||
$Date$
|
||||
$Author$
|
||||
|
||||
@copy © Marc Wäckerlin
|
||||
@license LGPL, see file <a href="license.html">COPYING</a>
|
||||
|
||||
$Log$
|
||||
Revision 1.2 2005/01/07 00:35:17 marc
|
||||
initial version
|
||||
|
||||
Revision 1.1 2004/12/17 16:26:58 marc
|
||||
initial version
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <mrw/tokenizer.hxx>
|
||||
#include <mrw/list.hxx>
|
||||
#include <algorithm>
|
||||
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
|
||||
class TokenizerTest: public CppUnit::TestFixture {
|
||||
public:
|
||||
void CheckNonGreedy() {
|
||||
const std::string aux[] = {"first", "second", "third", "", "fifth"};
|
||||
std::list<std::string> a(aux, aux+sizeof(aux)/sizeof(std::string)), b;
|
||||
mrw::Tokenizer token("first,second,third,,fifth", false, ",");
|
||||
while (token) b<<token();
|
||||
CPPUNIT_ASSERT(equal(a.begin(), a.end(), b.begin()));
|
||||
}
|
||||
void CheckGreedy() {
|
||||
const std::string aux[] = {"Hello", "world", "here", "I", "am"};
|
||||
std::list<std::string> a(aux, aux+sizeof(aux)/sizeof(std::string)), b;
|
||||
mrw::Tokenizer token("Hello world, here I am!", true, " \t\n,.?!");
|
||||
while (token) b<<token();
|
||||
CPPUNIT_ASSERT(equal(a.begin(), a.end(), b.begin()));
|
||||
}
|
||||
void CheckReset() {
|
||||
const std::string aux[] = {"first", "second", "third", "", "fifth"};
|
||||
std::list<std::string> a(aux, aux+sizeof(aux)/sizeof(std::string)), b;
|
||||
mrw::Tokenizer token("first,second,third,,fifth", false, ",");
|
||||
while (token) b<<token();
|
||||
CPPUNIT_ASSERT(equal(a.begin(), a.end(), b.begin()));
|
||||
const std::string aux2[] = {"a", "b", "c", "d", "e"};
|
||||
std::list<std::string> a2(aux2, aux2+sizeof(aux2)/sizeof(std::string)),
|
||||
b2, b3;
|
||||
token.reset("a,b,c,d,e");
|
||||
while (token) b2<<token();
|
||||
CPPUNIT_ASSERT(equal(a2.begin(), a2.end(), b2.begin()));
|
||||
token.reset();
|
||||
while (token) b3<<token();
|
||||
CPPUNIT_ASSERT(equal(a2.begin(), a2.end(), b3.begin()));
|
||||
}
|
||||
CPPUNIT_TEST_SUITE(TokenizerTest);
|
||||
CPPUNIT_TEST(CheckNonGreedy);
|
||||
CPPUNIT_TEST(CheckGreedy);
|
||||
CPPUNIT_TEST(CheckReset);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
};
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(TokenizerTest);
|
||||
|
||||
int main() {
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
||||
return runner.run() ? 0 : 1;
|
||||
}
|
Reference in New Issue
Block a user