- Replaced old Tree-based parser with a faster, leaner parser.
  Currently lacking good error handling and a large test suite.
- Integrated new parser into Task object, for encode/decode.
- Replicated same basic unit tests.  Needs more.
- Fixed bug in handleShell that failed to call the new Context::initialize2.
- Removed debugging code from CmdInstall.
- Implemented format() that does not require width and precision args.
This commit is contained in:
Paul Beckingham 2011-05-20 00:18:36 -04:00
parent 05b3fa0bb6
commit 690fa6e206
8 changed files with 517 additions and 297 deletions

View file

@ -35,30 +35,53 @@ Context context;
////////////////////////////////////////////////////////////////////////////////
int main (int argc, char** argv)
{
UnitTest t (14);
UnitTest t (19);
try
{
// Basic parsing tests.
// j1
std::string input = "{}";
std::cout << "-- j1 -------------------\n"
<< "input: " << input << "\n";
JSON j1 (input);
j1.tree ()->dump ();
std::cout << "# -- j1 -------------------\n"
<< "# input: " << input << "\n";
json::value* root = json::parse (input);
t.ok (root, "j1 parse ok");
if (root)
{
t.diag ("output: " + root->dump ());
delete root;
}
else
t.fail ("j1 parse error");
// j2
input = "{\"name\":123}";
std::cout << "-- j2 -------------------\n"
<< "input: " << input << "\n";
JSON j2 (input);
j2.tree ()->dump ();
std::cout << "# -- j2 -------------------\n"
<< "# input: " << input << "\n";
root = json::parse (input);
t.ok (root, "j2 parse ok");
if (root)
{
t.diag ("output: " + root->dump ());
delete root;
}
else
t.fail ("j2 parse error");
// j3
input = "{\"name\":123, \"array\":[1,2,3.4], \"map\":{\"m1\":\"v1\", \"m2\":\"v2\"}}";
std::cout << "-- j3 -------------------\n"
<< "input: " << input << "\n";
JSON j3 (input);
j3.tree ()->dump ();
std::cout << "# -- j3 -------------------\n"
<< "# input: " << input << "\n";
root = json::parse (input);
t.ok (root, "j3 parse ok");
if (root)
{
t.diag ("output: " + root->dump ());
delete root;
}
else
t.fail ("j3 parse error");
// Sample ticket as a parsing test.
// j4
input = "{\n"
"\"ticket\": { \"type\":\"add\", \"client\":\"taskwarrior 2.x\"},\n"
"\"auth\": { \"user\":\"paul\", \"org\":\"gbf\", \"key\":\".........\",\n"
@ -68,33 +91,39 @@ int main (int argc, char** argv)
" \"project\":\"home\",\n"
" \"due\":\"20101101T000000Z\" }\n"
"}";
std::cout << "-- j4 -------------------\n"
<< "input: " << input << "\n";
JSON j4 (input);
j4.tree ()->dump ();
std::cout << "-------------------------\n";
std::cout << "# -- j4 -------------------\n"
<< "# input: " << input << "\n";
root = json::parse (input);
t.ok (root, "j4 parse ok");
if (root)
{
t.diag ("output: " + root->dump ());
delete root;
}
else
t.fail ("j4 parse error");
// Regular unit tests.
t.is (JSON::encode ("1\b2"), "1\\b2", "JSON::encode \\b -> \\\\b");
t.is (JSON::decode ("1\\b2"), "1\b2", "JSON::decode \\\\b -> \\b");
t.is (json::encode ("1\b2"), "1\\b2", "json::encode \\b -> \\\\b");
t.is (json::decode ("1\\b2"), "1\b2", "json::decode \\\\b -> \\b");
t.is (JSON::encode ("1\n2"), "1\\n2", "JSON::encode \\n -> \\\\n");
t.is (JSON::decode ("1\\n2"), "1\n2", "JSON::decode \\\\n -> \\n");
t.is (json::encode ("1\n2"), "1\\n2", "json::encode \\n -> \\\\n");
t.is (json::decode ("1\\n2"), "1\n2", "json::decode \\\\n -> \\n");
t.is (JSON::encode ("1\r2"), "1\\r2", "JSON::encode \\r -> \\\\r");
t.is (JSON::decode ("1\\r2"), "1\r2", "JSON::decode \\\\r -> \\r");
t.is (json::encode ("1\r2"), "1\\r2", "json::encode \\r -> \\\\r");
t.is (json::decode ("1\\r2"), "1\r2", "json::decode \\\\r -> \\r");
t.is (JSON::encode ("1\t2"), "1\\t2", "JSON::encode \\t -> \\\\t");
t.is (JSON::decode ("1\\t2"), "1\t2", "JSON::decode \\\\t -> \\t");
t.is (json::encode ("1\t2"), "1\\t2", "json::encode \\t -> \\\\t");
t.is (json::decode ("1\\t2"), "1\t2", "json::decode \\\\t -> \\t");
t.is (JSON::encode ("1\\2"), "1\\\\2", "JSON::encode \\ -> \\\\");
t.is (JSON::decode ("1\\\\2"), "1\\2", "JSON::decode \\\\ -> \\");
t.is (json::encode ("1\\2"), "1\\\\2", "json::encode \\ -> \\\\");
t.is (json::decode ("1\\\\2"), "1\\2", "json::decode \\\\ -> \\");
t.is (JSON::encode ("1\x2"), "1\x2", "JSON::encode \\x -> \\x (NOP)");
t.is (JSON::decode ("1\x2"), "1\x2", "JSON::decode \\x -> \\x (NOP)");
t.is (json::encode ("1\x2"), "1\x2", "json::encode \\x -> \\x (NOP)");
t.is (json::decode ("1\x2"), "1\x2", "json::decode \\x -> \\x (NOP)");
t.is (JSON::encode ("1€2"), "1€2", "JSON::encode € -> €");
t.is (JSON::decode ("1\\u20ac2"), "1€2", "JSON::decode \\u20ac -> €");
t.is (json::encode ("1€2"), "1€2", "json::encode € -> €");
t.is (json::decode ("1\\u20ac2"), "1€2", "json::decode \\u20ac -> €");
/*
{
@ -131,10 +160,17 @@ int main (int argc, char** argv)
}
*/
input = "{\"ticket\":{\"type\":\"synch\",\"client\":\"taskd-test-suite 1.0\"},\"synch\":{\"user\":{\"data\":[{\"uuid\":\"11111111-1111-1111-1111-111111111111\",\"status\":\"pending\",\"description\":\"This is a test\",\"entry\":\"20110111T124000Z\"}],\"synch\":\"key\"}},\"auth\":{\"org\":\"gbf\",\"user\":\"Paul Beckingham\",\"key\":\"K\",\"locale\":\"en-US\"}}";
std::cout << "-- j4 -------------------\n"
<< "input: " << input << "\n";
JSON j5 (input);
j5.tree ()->dump ();
std::cout << "# -- j5 -------------------\n"
<< "# input: " << input << "\n";
root = json::parse (input);
t.ok (root, "j5 parse ok");
if (root)
{
t.diag ("output: " + root->dump ());
delete root;
}
else
t.fail ("j5 parse error");
}
catch (std::string& e) {t.diag (e);}