Enhancement - Filters

- Filter implemented.
- Unit tests started, need more as Att::match matures.
This commit is contained in:
Paul Beckingham 2009-06-05 00:15:00 -04:00
parent 531cffdc7f
commit a60d54be61
7 changed files with 95 additions and 54 deletions

View file

@ -13,3 +13,4 @@ record.t
stringtable.t
nibbler.t
subst.t
filt.t

View file

@ -1,5 +1,5 @@
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
LFLAGS = -L/usr/local/lib
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
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
View 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;
}
////////////////////////////////////////////////////////////////////////////////