mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Enhancement - Filters
- Filter implemented. - Unit tests started, need more as Att::match matures.
This commit is contained in:
parent
531cffdc7f
commit
a60d54be61
7 changed files with 95 additions and 54 deletions
12
src/Att.cpp
12
src/Att.cpp
|
@ -140,7 +140,7 @@ bool Att::parse (Nibbler& n)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool Att::validMod (const std::string& mod)
|
bool Att::validMod (const std::string& mod) const
|
||||||
{
|
{
|
||||||
if (mod == "before" || mod == "after" || // i18n: TODO
|
if (mod == "before" || mod == "after" || // i18n: TODO
|
||||||
mod == "not" || // i18n: TODO
|
mod == "not" || // i18n: TODO
|
||||||
|
@ -159,7 +159,7 @@ bool Att::validMod (const std::string& mod)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool Att::evalMod (Att& other)
|
bool Att::match (const Att& other) const
|
||||||
{
|
{
|
||||||
// No modifier means automatic pass.
|
// No modifier means automatic pass.
|
||||||
/*
|
/*
|
||||||
|
@ -196,12 +196,6 @@ bool Att::evalMod (Att& other)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
bool Att::match (const Att& other)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// name : " value "
|
// name : " value "
|
||||||
std::string Att::composeF4 () const
|
std::string Att::composeF4 () const
|
||||||
|
@ -230,7 +224,7 @@ void Att::addMod (const std::string& mod)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void Att::mods (std::vector <std::string>& all)
|
void Att::mods (std::vector <std::string>& all) const
|
||||||
{
|
{
|
||||||
all = mMods;
|
all = mMods;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,13 +42,13 @@ public:
|
||||||
~Att (); // Destructor
|
~Att (); // Destructor
|
||||||
|
|
||||||
bool parse (Nibbler&);
|
bool parse (Nibbler&);
|
||||||
bool validMod (const std::string&);
|
bool validMod (const std::string&) const;
|
||||||
bool evalMod (Att&);
|
bool match (const Att&) const;
|
||||||
bool match (const Att&);
|
|
||||||
std::string composeF4 () const;
|
std::string composeF4 () const;
|
||||||
|
|
||||||
void addMod (const std::string&);
|
void addMod (const std::string&);
|
||||||
void mods (std::vector <std::string>&);
|
void mods (std::vector <std::string>&) const;
|
||||||
|
|
||||||
std::string name () const;
|
std::string name () const;
|
||||||
void name (const std::string&);
|
void name (const std::string&);
|
||||||
|
|
|
@ -26,45 +26,21 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "Filter.h"
|
#include "Filter.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
Filter::Filter ()
|
// For every Att in the filter, lookup the equivalent in Record, and perform a
|
||||||
|
// match. Aren't filters easy now that everything is an attribute?
|
||||||
|
bool Filter::pass (const Record& record) const
|
||||||
{
|
{
|
||||||
}
|
Record::const_iterator r;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
// If record doesn't have the attribute, fail. If it does have the attribute
|
||||||
Filter::Filter (const Filter& other)
|
// but it doesn't match, fail.
|
||||||
{
|
|
||||||
throw std::string ("unimplemented Filter::Filter");
|
|
||||||
*this = other;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
Filter& Filter::operator= (const Filter& other)
|
|
||||||
{
|
|
||||||
throw std::string ("unimplemented Filter::operator=");
|
|
||||||
if (this != &other)
|
|
||||||
{
|
|
||||||
*this = other;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
Filter::~Filter ()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
bool Filter::pass (Record& record)
|
|
||||||
{
|
|
||||||
throw std::string ("unimplemented Filter::pass");
|
|
||||||
/*
|
|
||||||
foreach (att, (*this))
|
foreach (att, (*this))
|
||||||
if (! att->match (record))
|
if ((r = record.find (att->name ())) == record.end () ||
|
||||||
return false;
|
! att->match (r->second))
|
||||||
*/
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,12 +34,7 @@
|
||||||
class Filter : public std::vector <Att>
|
class Filter : public std::vector <Att>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Filter (); // Default constructor
|
bool pass (const Record&) const;
|
||||||
Filter (const Filter&); // Copy constructor
|
|
||||||
Filter& operator= (const Filter&); // Assignment operator
|
|
||||||
~Filter (); // Destructor
|
|
||||||
|
|
||||||
bool pass (Record&);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
1
src/tests/.gitignore
vendored
1
src/tests/.gitignore
vendored
|
@ -13,3 +13,4 @@ record.t
|
||||||
stringtable.t
|
stringtable.t
|
||||||
nibbler.t
|
nibbler.t
|
||||||
subst.t
|
subst.t
|
||||||
|
filt.t
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
PROJECT = t.t t2.t tdb.t date.t duration.t t.benchmark.t text.t autocomplete.t \
|
PROJECT = t.t t2.t tdb.t date.t duration.t t.benchmark.t text.t autocomplete.t \
|
||||||
parse.t seq.t att.t stringtable.t record.t nibbler.t subst.t
|
parse.t seq.t att.t stringtable.t record.t nibbler.t subst.t filt.t
|
||||||
CFLAGS = -I. -I.. -Wall -pedantic -ggdb3 -fno-rtti
|
CFLAGS = -I. -I.. -Wall -pedantic -ggdb3 -fno-rtti
|
||||||
LFLAGS = -L/usr/local/lib
|
LFLAGS = -L/usr/local/lib
|
||||||
OBJECTS = ../TDB.o ../TDB2.o ../T.o ../T2.o ../parse.o ../text.o ../Date.o \
|
OBJECTS = ../TDB.o ../TDB2.o ../T.o ../T2.o ../parse.o ../text.o ../Date.o \
|
||||||
|
@ -66,3 +66,6 @@ subst.t: subst.t.o $(OBJECTS) test.o
|
||||||
nibbler.t: nibbler.t.o $(OBJECTS) test.o
|
nibbler.t: nibbler.t.o $(OBJECTS) test.o
|
||||||
g++ nibbler.t.o $(OBJECTS) test.o $(LFLAGS) -o nibbler.t
|
g++ nibbler.t.o $(OBJECTS) test.o $(LFLAGS) -o nibbler.t
|
||||||
|
|
||||||
|
filt.t: filt.t.o $(OBJECTS) test.o
|
||||||
|
g++ filt.t.o $(OBJECTS) test.o $(LFLAGS) -o filt.t
|
||||||
|
|
||||||
|
|
72
src/tests/filt.t.cpp
Normal file
72
src/tests/filt.t.cpp
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 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 "task.h"
|
||||||
|
#include "test.h"
|
||||||
|
#include "Filter.h"
|
||||||
|
#include "T2.h"
|
||||||
|
|
||||||
|
Context context;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
int main (int argc, char** argv)
|
||||||
|
{
|
||||||
|
UnitTest test (6);
|
||||||
|
|
||||||
|
// Create a filter consisting of two Att criteria.
|
||||||
|
Filter f;
|
||||||
|
f.push_back (Att ("name1", "value1"));
|
||||||
|
f.push_back (Att ("name2", "value2"));
|
||||||
|
test.is (f.size (), (size_t)2, "Filter created");
|
||||||
|
|
||||||
|
// Create a T2 to match against.
|
||||||
|
T2 yes;
|
||||||
|
yes.set ("name1", "value1");
|
||||||
|
yes.set ("name2", "value2");
|
||||||
|
test.ok (f.pass (yes), "full match");
|
||||||
|
|
||||||
|
yes.set ("name3", "value3");
|
||||||
|
test.ok (f.pass (yes), "over match");
|
||||||
|
|
||||||
|
// Negative tests.
|
||||||
|
T2 no0;
|
||||||
|
test.notok (f.pass (no0), "no match against default T2");
|
||||||
|
|
||||||
|
T2 no1;
|
||||||
|
no1.set ("name3", "value3");
|
||||||
|
test.notok (f.pass (no0), "no match against mismatch T2");
|
||||||
|
|
||||||
|
T2 partial;
|
||||||
|
partial.set ("name1", "value1");
|
||||||
|
test.notok (f.pass (no0), "no match against partial T2");
|
||||||
|
|
||||||
|
// TODO Modifiers.
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue