diff --git a/src/tests/Makefile b/src/tests/Makefile index 6e7f23555..6e887b90f 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -1,10 +1,10 @@ PROJECT = t.t tdb.t date.t duration.t t.benchmark.t text.t autocomplete.t \ - parse.t seq.t att.t mod.t stringtable.t # record.t + parse.t seq.t att.t mod.t stringtable.t # subst.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 \ ../util.o ../Config.o ../Sequence.o ../Att.o ../Record.o ../Mod.o \ - ../StringTable.o + ../StringTable.o ../Subst.o all: $(PROJECT) @@ -59,3 +59,6 @@ att.t: att.t.o $(OBJECTS) test.o stringtable.t: stringtable.t.o $(OBJECTS) test.o g++ stringtable.t.o $(OBJECTS) test.o $(LFLAGS) -o stringtable.t +subst.t: subst.t.o $(OBJECTS) test.o + g++ subst.t.o $(OBJECTS) test.o $(LFLAGS) -o subst.t + diff --git a/src/tests/subst.t.cpp b/src/tests/subst.t.cpp new file mode 100644 index 000000000..18dc0df47 --- /dev/null +++ b/src/tests/subst.t.cpp @@ -0,0 +1,63 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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 +#include + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest t (2); + + T task; + task.set ("description", "one two three four"); + + Subst s; + if (s.parse ("/two/TWO/")) + { + s.apply (task); + t.is (task.get ("description"), "one TWO three four", "single word subst"); + } + else + { + t.fail ("failed to parse '/two/TWO/'"); + } + + if (s.parse ("/e /E /g")) + { + s.apply (task); + t.is (task.get ("description"), "onE TWO threE four", "multiple word subst"); + } + else + { + t.fail ("failed to parse '/e /E /g'"); + } + + return 0; +} + +////////////////////////////////////////////////////////////////////////////////