Unit Tests
- Added unit test to ensure correct F4 and JSON parse/compose.
This commit is contained in:
@@ -475,6 +475,7 @@ void Task::parseJSON (const std::string& line)
|
|||||||
{
|
{
|
||||||
// If the attribute is a recognized column.
|
// If the attribute is a recognized column.
|
||||||
std::string type = Task::attributes[i->first];
|
std::string type = Task::attributes[i->first];
|
||||||
|
|
||||||
if (type != "")
|
if (type != "")
|
||||||
{
|
{
|
||||||
// Any specified id is ignored.
|
// Any specified id is ignored.
|
||||||
|
|||||||
@@ -36,7 +36,12 @@ Context context;
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int main (int argc, char** argv)
|
int main (int argc, char** argv)
|
||||||
{
|
{
|
||||||
UnitTest t (2);
|
UnitTest t (9);
|
||||||
|
|
||||||
|
Task::attributes["description"] = "string";
|
||||||
|
Task::attributes["entry"] = "date";
|
||||||
|
Task::attributes["tags"] = "string";
|
||||||
|
Task::attributes["uuid"] = "string";
|
||||||
|
|
||||||
bool good = true;
|
bool good = true;
|
||||||
try {Task t1 ("{}");}
|
try {Task t1 ("{}");}
|
||||||
@@ -44,10 +49,30 @@ int main (int argc, char** argv)
|
|||||||
t.ok (good, "Task::Task ('{}')");
|
t.ok (good, "Task::Task ('{}')");
|
||||||
|
|
||||||
good = true;
|
good = true;
|
||||||
try {Task t2 ("{\"uuid\":\"00000000-0000-0000-000000000001\",\"description\":\"foo\",\"entry\":1234567890}");}
|
try {Task t2 ("{\"uuid\":\"00000000-0000-0000-000000000001\",\"description\":\"foo\",\"entry\":\"1234567890\"}");}
|
||||||
catch (const std::string& e){t.diag (e); good = false;}
|
catch (const std::string& e){t.diag (e); good = false;}
|
||||||
t.ok (good, "Task::Task ('{<minimal>}')");
|
t.ok (good, "Task::Task ('{<minimal>}')");
|
||||||
|
|
||||||
|
// Verify tag handling is correct between F4 and JSON.
|
||||||
|
Task t3;
|
||||||
|
t3.set ("entry", "20130602T224000Z");
|
||||||
|
t3.set ("description", "DESC");
|
||||||
|
t3.addTag ("tag1");
|
||||||
|
t.is (t3.composeF4 (), "[description:\"DESC\" entry:\"20130602T224000Z\" tags:\"tag1\"]", "F4 good");
|
||||||
|
t.is (t3.composeJSON (), "{\"description\":\"DESC\",\"entry\":\"20130602T224000Z\",\"tags\":[\"tag1\"]}", "JSON good");
|
||||||
|
|
||||||
|
t3.addTag ("tag2");
|
||||||
|
t.is (t3.composeF4 (), "[description:\"DESC\" entry:\"20130602T224000Z\" tags:\"tag1,tag2\"]", "F4 good");
|
||||||
|
t.is (t3.composeJSON (), "{\"description\":\"DESC\",\"entry\":\"20130602T224000Z\",\"tags\":[\"tag1\",\"tag2\"]}", "JSON good");
|
||||||
|
|
||||||
|
good = true;
|
||||||
|
Task t4;
|
||||||
|
try {t4 = Task ("{\"description\":\"DESC\",\"entry\":\"20130602T224000Z\",\"tags\":[\"tag1\",\"tag2\"]}");}
|
||||||
|
catch (const std::string& e){t.diag (e); good = false;}
|
||||||
|
t.ok (good, "Task::Task ('{two tags}')");
|
||||||
|
t.is (t4.composeF4 (), "[description:\"DESC\" entry:\"1370212800\" tags:\"tag1,tag2\"]", "F4 good");
|
||||||
|
t.is (t4.composeJSON (), "{\"description\":\"DESC\",\"entry\":\"20130602T224000Z\",\"tags\":[\"tag1\",\"tag2\"]}", "JSON good");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user