mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Unit Tests - Complete Att unit tests
- Covers parsing, composition.
This commit is contained in:
parent
ed685a55ce
commit
766c2d3620
3 changed files with 61 additions and 36 deletions
12
src/Att.cpp
12
src/Att.cpp
|
@ -100,6 +100,9 @@ bool Att::parse (Nibbler& n)
|
|||
|
||||
if (n.getUntilOneOf (".:", mName))
|
||||
{
|
||||
if (mName.length () == 0)
|
||||
throw std::string ("Missing attribute name");
|
||||
|
||||
while (n.skip ('.'))
|
||||
{
|
||||
std::string mod;
|
||||
|
@ -113,8 +116,15 @@ bool Att::parse (Nibbler& n)
|
|||
{
|
||||
if (n.getQuoted ('"', mValue))
|
||||
return true;
|
||||
else if (n.getUntil (' ', mValue))
|
||||
|
||||
// This is here to tolerate unquoted values.
|
||||
// Consider removing this for a stricter parse.
|
||||
if (n.getUntil (' ', mValue))
|
||||
{
|
||||
dequote (mValue);
|
||||
decode (mValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
throw std::string ("Missing attribute value");
|
||||
}
|
||||
|
|
|
@ -212,7 +212,7 @@ bool Nibbler::skipAllOneOf (const std::string& chars)
|
|||
bool Nibbler::getQuoted (char c, std::string& result)
|
||||
{
|
||||
std::string::size_type start = mCursor;
|
||||
if (start < mInput.length () - 1 && mInput[start] == c)
|
||||
if (start < mInput.length () && mInput[start] == c)
|
||||
{
|
||||
++start;
|
||||
if (start < mInput.length ())
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest t (33);
|
||||
UnitTest t (36);
|
||||
|
||||
Att a1 ("name", "value");
|
||||
t.is (a1.name (), "name", "Att::Att (name, value), Att.name");
|
||||
|
@ -66,85 +66,100 @@ int main (int argc, char** argv)
|
|||
|
||||
// Att::addMod
|
||||
bool good = true;
|
||||
try {a6.addMod ("is");} catch (...) {t.fail ("Att::addMod (is)"); good = false;}
|
||||
if (good) t.pass ("Att::addMod (is)");
|
||||
try {a6.addMod ("is");} catch (...) {good = false;}
|
||||
t.ok (good, "Att::addMod (is)");
|
||||
|
||||
good = true;
|
||||
try {a6.addMod (Mod ("fartwizzle"));} catch (...) {t.pass ("Att::addMod (fartwizzle) failed"); good = false;}
|
||||
if (good) t.fail ("Att::addMod (fartwizzle)");
|
||||
try {a6.addMod (Mod ("fartwizzle"));} catch (...) {good = false;}
|
||||
t.notok (good, "Att::addMod (fartwizzle)");
|
||||
|
||||
// Att::parse
|
||||
Nibbler n ("");
|
||||
Att a7;
|
||||
good = true;
|
||||
try {a7.parse (n);} catch (...) {t.pass ("Att::compose () -> throw"); good = false;}
|
||||
if (good) t.fail ("Att::composeF4 () -> throw");
|
||||
try {a7.parse (n);} catch (...) {good = false;}
|
||||
t.notok (good, "Att::parse () -> throw");
|
||||
|
||||
n = Nibbler ("name:value");
|
||||
// TODO throws here -->
|
||||
a7.parse (n);
|
||||
t.is (a7.composeF4 (), "name:\"value\"", "Att::composeF4 (name:value)");
|
||||
t.is (a7.composeF4 (), "name:\"value\"",
|
||||
"Att::parse (name:value)");
|
||||
|
||||
n = Nibbler ("name:\"value\"");
|
||||
a7.parse (n);
|
||||
t.is (a7.composeF4 (), "name:\"value\"", "Att::composeF4 (name:\"value\")");
|
||||
t.is (a7.composeF4 (), "name:\"value\"",
|
||||
"Att::parse (name:\"value\")");
|
||||
|
||||
n = Nibbler ("name:\"one two\"");
|
||||
a7.parse (n);
|
||||
t.is (a7.composeF4 (), "name:\"one two\"", "Att::composeF4 (name:\"one two\")");
|
||||
t.is (a7.composeF4 (), "name:\"one two\"",
|
||||
"Att::parse (name:\"one two\")");
|
||||
|
||||
n = Nibbler ("name:\""\"");
|
||||
a7.parse (n);
|
||||
t.is (a7.composeF4 (), "name:\""\"", "Att::composeF4 (name:\""\")");
|
||||
t.is (a7.composeF4 (), "name:\""\"",
|
||||
"Att::parse (name:\""\")");
|
||||
|
||||
n = Nibbler ("name:\"&tab;",&open;&close;:\"");
|
||||
a7.parse (n);
|
||||
t.is (a7.composeF4 (), "name:\"&tab;",&open;&close;:\"",
|
||||
"Att::composeF4 (name:\"&tab;",&open;&close;:\")");
|
||||
"Att::parse (name:\"&tab;",&open;&close;:\")");
|
||||
|
||||
n = Nibbler ("total gibberish");
|
||||
a7.parse (n);
|
||||
t.is (a7.composeF4 (), "", "Att::composeF4 (total gibberish)");
|
||||
good = true;
|
||||
try {a7.parse (n);} catch (...) {good = false;}
|
||||
t.notok (good, "Att::parse (total gibberish)");
|
||||
|
||||
n = Nibbler ("malformed");
|
||||
a7.parse (n);
|
||||
t.is (a7.composeF4 (), "", "Att::composeF4 (malformed)");
|
||||
good = true;
|
||||
try {a7.parse (n);} catch (...) {good = false;}
|
||||
t.notok (good, "Att::parse (malformed)");
|
||||
|
||||
n = Nibbler (":malformed");
|
||||
a7.parse (n);
|
||||
t.is (a7.composeF4 (), "", "Att::composeF4 (:malformed)");
|
||||
good = true;
|
||||
try {a7.parse (n);} catch (...) {good = false;}
|
||||
t.notok (good, "Att::parse (:malformed)");
|
||||
|
||||
n = Nibbler (":\"\"");
|
||||
a7.parse (n);
|
||||
t.is (a7.composeF4 (), "", "Att::composeF4 (:\"\")");
|
||||
good = true;
|
||||
try {a7.parse (n);} catch (...) {good = false;}
|
||||
t.notok (good, "Att::parse (:\"\")");
|
||||
|
||||
n = Nibbler (":\"");
|
||||
a7.parse (n);
|
||||
t.is (a7.composeF4 (), "", "Att::composeF4 (:\")");
|
||||
good = true;
|
||||
try {a7.parse (n);} catch (...) {good = false;}
|
||||
t.notok (good, "Att::parse (:\")");
|
||||
|
||||
n = Nibbler ("name:");
|
||||
a7.parse (n);
|
||||
t.is (a7.composeF4 (), "", "Att::composeF4 (name:)");
|
||||
good = true;
|
||||
try {a7.parse (n);} catch (...) {good = false;}
|
||||
t.notok (good, "Att::parse (name:)");
|
||||
|
||||
n = Nibbler ("name:\"value");
|
||||
a7.parse (n);
|
||||
t.is (a7.composeF4 (), "name:\"value\"", "Att::composeF4 (name:\"value)");
|
||||
good = true;
|
||||
try {a7.parse (n);} catch (...) {good = false;}
|
||||
t.ok (good, "Att::parse (name:\"value)");
|
||||
t.is (a7.composeF4 (), "name:\"value\"", "Att::composeF4 -> name:\"value\"");
|
||||
|
||||
n = Nibbler ("name:value\"");
|
||||
a7.parse (n);
|
||||
t.is (a7.composeF4 (), "name:\"value\"", "Att::composeF4 (name:value\")");
|
||||
good = true;
|
||||
try {a7.parse (n);} catch (...) {good = false;}
|
||||
t.ok (good, "Att::parse (name:value\")");
|
||||
t.is (a7.composeF4 (), "name:\"value\"", "Att::composeF4 -> name:\"value\"");
|
||||
|
||||
n = Nibbler ("name:val\"ue");
|
||||
a7.parse (n);
|
||||
t.is (a7.composeF4 (), "name:\"value\"", "Att::composeF4 (name:val\"ue)");
|
||||
good = true;
|
||||
try {a7.parse (n);} catch (...) {good = false;}
|
||||
t.ok (good, "Att::parse (name:val\"ue)");
|
||||
t.is (a7.composeF4 (), "name:\"value\"", "Att::composeF4 -> name:\"value\"");
|
||||
|
||||
n = Nibbler ("name:\"\"va\"\"\"\"\"lu\"\"\"e\"\"");
|
||||
a7.parse (n);
|
||||
t.is (a7.composeF4 (), "name:\"value\"", "Att::composeF4 (name:\"\"va\"\"\"\"\"lu\"\"\"e\"\")");
|
||||
|
||||
n = Nibbler ("name\"");
|
||||
a7.parse (n);
|
||||
t.is (a7.composeF4 (), "", "Att::composeF4 (name\")");
|
||||
good = true;
|
||||
try {a7.parse (n);} catch (...) {good = false;}
|
||||
t.notok (good, "Att::parse (name\")");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue