mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-06-26 10:54:28 +02:00
Test: Added tests for common/text.cpp
This commit is contained in:
parent
648517f608
commit
2c181ec07e
4 changed files with 95 additions and 7 deletions
|
@ -70,11 +70,5 @@ const std::string format (const std::string& fmt, Args... args)
|
|||
return format (1, fmt, args...);
|
||||
}
|
||||
|
||||
std::string leftJustify (const int, const int);
|
||||
std::string leftJustify (const std::string&, const int);
|
||||
std::string rightJustifyZero (const int, const int);
|
||||
std::string rightJustify (const int, const int);
|
||||
std::string rightJustify (const std::string&, const int);
|
||||
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
1
test/.gitignore
vendored
1
test/.gitignore
vendored
|
@ -1,4 +1,5 @@
|
|||
all.log
|
||||
color.t
|
||||
rx.t
|
||||
text.t
|
||||
utf8.t
|
||||
|
|
|
@ -9,7 +9,7 @@ include_directories (${CMAKE_SOURCE_DIR}
|
|||
${CMAKE_SOURCE_DIR}/test
|
||||
${TIMEW_INCLUDE_DIRS})
|
||||
|
||||
set (test_SRCS color.t rx.t utf8.t)
|
||||
set (test_SRCS color.t rx.t text.t utf8.t)
|
||||
|
||||
add_custom_target (test ./run_all --verbose
|
||||
DEPENDS ${test_SRCS} timew_executable
|
||||
|
|
93
test/text.t.cpp
Normal file
93
test/text.t.cpp
Normal file
|
@ -0,0 +1,93 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright 2006 - 2015, 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 <cmake.h>
|
||||
#include <text.h>
|
||||
#include <test.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int, char**)
|
||||
{
|
||||
UnitTest t (29);
|
||||
|
||||
// void split (std::vector<std::string>& results, const std::string& input, const char delimiter)
|
||||
std::vector <std::string> items;
|
||||
std::string unsplit = "";
|
||||
split (items, unsplit, '-');
|
||||
t.is (items.size (), (size_t) 0, "split '' '-' -> 0 items");
|
||||
|
||||
unsplit = "a";
|
||||
split (items, unsplit, '-');
|
||||
t.is (items.size (), (size_t) 1, "split 'a' '-' -> 1 item");
|
||||
t.is (items[0], "a", "split 'a' '-' -> 'a'");
|
||||
|
||||
split (items, unsplit, '-');
|
||||
t.is (items.size (), (size_t) 1, "split 'a' '-' -> 1 item");
|
||||
t.is (items[0], "a", "split 'a' '-' -> 'a'");
|
||||
|
||||
unsplit = "-";
|
||||
split (items, unsplit, '-');
|
||||
t.is (items.size (), (size_t) 2, "split '-' '-' -> '' ''");
|
||||
t.is (items[0], "", "split '-' '-' -> [0] ''");
|
||||
t.is (items[1], "", "split '-' '-' -> [1] ''");
|
||||
|
||||
unsplit = "-a-bc-def";
|
||||
split (items, unsplit, '-');
|
||||
t.is (items.size (), (size_t) 4, "split '-a-bc-def' '-' -> '' 'a' 'bc' 'def'");
|
||||
t.is (items[0], "", "split '-a-bc-def' '-' -> [0] ''");
|
||||
t.is (items[1], "a", "split '-a-bc-def' '-' -> [1] 'a'");
|
||||
t.is (items[2], "bc", "split '-a-bc-def' '-' -> [2] 'bc'");
|
||||
t.is (items[3], "def", "split '-a-bc-def' '-' -> [3] 'def'");
|
||||
|
||||
// std::string format (char);
|
||||
t.is (format ('A'), "A", "format ('A') -> A");
|
||||
|
||||
// std::string format (int);
|
||||
t.is (format (0), "0", "format (0) -> 0");
|
||||
t.is (format (-1), "-1", "format (-1) -> -1");
|
||||
|
||||
// std::string formatHex (int);
|
||||
t.is (formatHex (0), "0", "formatHex (0) -> 0");
|
||||
t.is (formatHex (10), "a", "formatHex (10) -> a");
|
||||
t.is (formatHex (123), "7b", "formatHex (123) -> 7b");
|
||||
|
||||
// std::string format (float, int, int);
|
||||
t.is (format (0.12345678, 8, 4), " 0.1235", "format (0.12345678, 8, 4) -> __0.1235");
|
||||
|
||||
t.is (format (1.23456789, 8, 1), " 1", "format (1.23456789, 8, 1) -> _______1");
|
||||
t.is (format (1.23456789, 8, 2), " 1.2", "format (1.23456789, 8, 2) -> _____1.2");
|
||||
t.is (format (1.23456789, 8, 3), " 1.23", "format (1.23456789, 8, 3) -> ____1.23");
|
||||
t.is (format (1.23456789, 8, 4), " 1.235", "format (1.23456789, 8, 4) -> ___1.235");
|
||||
t.is (format (1.23456789, 8, 5), " 1.2346", "format (1.23456789, 8, 5) -> __1.2346");
|
||||
t.is (format (1.23456789, 8, 6), " 1.23457", "format (1.23456789, 8, 6) -> 1.23457");
|
||||
t.is (format (1.23456789, 8, 7), "1.234568", "format (1.23456789, 8, 7) -> 1.234568");
|
||||
t.is (format (1.23456789, 8, 8), "1.2345679", "format (1.23456789, 8, 8) -> 1.2345679");
|
||||
t.is (format (2444238.56789, 12, 11), "2444238.5679", "format (2444238.56789, 12, 11) -> 2444238.5679");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
Loading…
Add table
Add a link
Reference in a new issue