forked from Illumina/strelka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring_util_test.cpp
89 lines (70 loc) · 2.5 KB
/
string_util_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//
// Strelka - Small Variant Caller
// Copyright (c) 2009-2018 Illumina, Inc.
//
// 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 3 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, see <http://www.gnu.org/licenses/>.
//
//
#include "boost/test/unit_test.hpp"
#include "string_util.hh"
#include <cstring>
BOOST_AUTO_TEST_SUITE( string_util )
static const char* test_string("234562342");
template <typename T>
void
test_split_string_bytype(T test)
{
std::vector<std::string> result;
split_string(test,'2',result);
BOOST_REQUIRE_EQUAL(static_cast<int>(result.size()), 4);
BOOST_REQUIRE_EQUAL(result[0], "");
BOOST_REQUIRE_EQUAL(result[1], "3456");
BOOST_REQUIRE_EQUAL(result[3], "");
split_string(test,'2',result, true);
BOOST_REQUIRE_EQUAL(static_cast<int>(result.size()), 2);
BOOST_REQUIRE_EQUAL(result[0], "3456");
split_string(test,'X',result);
BOOST_REQUIRE_EQUAL(static_cast<int>(result.size()), 1);
BOOST_REQUIRE_EQUAL(result[0], test);
split_string("",'X',result);
BOOST_REQUIRE_EQUAL(static_cast<int>(result.size()), 1);
BOOST_REQUIRE_EQUAL(result[0], "");
}
BOOST_AUTO_TEST_CASE( test_split_string_cstr )
{
test_split_string_bytype(test_string);
}
BOOST_AUTO_TEST_CASE( test_split_string )
{
const std::string test(test_string);
test_split_string_bytype(test);
}
BOOST_AUTO_TEST_CASE( test_destructive_split_string )
{
std::unique_ptr<char[]> tmp(new char[strlen(test_string)+1]);
std::strcpy(tmp.get(),test_string);
std::vector<const char*> result;
destructive_split_string(tmp.get(),'2',result);
BOOST_REQUIRE_EQUAL(static_cast<int>(result.size()), 4);
BOOST_REQUIRE_EQUAL(std::strcmp(result[0], ""),0);
BOOST_REQUIRE_EQUAL(std::strcmp(result[1], "3456"),0);
BOOST_REQUIRE_EQUAL(std::strcmp(result[3], ""),0);
}
BOOST_AUTO_TEST_CASE( test_split_match )
{
const std::string test(test_string);
BOOST_REQUIRE(split_match(test,'2',"34"));
BOOST_REQUIRE(! split_match(test,'2',"XX"));
}
BOOST_AUTO_TEST_SUITE_END()