mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Enhancement - Task::operator==
- Implemented Task::operator==. - Implemented unit tests.
This commit is contained in:
parent
a56eeb9ec2
commit
1cfe879409
3 changed files with 24 additions and 1 deletions
15
src/Task.cpp
15
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.
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue