diff --git a/src/Task.cpp b/src/Task.cpp index 1fb9c5098..52b95a3a8 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -59,6 +59,21 @@ Task& Task::operator= (const Task& other) return *this; } +//////////////////////////////////////////////////////////////////////////////// +// The uuid and id attributes must be exempt for comparison. +bool Task::operator== (const Task& other) +{ + if (size () != other.size ()) + return false; + + foreach (att, *this) + if (att->first != "uuid") + if (att->second.value () != other.get (att->first)) + return false; + + return true; +} + //////////////////////////////////////////////////////////////////////////////// // Attempt an FF4 parse first, using Record::parse, and in the event of an error // try a legacy parse (F3, FF2). Note that FF1 is no longer supported. diff --git a/src/Task.h b/src/Task.h index fbe7d37e9..6e51f3e4b 100644 --- a/src/Task.h +++ b/src/Task.h @@ -38,6 +38,7 @@ public: Task (); // Default constructor Task (const Task&); // Copy constructor Task& operator= (const Task&); // Assignment operator + bool operator== (const Task&); // Comparison operator Task (const std::string&); // Parse ~Task (); // Destructor diff --git a/src/tests/t.t.cpp b/src/tests/t.t.cpp index e93b09dd5..26b585db8 100644 --- a/src/tests/t.t.cpp +++ b/src/tests/t.t.cpp @@ -32,7 +32,7 @@ Context context; //////////////////////////////////////////////////////////////////////////////// int main (int argc, char** argv) { - UnitTest test (34); + UnitTest test (36); test.is ((int)Task::textToStatus ("pending"), (int)Task::pending, "textToStatus pending"); test.is ((int)Task::textToStatus ("completed"), (int)Task::completed, "textToStatus completed"); @@ -146,6 +146,13 @@ TODO Task::*Annotation* */ + // Task::operator== + Task left ("[one:1 two:2 three:3]"); + Task right (left); + test.ok (left == right, "left == right -> true"); + left.set ("one", "1.0"); + test.notok (left == right, "left == right -> false"); + return 0; }