diff --git a/src/Record.cpp b/src/Record.cpp index 439758820..32328cb3f 100644 --- a/src/Record.cpp +++ b/src/Record.cpp @@ -42,6 +42,12 @@ Record::Record (const Record& other) *this = other; } +//////////////////////////////////////////////////////////////////////////////// +Record::Record (const std::string& input) +{ + parse (input); +} + //////////////////////////////////////////////////////////////////////////////// Record& Record::operator= (const Record& other) { diff --git a/src/Record.h b/src/Record.h index e28ecc380..d8313e595 100644 --- a/src/Record.h +++ b/src/Record.h @@ -29,6 +29,7 @@ #include #include +#include #include "Att.h" class Record : public std::map @@ -36,12 +37,12 @@ class Record : public std::map public: Record (); // Default constructor Record (const Record&); // Copy constructor + Record (const std::string&); // Copy constructor Record& operator= (const Record&); // Assignment operator virtual ~Record (); // Destructor - virtual std::string composeCSV () = 0; - std::string composeF4 (); + std::string composeCSV (); void parse (const std::string&); std::vector all (); diff --git a/src/tests/Makefile b/src/tests/Makefile index 6e887b90f..76f9de225 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 stringtable.t # subst.t record.t + parse.t seq.t att.t mod.t stringtable.t record.t # subst.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/record.t.cpp b/src/tests/record.t.cpp new file mode 100644 index 000000000..f78b7d690 --- /dev/null +++ b/src/tests/record.t.cpp @@ -0,0 +1,76 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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 +#include + +//////////////////////////////////////////////////////////////////////////////// +Record parseRecord (const std::string& input) +{ + try { Record r (input); return r; } + catch (...) {} + return Record (); +} + +int main (int argc, char** argv) +{ + UnitTest t (4); + + // (blank) + Record record = parseRecord (""); + t.is (record.size (), (size_t)0, "Record (blank)"); + + // [] + record = parseRecord ("[]"); + t.is (record.size (), (size_t)0, "Record []"); + + // [name:value] + record = parseRecord ("[name:value]"); + t.is (record.size (), (size_t)1, "Record [name:value]"); + if (record.size () == 1) + { + Att a = record["name"]; + t.is (a.name (), "name", "Record [name:value] -> 'name'"); + } + else + { + t.fail ("Record [name:value] -> 'name'"); + } + + // TODO [name:"value"] + // TODO [name:"one two"] + // TODO [one:two three:four] + + // TODO FF3 + // TODO FF2 + // TODO FF1 + + return 0; +} + +////////////////////////////////////////////////////////////////////////////////