mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Enhancement - Record object
- Added Record::Record (const std::string&) - Added basic unit test for Record, which currently throws.
This commit is contained in:
parent
4fda101f28
commit
7c0aee4a5f
4 changed files with 86 additions and 3 deletions
|
@ -42,6 +42,12 @@ Record::Record (const Record& other)
|
||||||
*this = other;
|
*this = other;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Record::Record (const std::string& input)
|
||||||
|
{
|
||||||
|
parse (input);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
Record& Record::operator= (const Record& other)
|
Record& Record::operator= (const Record& other)
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <string>
|
||||||
#include "Att.h"
|
#include "Att.h"
|
||||||
|
|
||||||
class Record : public std::map <std::string, Att>
|
class Record : public std::map <std::string, Att>
|
||||||
|
@ -36,12 +37,12 @@ class Record : public std::map <std::string, Att>
|
||||||
public:
|
public:
|
||||||
Record (); // Default constructor
|
Record (); // Default constructor
|
||||||
Record (const Record&); // Copy constructor
|
Record (const Record&); // Copy constructor
|
||||||
|
Record (const std::string&); // Copy constructor
|
||||||
Record& operator= (const Record&); // Assignment operator
|
Record& operator= (const Record&); // Assignment operator
|
||||||
virtual ~Record (); // Destructor
|
virtual ~Record (); // Destructor
|
||||||
|
|
||||||
virtual std::string composeCSV () = 0;
|
|
||||||
|
|
||||||
std::string composeF4 ();
|
std::string composeF4 ();
|
||||||
|
std::string composeCSV ();
|
||||||
void parse (const std::string&);
|
void parse (const std::string&);
|
||||||
|
|
||||||
std::vector <Att> all ();
|
std::vector <Att> all ();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
PROJECT = t.t tdb.t date.t duration.t t.benchmark.t text.t autocomplete.t \
|
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
|
CFLAGS = -I. -I.. -Wall -pedantic -ggdb3 -fno-rtti
|
||||||
LFLAGS = -L/usr/local/lib
|
LFLAGS = -L/usr/local/lib
|
||||||
OBJECTS = ../TDB.o ../T.o ../parse.o ../text.o ../Date.o ../Duration.o \
|
OBJECTS = ../TDB.o ../T.o ../parse.o ../text.o ../Date.o ../Duration.o \
|
||||||
|
|
76
src/tests/record.t.cpp
Normal file
76
src/tests/record.t.cpp
Normal file
|
@ -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 <iostream>
|
||||||
|
#include <Att.h>
|
||||||
|
#include <Record.h>
|
||||||
|
#include <test.h>
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
Loading…
Add table
Add a link
Reference in a new issue