From 41a6cdea228c00ac3fc4f6d371170505eec12f73 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 24 May 2009 14:45:50 -0400 Subject: [PATCH] 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. --- src/Att.cpp | 4 +-- src/Att.h | 2 +- src/Mod.cpp | 66 ++++++++++++++++++++++++++------------------- src/Mod.h | 8 +++--- src/Record.cpp | 4 +++ src/tests/Makefile | 2 +- src/tests/att.t.cpp | 11 ++++++-- src/tests/mod.t.cpp | 57 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 117 insertions(+), 37 deletions(-) create mode 100644 src/tests/mod.t.cpp diff --git a/src/Att.cpp b/src/Att.cpp index df0b2ba16..400043ad0 100644 --- a/src/Att.cpp +++ b/src/Att.cpp @@ -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); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/Att.h b/src/Att.h index c29312e80..84a88371a 100644 --- a/src/Att.h +++ b/src/Att.h @@ -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; diff --git a/src/Mod.cpp b/src/Mod.cpp index 3bfea6c5e..4fb66777c 100644 --- a/src/Mod.cpp +++ b/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; } diff --git a/src/Mod.h b/src/Mod.h index 4e7e6e669..e96b7e7ce 100644 --- a/src/Mod.h +++ b/src/Mod.h @@ -34,10 +34,12 @@ class Mod; class Mod : public std::string { public: - Mod (); // Default constructor - ~Mod (); // Destructor + Mod (); // Default constructor + Mod (const char*); // Copy constructor + Mod (const std::string&); // Copy constructor + ~Mod (); // Destructor - bool isValid (); + bool valid (); bool eval (const Mod&); }; diff --git a/src/Record.cpp b/src/Record.cpp index c42c6dd87..b7670e6b8 100644 --- a/src/Record.cpp +++ b/src/Record.cpp @@ -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 diff --git a/src/tests/Makefile b/src/tests/Makefile index 52b29fee6..6e69f9861 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -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 \ diff --git a/src/tests/att.t.cpp b/src/tests/att.t.cpp index c0c1bf2d0..4b55186a5 100644 --- a/src/tests/att.t.cpp +++ b/src/tests/att.t.cpp @@ -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; diff --git a/src/tests/mod.t.cpp b/src/tests/mod.t.cpp new file mode 100644 index 000000000..385a57038 --- /dev/null +++ b/src/tests/mod.t.cpp @@ -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 +#include + +//////////////////////////////////////////////////////////////////////////////// +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; +} + +////////////////////////////////////////////////////////////////////////////////