mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Enhancement - Mod/Att interaction
- New unit tests for Mod object. - Added new constructors to Mod object for ease of use. - Added Mod handling in Att object. - Added more Att unit tests.
This commit is contained in:
parent
c860d58641
commit
41a6cdea22
8 changed files with 117 additions and 37 deletions
|
@ -126,9 +126,9 @@ std::string Att::composeF4 () const
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Att::addMod (const std::string&)
|
||||
void Att::addMod (const Mod& mod)
|
||||
{
|
||||
throw std::string ("unimplemented Att::addMod");
|
||||
mMods.push_back (mod);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
void parse (const std::string&);
|
||||
std::string composeF4 () const;
|
||||
|
||||
void addMod (const std::string&);
|
||||
void addMod (const Mod&);
|
||||
// TODO Need method to access mods.
|
||||
|
||||
std::string name () const;
|
||||
|
|
66
src/Mod.cpp
66
src/Mod.cpp
|
@ -29,27 +29,33 @@
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Mod::Mod ()
|
||||
: std::string ("")
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Mod::Mod (const char* other)
|
||||
: std::string (other)
|
||||
{
|
||||
if (!valid ())
|
||||
throw std::string ("Unrecognized modifier '") + other + "'";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Mod::Mod (const std::string& other)
|
||||
: std::string (other)
|
||||
{
|
||||
if (!valid ())
|
||||
throw std::string ("Unrecognized modifier '") + other + "'";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Mod::~Mod ()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// before after
|
||||
// not
|
||||
// none any
|
||||
// over under
|
||||
// synth
|
||||
// first last
|
||||
// this
|
||||
// next
|
||||
// is isnt
|
||||
// has hasnt
|
||||
// startswith endswith
|
||||
bool Mod::isValid ()
|
||||
bool Mod::valid ()
|
||||
{
|
||||
if (*this == "before" || *this == "after" ||
|
||||
*this == "not" ||
|
||||
|
@ -70,18 +76,22 @@ bool Mod::isValid ()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Mod::eval (const Mod& other)
|
||||
{
|
||||
// before
|
||||
// after
|
||||
// non
|
||||
// none
|
||||
// any
|
||||
// synth
|
||||
// under
|
||||
// over
|
||||
// first
|
||||
// last
|
||||
// this
|
||||
// next
|
||||
// No modifier means automatic pass.
|
||||
if (*this == "")
|
||||
return true;
|
||||
|
||||
// TODO before
|
||||
// TODO after
|
||||
// TODO not
|
||||
// TODO none
|
||||
// TODO any
|
||||
// TODO synth
|
||||
// TODO under
|
||||
// TODO over
|
||||
// TODO first
|
||||
// TODO last
|
||||
// TODO this
|
||||
// TODO next
|
||||
|
||||
if (*this == ".is")
|
||||
return *this == other ? true : false;
|
||||
|
@ -89,10 +99,10 @@ bool Mod::eval (const Mod& other)
|
|||
if (*this == ".isnt")
|
||||
return *this != other ? true : false;
|
||||
|
||||
// has
|
||||
// hasnt
|
||||
// startswith
|
||||
// endswith
|
||||
// TODO has
|
||||
// TODO hasnt
|
||||
// TODO startswith
|
||||
// TODO endswith
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -35,9 +35,11 @@ class Mod : public std::string
|
|||
{
|
||||
public:
|
||||
Mod (); // Default constructor
|
||||
Mod (const char*); // Copy constructor
|
||||
Mod (const std::string&); // Copy constructor
|
||||
~Mod (); // Destructor
|
||||
|
||||
bool isValid ();
|
||||
bool valid ();
|
||||
bool eval (const Mod&);
|
||||
};
|
||||
|
||||
|
|
|
@ -68,6 +68,10 @@ void Record::parse (const std::string& input)
|
|||
{
|
||||
if (input[0] == '[' && input[input.length () - 1] == ']')
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
throw std::string ("unimplemented Record:parse");
|
||||
}
|
||||
else
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
PROJECT = t.t tdb.t date.t duration.t t.benchmark.t text.t autocomplete.t \
|
||||
parse.t seq.t att.t # mod.t record.t
|
||||
parse.t seq.t att.t mod.t # record.t
|
||||
CFLAGS = -I. -I.. -Wall -pedantic -ggdb3 -fno-rtti
|
||||
LFLAGS = -L/usr/local/lib
|
||||
OBJECTS = ../TDB.o ../T.o ../parse.o ../text.o ../Date.o ../Duration.o \
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest t (31);
|
||||
UnitTest t (33);
|
||||
|
||||
Att a1 ("name", "value");
|
||||
t.is (a1.name (), "name", "Att::Att (name, value), Att.name");
|
||||
|
@ -64,7 +64,14 @@ int main (int argc, char** argv)
|
|||
t.is (a6.value_int (), 7, "Att::value_int set/get");
|
||||
t.is (a6.value (), "7", "Att::value 7");
|
||||
|
||||
// TODO Att::addMod
|
||||
// Att::addMod
|
||||
bool good = true;
|
||||
try {a6.addMod ("is");} catch (...) {t.fail ("Att::addMod (is)"); good = false;}
|
||||
if (good) t.pass ("Att::addMod (is)");
|
||||
|
||||
good = true;
|
||||
try {a6.addMod (Mod ("fartwizzle"));} catch (...) {t.pass ("Att::addMod (fartwizzle) failed"); good = false;}
|
||||
if (good) t.fail ("Att::addMod (fartwizzle)");
|
||||
|
||||
// Att::parse
|
||||
Att a7;
|
||||
|
|
57
src/tests/mod.t.cpp
Normal file
57
src/tests/mod.t.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// task - a command line task list manager.
|
||||
//
|
||||
// Copyright 2006 - 2009, Paul Beckingham.
|
||||
// All rights reserved.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation; either version 2 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
// details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program; if not, write to the
|
||||
//
|
||||
// Free Software Foundation, Inc.,
|
||||
// 51 Franklin Street, Fifth Floor,
|
||||
// Boston, MA
|
||||
// 02110-1301
|
||||
// USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include <Mod.h>
|
||||
#include <test.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest t (18);
|
||||
|
||||
Mod m = "before"; t.ok (m.valid (), "Mod: before is valid");
|
||||
m = "after"; t.ok (m.valid (), "Mod: after is valid");
|
||||
m = "not"; t.ok (m.valid (), "Mod: not is valid");
|
||||
m = "none"; t.ok (m.valid (), "Mod: none is valid");
|
||||
m = "any"; t.ok (m.valid (), "Mod: any is valid");
|
||||
m = "over"; t.ok (m.valid (), "Mod: over is valid");
|
||||
m = "under"; t.ok (m.valid (), "Mod: under is valid");
|
||||
m = "synth"; t.ok (m.valid (), "Mod: synth is valid");
|
||||
m = "first"; t.ok (m.valid (), "Mod: first is valid");
|
||||
m = "last"; t.ok (m.valid (), "Mod: last is valid");
|
||||
m = "this"; t.ok (m.valid (), "Mod: this is valid");
|
||||
m = "next"; t.ok (m.valid (), "Mod: next is valid");
|
||||
m = "is"; t.ok (m.valid (), "Mod: is is valid");
|
||||
m = "isnt"; t.ok (m.valid (), "Mod: isnt is valid");
|
||||
m = "has"; t.ok (m.valid (), "Mod: has is valid");
|
||||
m = "hasnt"; t.ok (m.valid (), "Mod: hasnt is valid");
|
||||
m = "startswith"; t.ok (m.valid (), "Mod: startswith is valid");
|
||||
m = "endswith"; t.ok (m.valid (), "Mod: endswith is valid");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
Loading…
Add table
Add a link
Reference in a new issue