ultimatepp/upptst/StringFind/StringFind.cpp
cxl 5378587029 .upptst
git-svn-id: svn://ultimatepp.org/upp/trunk@7077 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2014-03-23 16:35:44 +00:00

54 lines
1.1 KiB
C++

#include <Core/Core.h>
using namespace Upp;
#define LDUMP(x) DUMP(x)
template <class T>
void Check(T haystack, T needle, int pos)
{
if(haystack.Find(needle) != pos) {
DUMP(haystack);
DUMP(needle);
DUMP(haystack.Find(needle));
NEVER();
}
if(haystack.ReverseFind(needle) != pos) {
DUMP(haystack);
DUMP(needle);
DUMP(haystack.ReverseFind(needle));
NEVER();
}
}
template <class T>
void Check()
{
for(int l = 0; l < 30; l++) {
for(int r = 0; r < 30; r++) {
LOG(l << ":" << r);
for(int nl = 0; nl < 30; nl++)
for(int nr = 0; nr < 30; nr++)
for(int nc = 1; nc < 30; nc++) {
T needle = T('a', nl) + T('x', nc) + T('a', nr);
Check(T('a', l) + needle + T('a', r), needle, l);
Check(T('b', l) + needle + T('c', r), needle, l);
}
}
}
ASSERT(T("test").Find("x") < 0);
}
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
String x("aaaaaxxxxxxxxx");
int pos = x.Find(String("aaaaxxxxxxxxx"));
Check<String>();
Check<WString>();
LOG("Everything OK");
}