-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_utils.cpp
More file actions
95 lines (72 loc) · 2.32 KB
/
test_utils.cpp
File metadata and controls
95 lines (72 loc) · 2.32 KB
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
90
91
92
93
94
95
#include "testing_utils/defines.hpp"
#include <catch2/catch_test_macros.hpp>
#include <fstream>
#include <libdbc/utils/utils.hpp>
#include <sstream>
namespace Utils {
TEST_CASE("Basic file input with safe get_line that is non line ending specific", "") {
SECTION("Verify various line ending input files") {
std::ifstream TextFile;
std::string test;
TextFile.open(TEXT_FILE, std::ios::in);
CHECK(TextFile.is_open());
if (TextFile.is_open()) {
StreamHandler::get_line(TextFile, test);
REQUIRE(test == "This is a non dbc formatted file.");
StreamHandler::get_line(TextFile, test);
REQUIRE(test == "");
StreamHandler::get_line(TextFile, test);
REQUIRE(test == "Make sure things pass with this");
StreamHandler::get_line(TextFile, test);
REQUIRE(test == "Who knows what might happen.");
TextFile.close();
}
}
}
TEST_CASE("Test line finding utility functions", "") {
std::string line;
std::string test_string =
"hello\n\
\n\
\n\
\n\
this is not blank\n\
maybe not this one either\n\
\n\
Someone wrote something....\n\
b\n\
end";
std::istringstream stream(test_string);
SECTION("Test skipping empty lines") {
StreamHandler::get_line(stream, line);
CHECK(line == "hello");
StreamHandler::get_next_non_blank_line(stream, line);
REQUIRE(line == "this is not blank");
StreamHandler::skip_to_next_blank_line(stream, line);
REQUIRE(line == "");
StreamHandler::get_next_non_blank_line(stream, line);
REQUIRE(line == "Someone wrote something....");
StreamHandler::get_next_non_blank_line(stream, line);
REQUIRE(line == " b");
StreamHandler::get_next_non_blank_line(stream, line);
REQUIRE(line == "end");
SECTION("Test end of the files", "[edge case]") {
StreamHandler::get_next_non_blank_line(stream, line);
REQUIRE(line == "");
StreamHandler::skip_to_next_blank_line(stream, line);
REQUIRE(line == "");
}
}
}
TEST_CASE("Test the string trim feature", "[string]") {
std::string s = " there might be some white space.... ";
REQUIRE(String::trim(s) == "there might be some white space....");
}
TEST_CASE("Test string split feature", "[string]") {
std::string s = "name1 name2 name3 name4 name5 ";
std::vector<std::string> vs = {"name1", "name2", "name3", "name4", "name5"};
std::vector<std::string> v;
String::split(s, v);
REQUIRE(v == vs);
}
} // Utils