diff --git a/src/Task.cpp b/src/Task.cpp index a70c1665b..b5d22ed63 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -475,6 +475,7 @@ void Task::parseJSON (const std::string& line) { // If the attribute is a recognized column. std::string type = Task::attributes[i->first]; + if (type != "") { // Any specified id is ignored. diff --git a/test/t3.t.cpp b/test/t3.t.cpp index c250e42df..d9746d7e2 100644 --- a/test/t3.t.cpp +++ b/test/t3.t.cpp @@ -36,7 +36,12 @@ Context context; //////////////////////////////////////////////////////////////////////////////// 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; try {Task t1 ("{}");} @@ -44,10 +49,30 @@ int main (int argc, char** argv) t.ok (good, "Task::Task ('{}')"); 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;} t.ok (good, "Task::Task ('{}')"); + // 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; }