mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-06-26 10:54:28 +02:00
93 lines
4.3 KiB
C++
93 lines
4.3 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// 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;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|