From 6d53cb7c9575d977f20d22be71e9b34d9e924697 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 5 Jan 2016 16:57:07 -0500 Subject: [PATCH] Tests: Added Table tests --- test/.gitignore | 1 + test/CMakeLists.txt | 2 +- test/table.t.cpp | 96 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 test/table.t.cpp diff --git a/test/.gitignore b/test/.gitignore index 32fd5f1a..0b562dd4 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -8,5 +8,6 @@ list.t pig.t rules.t rx.t +table.t text.t utf8.t diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 21733418..575b2fb2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,7 +9,7 @@ include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/test ${TIMEW_INCLUDE_DIRS}) -set (test_SRCS color.t fs.t grammar.t lexer.t list.t lr0.t pig.t rules.t rx.t text.t utf8.t) +set (test_SRCS color.t fs.t grammar.t lexer.t list.t lr0.t pig.t rules.t rx.t table.t text.t utf8.t) add_custom_target (test ./run_all --verbose DEPENDS ${test_SRCS} timew_executable diff --git a/test/table.t.cpp b/test/table.t.cpp new file mode 100644 index 00000000..103a5d66 --- /dev/null +++ b/test/table.t.cpp @@ -0,0 +1,96 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2006 - 2016, Paul Beckingham, Federico Hernandez. +// +// 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 +//#include +//#include +#include + +//////////////////////////////////////////////////////////////////////////////// +int main (int, char**) +{ + UnitTest t (1); + + try + { + // Create colors. + Color header_color (Color (Color::yellow, Color::nocolor, false, false, false)); + Color odd_color ("on gray1"); + Color even_color ("on gray0"); + + // Now render a string-only grid. + Color single_cell ("bold white on red"); + + Table t1; + t1.width (80); + t1.leftMargin (4); + t1.extraPadding (0); + t1.intraPadding (1); + t1.colorHeader (header_color); + t1.colorOdd (odd_color); + t1.colorEven (even_color); + t1.intraColorOdd (odd_color); + t1.intraColorEven (even_color); + +// t1.add (Column::factory ("string", "One")); +// t1.add (Column::factory ("string", "Two")); +// t1.add (Column::factory ("string", "Three")); + t1.add ("Header1", true); + t1.add ("Header2", true); + t1.add ("Header3", false); + + int row = t1.addRow (); + t1.set (row, 0, "top left"); + t1.set (row, 1, "top center"); + t1.set (row, 2, "top right"); + + row = t1.addRow (); + t1.set (row, 0, "bottom left", single_cell); + t1.set (row, 1, "bottom center, containing sufficient text that " + "wrapping will occur because it exceeds all " + "reasonable values for default width. Even in a " + "very wide terminal window. Just look at the " + "lengths we must go to, to get passing unit tests " + "and not flaky tests."); + t1.set (row, 2, "bottom right"); + + std::cout << t1.render (); + t.ok (t1.lines () > 4, "Table::lines > 4"); + } + + catch (const std::string& e) + { + t.fail ("Exception thrown."); + t.diag (e); + } + + return 0; +} + +////////////////////////////////////////////////////////////////////////////////