From bb58b796fdbca003eb40b291d6384809b98f3ff8 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 23 Oct 2015 10:13:38 -0400 Subject: [PATCH] Task Data Parsing - Improved the handling when parsing blank lines and empty task in the data, so that instead of the message: Taskwarrior no longer supports file format 1, originally used between 27 November 2006 and 31 December 2007. We now see: Unrecognized Taskwarrior file format or blank line in data. - Merged t2.t.cpp into t.t.cpp. --- src/Task.cpp | 8 ++-- src/l10n/eng-USA.h | 2 +- src/l10n/fra-FRA.h | 2 +- src/l10n/jpn-JPN.h | 2 +- test/.gitignore | 1 - test/CMakeLists.txt | 2 +- test/t.t.cpp | 70 ++++++++++++++++++++++++++-- test/t2.t.cpp | 111 -------------------------------------------- 8 files changed, 73 insertions(+), 125 deletions(-) delete mode 100644 test/t2.t.cpp diff --git a/src/Task.cpp b/src/Task.cpp index 2cf96ce34..868d14038 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -1676,10 +1676,10 @@ int Task::determineVersion (const std::string& line) // X [tags] [attributes] description\n // // Scan for the first character being either the bracket or X. - else if (line.find ("X [") == 0 || - line.find ("uuid") == std::string::npos || - (line[0] == '[' && - line.substr (line.length () - 1, 1) != "]")) + else if (line.find ("X [") == 0 || + (line[0] == '[' && + line.substr (line.length () - 1, 1) != "]" && + line.length () > 3)) return 1; // Version 5? diff --git a/src/l10n/eng-USA.h b/src/l10n/eng-USA.h index 2e45d0a82..54aaae84b 100644 --- a/src/l10n/eng-USA.h +++ b/src/l10n/eng-USA.h @@ -839,7 +839,7 @@ #define STRING_TASK_NO_FF1 "Taskwarrior no longer supports file format 1, originally used between 27 November 2006 and 31 December 2007." #define STRING_TASK_NO_FF2 "Taskwarrior no longer supports file format 2, originally used between 1 January 2008 and 12 April 2009." #define STRING_TASK_NO_FF3 "Taskwarrior no longer supports file format 3, originally used between 23 March 2009 and 16 May 2009." -#define STRING_TASK_PARSE_UNREC_FF "Unrecognized Taskwarrior file format." +#define STRING_TASK_PARSE_UNREC_FF "Unrecognized Taskwarrior file format or blank line in data." #define STRING_TASK_DEPEND_ITSELF "A task cannot be dependent on itself." #define STRING_TASK_DEPEND_MISS_CREA "Could not create a dependency on task {1} - not found." #define STRING_TASK_DEPEND_MISS_DEL "Could not delete a dependency on task {1} - not found." diff --git a/src/l10n/fra-FRA.h b/src/l10n/fra-FRA.h index 91900812b..3b0746272 100644 --- a/src/l10n/fra-FRA.h +++ b/src/l10n/fra-FRA.h @@ -841,7 +841,7 @@ #define STRING_TASK_NO_FF1 "Taskwarrior no longer supports file format 1, originally used between 27 November 2006 and 31 December 2007." #define STRING_TASK_NO_FF2 "Taskwarrior no longer supports file format 2, originally used between 1 January 2008 and 12 April 2009." #define STRING_TASK_NO_FF3 "Taskwarrior no longer supports file format 3, originally used between 23 March 2009 and 16 May 2009." -#define STRING_TASK_PARSE_UNREC_FF "Unrecognized taskwarrior file format." +#define STRING_TASK_PARSE_UNREC_FF "Unrecognized Taskwarrior file format or blank line in data." #define STRING_TASK_DEPEND_ITSELF "A task cannot be dependent on itself." #define STRING_TASK_DEPEND_MISS_CREA "Could not create a dependency on task {1} - not found." #define STRING_TASK_DEPEND_MISS_DEL "Could not delete a dependency on task {1} - not found." diff --git a/src/l10n/jpn-JPN.h b/src/l10n/jpn-JPN.h index a240fe6f6..0b6a90b89 100644 --- a/src/l10n/jpn-JPN.h +++ b/src/l10n/jpn-JPN.h @@ -841,7 +841,7 @@ #define STRING_TASK_NO_FF1 "Taskwarrior no longer supports file format 1, originally used between 27 November 2006 and 31 December 2007." #define STRING_TASK_NO_FF2 "Taskwarrior no longer supports file format 2, originally used between 1 January 2008 and 12 April 2009." #define STRING_TASK_NO_FF3 "Taskwarrior no longer supports file format 3, originally used between 23 March 2009 and 16 May 2009." -#define STRING_TASK_PARSE_UNREC_FF "Unrecognized taskwarrior file format." +#define STRING_TASK_PARSE_UNREC_FF "Unrecognized Taskwarrior file format or blank line in data." #define STRING_TASK_DEPEND_ITSELF "A task cannot be dependent on itself." #define STRING_TASK_DEPEND_MISS_CREA "Could not create a dependency on task {1} - not found." #define STRING_TASK_DEPEND_MISS_DEL "Could not delete a dependency on task {1} - not found." diff --git a/test/.gitignore b/test/.gitignore index 7b83e1fb3..46a180944 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -20,7 +20,6 @@ msg.t nibbler.t rx.t t.t -t2.t t3.t taskmod.t tdb2.t diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 04d808aae..830dda4c8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -10,7 +10,7 @@ include_directories (${CMAKE_SOURCE_DIR} ${TASK_INCLUDE_DIRS}) set (test_SRCS autocomplete.t col.t color.t config.t fs.t i18n.t json.t list.t - msg.t nibbler.t rx.t t.t t2.t t3.t tdb2.t text.t utf8.t util.t + msg.t nibbler.t rx.t t.t t3.t tdb2.t text.t utf8.t util.t view.t json_test lexer.t iso8601d.t iso8601p.t eval.t dates.t variant_add.t variant_and.t variant_cast.t variant_divide.t variant_equal.t variant_exp.t variant_gt.t variant_gte.t diff --git a/test/t.t.cpp b/test/t.t.cpp index 8f863c22e..3f19ec1c5 100644 --- a/test/t.t.cpp +++ b/test/t.t.cpp @@ -34,7 +34,7 @@ Context context; //////////////////////////////////////////////////////////////////////////////// int main (int, char**) { - UnitTest test (23); + UnitTest test (40); // Ensure environment has no influence. unsetenv ("TASKDATA"); @@ -151,11 +151,71 @@ TODO Task::decode left.set ("one", "1.0"); test.notok (left == right, "left == right -> false"); - // Task::validate - Task bad ("[entry:1000000001 start:1000000000]"); + //////////////////////////////////////////////////////////////////////////////// + Task task; + + // (blank) good = true; - try { bad.validate (); } catch (...) { good = false; } - test.notok (good, "Task::validate entry <= start"); + try {task = Task ("");} + catch (const std::string& e){test.diag (e); good = false;} + test.notok (good, "Task::Task ('')"); + + // [] + good = true; + try {task = Task ("[]");} + catch (const std::string& e){test.diag (e); good = false;} + test.notok (good, "Task::Task ('[]')"); + + // [name:"value"] + good = true; + try {task = Task ("[name:\"value\"]");} + catch (const std::string& e){test.diag (e); good = false;} + test.ok (good, "Task::Task ('[name:\"value\"]')"); + test.is (task.get ("name"), "value", "name=value"); + + // [name:"one two"] + good = true; + try {task = Task ("[name:\"one two\"]");} + catch (const std::string& e){test.diag (e); good = false;} + test.ok (good, "Task::Task ('[name:\"one two\"]')"); + test.is (task.get ("name"), "one two", "name=one two"); + + // [one:two three:four] + good = true; + try {task = Task ("[one:\"two\" three:\"four\"]");} + catch (const std::string& e){test.diag (e); good = false;} + test.ok (good, "Task::Task ('[one:\"two\" three:\"four\"]')"); + test.is (task.get ("one"), "two", "one=two"); + test.is (task.get ("three"), "four", "three=four"); + + // Task::set + task.clear (); + task.set ("name", "value"); + test.is (task.composeF4 (), "[name:\"value\"]", "Task::set"); + + // Task::has + test.ok (task.has ("name"), "Task::has"); + test.notok (task.has ("woof"), "Task::has not"); + + // Task::get_int + task.set ("one", 1); + test.is (task.composeF4 (), "[name:\"value\" one:\"1\"]", "Task::set"); + test.is (task.get_int ("one"), 1, "Task::get_int"); + + // Task::get_ulong + task.set ("two", "4294967295"); + test.is (task.composeF4 (), "[name:\"value\" one:\"1\" two:\"4294967295\"]", "Task::set"); + test.is ((size_t)task.get_ulong ("two"), (size_t)4294967295UL, "Task::get_ulong"); + + // Task::remove + task.remove ("one"); + task.remove ("two"); + test.is (task.composeF4 (), "[name:\"value\"]", "Task::remove"); + + // Task::all + test.is (task.size (), (size_t)1, "Task::all size"); + + //////////////////////////////////////////////////////////////////////////////// return 0; } diff --git a/test/t2.t.cpp b/test/t2.t.cpp deleted file mode 100644 index 2c4600576..000000000 --- a/test/t2.t.cpp +++ /dev/null @@ -1,111 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// -// http://www.opensource.org/licenses/mit-license.php -// -//////////////////////////////////////////////////////////////////////////////// - -#include -#include -#include -#include -#include -#include - -Context context; - -//////////////////////////////////////////////////////////////////////////////// -int main (int, char**) -{ - UnitTest t (18); - - // Ensure environment has no influence. - unsetenv ("TASKDATA"); - unsetenv ("TASKRC"); - - // (blank) - bool good = true; - Task task; - - try {task = Task ("");} - catch (const std::string& e){t.diag (e); good = false;} - t.notok (good, "Task::Task ('')"); - - // [] - good = true; - try {task = Task ("[]");} - catch (const std::string& e){t.diag (e); good = false;} - t.notok (good, "Task::Task ('[]')"); - - // [name:"value"] - good = true; - try {task = Task ("[name:\"value\"]");} - catch (const std::string& e){t.diag (e); good = false;} - t.ok (good, "Task::Task ('[name:\"value\"]')"); - t.is (task.get ("name"), "value", "name=value"); - - // [name:"one two"] - good = true; - try {task = Task ("[name:\"one two\"]");} - catch (const std::string& e){t.diag (e); good = false;} - t.ok (good, "Task::Task ('[name:\"one two\"]')"); - t.is (task.get ("name"), "one two", "name=one two"); - - // [one:two three:four] - good = true; - try {task = Task ("[one:\"two\" three:\"four\"]");} - catch (const std::string& e){t.diag (e); good = false;} - t.ok (good, "Task::Task ('[one:\"two\" three:\"four\"]')"); - t.is (task.get ("one"), "two", "one=two"); - t.is (task.get ("three"), "four", "three=four"); - - // Task::set - task.clear (); - task.set ("name", "value"); - t.is (task.composeF4 (), "[name:\"value\"]", "Task::set"); - - // Task::has - t.ok (task.has ("name"), "Task::has"); - t.notok (task.has ("woof"), "Task::has not"); - - // Task::get_int - task.set ("one", 1); - t.is (task.composeF4 (), "[name:\"value\" one:\"1\"]", "Task::set"); - t.is (task.get_int ("one"), 1, "Task::get_int"); - - // Task::get_ulong - task.set ("two", "4294967295"); - t.is (task.composeF4 (), "[name:\"value\" one:\"1\" two:\"4294967295\"]", "Task::set"); - t.is ((size_t)task.get_ulong ("two"), (size_t)4294967295UL, "Task::get_ulong"); - - // Task::remove - task.remove ("one"); - task.remove ("two"); - t.is (task.composeF4 (), "[name:\"value\"]", "Task::remove"); - - // Task::all - t.is (task.size (), (size_t)1, "Task::all size"); - - return 0; -} - -////////////////////////////////////////////////////////////////////////////////