mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-02 14:38:34 +02:00
Enhancement - Sequence object
- Implemented sequence object to encapsulate the worries of parsing sequences. - Implemented unit tests.
This commit is contained in:
parent
3cdfb733de
commit
f3724aa714
15 changed files with 209 additions and 29 deletions
1
src/tests/.gitignore
vendored
1
src/tests/.gitignore
vendored
|
@ -6,3 +6,4 @@ duration.t
|
|||
text.t
|
||||
autocomplete.t
|
||||
parse.t
|
||||
seq.t
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
PROJECT = t.t tdb.t date.t duration.t t.benchmark.t text.t autocomplete.t \
|
||||
parse.t
|
||||
parse.t seq.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
|
||||
../util.o ../Config.o ../Sequence.o
|
||||
|
||||
all: $(PROJECT)
|
||||
|
||||
|
@ -43,3 +43,6 @@ autocomplete.t: autocomplete.t.o $(OBJECTS) test.o
|
|||
parse.t: parse.t.o $(OBJECTS) test.o
|
||||
g++ parse.t.o $(OBJECTS) test.o $(LFLAGS) -o parse.t
|
||||
|
||||
seq.t: seq.t.o $(OBJECTS) test.o
|
||||
g++ seq.t.o $(OBJECTS) test.o $(LFLAGS) -o seq.t
|
||||
|
||||
|
|
|
@ -26,7 +26,8 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include <iostream>
|
||||
#include <test.h>
|
||||
#include <../task.h>
|
||||
#include <util.h>
|
||||
#include <task.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int argc, char** argv)
|
||||
|
|
|
@ -30,11 +30,11 @@
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// daily, day, Nd
|
||||
// weekly, Nw, sennight, biweekly, fortnight
|
||||
// weekly, 1w, sennight, biweekly, fortnight
|
||||
// monthly, bimonthly, Nm, semimonthly
|
||||
// 1st 2nd 3rd 4th .. 31st
|
||||
// quarterly, Nq
|
||||
// biannual, biyearly, annual, semiannual, yearly, Ny
|
||||
// quarterly, 1q
|
||||
// biannual, biyearly, annual, semiannual, yearly, 1y
|
||||
|
||||
int convertDuration (const std::string& input)
|
||||
{
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include <iostream>
|
||||
#include "task.h"
|
||||
#include "text.h"
|
||||
#include "test.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
118
src/tests/seq.t.cpp
Normal file
118
src/tests/seq.t.cpp
Normal file
|
@ -0,0 +1,118 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 <Sequence.h>
|
||||
#include <test.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Sequence parseSequence (const std::string& input)
|
||||
{
|
||||
try { Sequence s (input); return s; }
|
||||
catch (...) {}
|
||||
return Sequence ();
|
||||
}
|
||||
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest t (18);
|
||||
|
||||
// 1
|
||||
Sequence seq = parseSequence ("1");
|
||||
t.is (seq.size (), (size_t)1, "seq '1' -> 1 item");
|
||||
if (seq.size () == 1)
|
||||
{
|
||||
t.is (seq[0], 1, "seq '1' -> [0] == 1");
|
||||
}
|
||||
else
|
||||
{
|
||||
t.fail ("seq '1' -> [0] == 1");
|
||||
}
|
||||
|
||||
// 1,3
|
||||
seq = parseSequence ("1,3");
|
||||
t.is (seq.size (), (size_t)2, "seq '1,3' -> 2 items");
|
||||
if (seq.size () == 2)
|
||||
{
|
||||
t.is (seq[0], 1, "seq '1,3' -> [0] == 1");
|
||||
t.is (seq[1], 3, "seq '1,3' -> [1] == 3");
|
||||
}
|
||||
else
|
||||
{
|
||||
t.fail ("seq '1,3' -> [0] == 1");
|
||||
t.fail ("seq '1,3' -> [1] == 3");
|
||||
}
|
||||
|
||||
// 1,3-5,7
|
||||
seq = parseSequence ("1,3-5,7");
|
||||
t.is (seq.size (), (size_t)5, "seq '1,3-5,7' -> 5 items");
|
||||
if (seq.size () == 5)
|
||||
{
|
||||
t.is (seq[0], 1, "seq '1,3-5,7' -> [0] == 1");
|
||||
t.is (seq[1], 3, "seq '1,3-5,7' -> [1] == 3");
|
||||
t.is (seq[2], 4, "seq '1,3-5,7' -> [2] == 4");
|
||||
t.is (seq[3], 5, "seq '1,3-5,7' -> [3] == 5");
|
||||
t.is (seq[4], 7, "seq '1,3-5,7' -> [4] == 7");
|
||||
}
|
||||
else
|
||||
{
|
||||
t.fail ("seq '1,3-5,7' -> [0] == 1");
|
||||
t.fail ("seq '1,3-5,7' -> [1] == 3");
|
||||
t.fail ("seq '1,3-5,7' -> [2] == 4");
|
||||
t.fail ("seq '1,3-5,7' -> [3] == 5");
|
||||
t.fail ("seq '1,3-5,7' -> [4] == 7");
|
||||
}
|
||||
|
||||
// 1--2
|
||||
seq = parseSequence ("1--2");
|
||||
t.is (seq.size (), (size_t)0, "seq '1--2' -> 0 items (error)");
|
||||
|
||||
// 1-1000
|
||||
seq = parseSequence ("1-1000");
|
||||
t.is (seq.size (), (size_t)1000, "seq '1-1000' -> 1000 items");
|
||||
if (seq.size () == 1000)
|
||||
{
|
||||
t.is (seq[0], 1, "seq '1-1000' -> [0] == 1");
|
||||
t.is (seq[1], 2, "seq '1-1000' -> [1] == 3");
|
||||
t.is (seq[998], 999, "seq '1-1000' -> [998] == 999");
|
||||
t.is (seq[999], 1000, "seq '1-1000' -> [999] == 1000");
|
||||
}
|
||||
else
|
||||
{
|
||||
t.fail ("seq '1-1000' -> [0] == 1");
|
||||
t.fail ("seq '1-1000' -> [1] == 2");
|
||||
t.fail ("seq '1-1000' -> [998] == 999");
|
||||
t.fail ("seq '1-1000' -> [999] == 1000");
|
||||
}
|
||||
|
||||
// 1-1001
|
||||
seq = parseSequence ("1-1001");
|
||||
t.is (seq.size (), (size_t)0, "seq '1-1001' -> 0 items (error)");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
|
@ -25,8 +25,8 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include <sys/time.h>
|
||||
#include "../T.h"
|
||||
#include "../task.h"
|
||||
#include "T.h"
|
||||
#include "task.h"
|
||||
#include "test.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -24,8 +24,9 @@
|
|||
// USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include "../T.h"
|
||||
#include "../task.h"
|
||||
#include "TDB.h"
|
||||
#include "T.h"
|
||||
#include "task.h"
|
||||
#include "test.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../TDB.h"
|
||||
#include "../task.h"
|
||||
#include "TDB.h"
|
||||
#include "task.h"
|
||||
#include "test.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#include <iomanip>
|
||||
#include <string>
|
||||
#include <task.h>
|
||||
#include <util.h>
|
||||
#include <text.h>
|
||||
#include "test.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include <iostream>
|
||||
#include "task.h"
|
||||
#include "text.h"
|
||||
#include "test.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue