From 09f6160880674886b9d58b64ada231b3366bd6a5 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 5 Jan 2014 21:23:34 -0500 Subject: [PATCH] Unit Tests - Updated named dates tests. --- test/.gitignore | 1 + test/CMakeLists.txt | 3 +- test/dates.t.cpp | 148 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 test/dates.t.cpp diff --git a/test/.gitignore b/test/.gitignore index 658924345..51e74ca4a 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -6,6 +6,7 @@ autocomplete.t color.t config.t date.t +dates.t directory.t dom.t duration.t diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b7f8ca52f..3948d6b49 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -15,8 +15,7 @@ set (test_SRCS autocomplete.t color.t config.t date.t directory.t dom.t variant_inequal.t variant_lt.t variant_lte.t variant_match.t variant_math.t variant_modulo.t variant_multiply.t variant_nomatch.t variant_not.t variant_or.t variant_subtract.t - variant_xor.t eval.t) - + variant_xor.t eval.t dates.t) message ("-- Configuring run_all") if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) diff --git a/test/dates.t.cpp b/test/dates.t.cpp new file mode 100644 index 000000000..2ecdd48cf --- /dev/null +++ b/test/dates.t.cpp @@ -0,0 +1,148 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2013 - 2014, Göteborg Bit Factory. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include + +Context context; + +//////////////////////////////////////////////////////////////////////////////// +void testInit (UnitTest& t, const std::string& value, Variant& var) +{ + try + { + namedDates (value, var); + t.pass (value + " --> valid"); + } + + catch (const std::string& e) + { + t.fail (value + " --> valid"); + t.diag (e); + } + + catch (...) + { + t.fail (value + " --> valid"); + } +} + +//////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) +{ + UnitTest t (75); + + Variant sunday; testInit (t, "sunday", sunday); + Variant monday; testInit (t, "monday", monday); + Variant tuesday; testInit (t, "tuesday", tuesday); + Variant wednesday; testInit (t, "wednesday", wednesday); + Variant thursday; testInit (t, "thursday", thursday); + Variant friday; testInit (t, "friday", friday); + Variant saturday; testInit (t, "saturday", saturday); + + Variant sun; testInit (t, "sun", sun); + Variant mon; testInit (t, "mon", mon); + Variant tue; testInit (t, "tue", tue); + Variant wed; testInit (t, "wed", wed); + Variant thu; testInit (t, "thu", thu); + Variant fri; testInit (t, "fri", fri); + Variant sat; testInit (t, "sat", sat); + + t.ok (sunday == sun, "sunday == sun"); + t.ok (monday == mon, "monday == mon"); + t.ok (tuesday == tue, "tuesday == tue"); + t.ok (wednesday == wed, "wednesday == wed"); + t.ok (thursday == thu, "thursday == thu"); + t.ok (friday == fri, "friday == fri"); + t.ok (saturday == sat, "saturday == sat"); + + Variant january; testInit (t, "january", january); + Variant february; testInit (t, "february", february); + Variant march; testInit (t, "march", march); + Variant april; testInit (t, "april", april); + Variant may; testInit (t, "may", may); + Variant june; testInit (t, "june", june); + Variant july; testInit (t, "july", july); + Variant august; testInit (t, "august", august); + Variant september; testInit (t, "september", september); + Variant october; testInit (t, "october", october); + Variant november; testInit (t, "november", november); + Variant december; testInit (t, "december", december); + + Variant jan; testInit (t, "jan", jan); + Variant feb; testInit (t, "feb", feb); + Variant mar; testInit (t, "mar", mar); + Variant apr; testInit (t, "apr", apr); + Variant jun; testInit (t, "jun", jun); + Variant jul; testInit (t, "jul", jul); + Variant aug; testInit (t, "aug", aug); + Variant sep; testInit (t, "sep", sep); + Variant oct; testInit (t, "oct", oct); + Variant nov; testInit (t, "nov", nov); + Variant dec; testInit (t, "dec", dec); + + t.ok (january == jan, "january == jan"); + t.ok (february == feb, "february == feb"); + t.ok (march == mar, "march == mar"); + t.ok (april == apr, "april == apr"); + // May has only three letters. + t.ok (june == jun, "june == jun"); + t.ok (july == jul, "july == jul"); + t.ok (august == aug, "august == aug"); + t.ok (september == sep, "september == sep"); + t.ok (october == oct, "october == oct"); + t.ok (november == nov, "november == nov"); + t.ok (december == dec, "december == dec"); + + + // Simply instantiate these for now. Test later. + Variant now; testInit (t, "now", now); + Variant today; testInit (t, "today", today); + Variant sod; testInit (t, "sod", sod); + Variant yesterday; testInit (t, "yesterday", yesterday); + Variant tomorrow; testInit (t, "tomorrow", tomorrow); + Variant eod; testInit (t, "eod", eod); + Variant soy; testInit (t, "soy", soy); + Variant eoy; testInit (t, "eoy", eoy); + Variant socm; testInit (t, "socm", socm); + Variant som; testInit (t, "som", som); + Variant later; testInit (t, "later", later); + Variant someday; testInit (t, "someday", someday); + Variant easter; testInit (t, "easter", easter); + Variant eastermonday; testInit (t, "eastermonday", eastermonday); + Variant ascension; testInit (t, "ascension", ascension); + Variant pentecost; testInit (t, "pentecost", pentecost); + Variant goodfriday; testInit (t, "goodfriday", goodfriday); + Variant pi; testInit (t, "pi", pi); + Variant var_true; testInit (t, "true", var_true); + Variant var_false; testInit (t, "false", var_false); + + return 0; +} + +////////////////////////////////////////////////////////////////////////////////