mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Parsing
- Integrated modified Nibbler and test code from kronisk. These changes make both test and Nibbler standalone objects, with configurable features.
This commit is contained in:
parent
a262d41828
commit
fb38dca1db
4 changed files with 74 additions and 12 deletions
|
@ -26,8 +26,10 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <Context.h>
|
||||
#include <Date.h>
|
||||
#include <Nibbler.h>
|
||||
#ifdef NIBBLER_FEATURE_DATE
|
||||
#include <Date.h>
|
||||
#endif
|
||||
#include <test.h>
|
||||
|
||||
Context context;
|
||||
|
@ -35,7 +37,19 @@ Context context;
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
#ifdef NIBBLER_FEARURE_DATE
|
||||
#ifdef NIBBLER_FEATURE_REGEX
|
||||
UnitTest t (292);
|
||||
#else
|
||||
UnitTest t (268);
|
||||
#endif
|
||||
#else
|
||||
#ifdef NIBBLER_FEATURE_REGEX
|
||||
UnitTest t (242);
|
||||
#else
|
||||
UnitTest t (218);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -44,7 +58,10 @@ int main (int argc, char** argv)
|
|||
int i;
|
||||
double d;
|
||||
time_t ti;
|
||||
|
||||
#ifdef NIBBLER_FEATURE_DATE
|
||||
Date dt;
|
||||
#endif
|
||||
std::vector <std::string> options;
|
||||
|
||||
// Make sure the nibbler behaves itself with trivial input.
|
||||
|
@ -65,7 +82,9 @@ int main (int argc, char** argv)
|
|||
t.notok (n.getUntilEOL (s), "trivial: getUntilEOL");
|
||||
t.notok (n.getUntilEOS (s), "trivial: getUntilEOS");
|
||||
t.notok (n.getDateISO (ti), "trivial: getDateISO");
|
||||
#ifdef NIBBLER_FEATURE_DATE
|
||||
t.notok (n.getDate ("YYYYMMDD", ti), "trivial: getDate");
|
||||
#endif
|
||||
t.notok (n.getOneOf (options, s), "trivial: getOneOf");
|
||||
t.ok (n.depleted (), "trivial: depleted");
|
||||
|
||||
|
@ -81,6 +100,7 @@ int main (int argc, char** argv)
|
|||
t.notok (n.getUntil (' ', s), " '' : getUntil (' ') -> false");
|
||||
t.ok (n.depleted (), " '' : depleted () -> true");
|
||||
|
||||
#ifdef NIBBLER_FEATURE_REGEX
|
||||
// bool getUntilRx (const std::string&, std::string&);
|
||||
t.diag ("Nibbler::getUntilRx");
|
||||
n = Nibbler ("one two");
|
||||
|
@ -95,6 +115,7 @@ int main (int argc, char** argv)
|
|||
t.ok (n.getUntilRx ("$", s), " 'two' : getUntilRx ('$') -> true");
|
||||
t.is (s, "two", " 'two' : getUntilRx ('$') -> 'two'");
|
||||
t.ok (n.depleted (), " '' : depleted () -> true");
|
||||
#endif
|
||||
|
||||
// bool getUntilOneOf (const std::string&, std::string&);
|
||||
t.diag ("Nibbler::getUntilOneOf");
|
||||
|
@ -170,6 +191,7 @@ int main (int argc, char** argv)
|
|||
t.is (s, "foo", " 'foo' : getUntilEOS () -> 'foo'");
|
||||
t.ok (n.depleted (), " '' : depleted () -> true");
|
||||
|
||||
#ifdef NIBBLER_FEATURE_REGEX
|
||||
// bool skipRx (const std::string&);
|
||||
t.diag ("Nibbler::skipRx");
|
||||
n = Nibbler ("one two");
|
||||
|
@ -178,6 +200,7 @@ int main (int argc, char** argv)
|
|||
t.ok (n.skipRx ("e+"), " 'e two' : skipRx ('e+') -> true");
|
||||
t.ok (n.skipRx ("...."), " ' two' : skipRx ('....') -> true");
|
||||
t.ok (n.depleted (), " '' : depleted () -> true");
|
||||
#endif
|
||||
|
||||
// bool getQuoted (char, std::string&);
|
||||
t.diag ("Nibbler::getQuoted");
|
||||
|
@ -280,6 +303,7 @@ int main (int argc, char** argv)
|
|||
t.ok (n.getLiteral ("bar"), " 'bar' : getLiteral ('bar') -> true");
|
||||
t.ok (n.depleted (), " '' : depleted () -> true");
|
||||
|
||||
#ifdef NIBBLER_FEATURE_REGEX
|
||||
// bool getRx (const std::string&, std::string&);
|
||||
t.diag ("Nibbler::getRx");
|
||||
n = Nibbler ("one two three");
|
||||
|
@ -293,6 +317,7 @@ int main (int argc, char** argv)
|
|||
t.ok (n.getRx ("th...", s), " 'three' : getRx ('th...') -> true");
|
||||
t.is (s, "three", " 'three' : getRx ('th...') -> 'three'");
|
||||
t.ok (n.depleted (), " '' : depleted () -> true");
|
||||
#endif
|
||||
|
||||
// bool getUUID (std::string&);
|
||||
t.diag ("Nibbler::getUUID");
|
||||
|
@ -321,6 +346,7 @@ int main (int argc, char** argv)
|
|||
t.is (ti, 1234567890, "'20090213T233130Z': getDateISO () -> 1234567890");
|
||||
t.ok (n.depleted (), "depleted");
|
||||
|
||||
#ifdef NIBBLER_FEATURE_DATE
|
||||
// bool getDate (time_t&, const std::string&);
|
||||
t.diag ("Nibbler::getDate");
|
||||
n = Nibbler ("1/1/2008");
|
||||
|
@ -401,6 +427,7 @@ int main (int argc, char** argv)
|
|||
t.is (dt.hour (), 12, "ctor (std::string) -> h");
|
||||
t.is (dt.minute (), 34, "ctor (std::string) -> N");
|
||||
t.is (dt.second (), 56, "ctor (std::string) -> S");
|
||||
#endif
|
||||
|
||||
// bool getOneOf (const std::vector <std::string>&, std::string&);
|
||||
t.diag ("Nibbler::getOneOf");
|
||||
|
|
|
@ -29,9 +29,6 @@
|
|||
#include <iomanip>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <main.h>
|
||||
#include <util.h>
|
||||
#include <text.h>
|
||||
#include <test.h>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -394,9 +391,9 @@ void UnitTest::is (
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
void UnitTest::diag (const std::string& text)
|
||||
{
|
||||
std::string trimmed = trim (text, " \t\n\r\f");
|
||||
|
||||
std::cout << "# " << trimmed << "\n";
|
||||
std::string::size_type start = text.find_first_not_of (" \t\n\r\f");
|
||||
std::string::size_type end = text.find_last_not_of (" \t\n\r\f");
|
||||
std::cout << "# " << text.substr (start, end - start + 1);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue