diff --git a/src/tests/.gitignore b/src/tests/.gitignore index 17a026577..f25e411bc 100644 --- a/src/tests/.gitignore +++ b/src/tests/.gitignore @@ -4,3 +4,4 @@ tdb.t date.t duration.t text.t +autocomplete.t diff --git a/src/tests/Makefile b/src/tests/Makefile index 8df7ab92f..0650a8a92 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -1,4 +1,4 @@ -PROJECT = t.t tdb.t date.t duration.t t.benchmark.t text.t +PROJECT = t.t tdb.t date.t duration.t t.benchmark.t text.t autocomplete.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 ../util.o ../Config.o @@ -35,3 +35,6 @@ t.benchmark.t: t.benchmark.t.o $(OBJECTS) test.o text.t: text.t.o $(OBJECTS) test.o g++ text.t.o $(OBJECTS) test.o $(LFLAGS) -o text.t +autocomplete.t: autocomplete.t.o $(OBJECTS) test.o + g++ autocomplete.t.o $(OBJECTS) test.o $(LFLAGS) -o autocomplete.t + diff --git a/src/tests/autocomplete.t.cpp b/src/tests/autocomplete.t.cpp new file mode 100644 index 000000000..e97e2fb3e --- /dev/null +++ b/src/tests/autocomplete.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 <../task.h> + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest t (8); + + std::vector options; + options.push_back ("abc"); + options.push_back ("abcd"); + options.push_back ("abcde"); + options.push_back ("bcdef"); + options.push_back ("cdefg"); + + std::vector matches; + int result = autoComplete ("", options, matches); + t.is (result, 0, "no match on empty string"); + + result = autoComplete ("x", options, matches); + t.is (result, 0, "no match on wrong string"); + + result = autoComplete ("abcd", options, matches); + t.is (result, 1, "exact match on 'abcd'"); + t.is (matches[0], "abcd", "exact match on 'abcd'"); + + result = autoComplete ("ab", options, matches); + t.is (result, 3, "partial match on 'ab'"); + t.is (matches[0], "abc", "partial match on 'abc'"); + t.is (matches[1], "abcd", "partial match on 'abcd'"); + t.is (matches[2], "abcde", "partial match on 'abcde'"); + + return 0; +} + +////////////////////////////////////////////////////////////////////////////////