-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtestcsvparser.cpp
156 lines (126 loc) · 5.51 KB
/
testcsvparser.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include "catch.hpp"
#include "input/parsers/csvparser.h"
#include <cstdio>
#include <sstream>
#include <iostream>
#include <sstream>
TEST_CASE("csv_parser: smoke test", "[parsing]") {
std::string input = "id:id, symb:symbol\n"
"1, a\n"
"2, b\n"
"3, c";
std::istringstream inputstream(input);
auto parser = csv_parser(
std::make_unique<csv::CSVReader>(
inputstream,
csv::CSVFormat().trim({' '})
)
);
auto first = parser.next().value();
REQUIRE(first.get("id") == std::vector<std::string>{"1"});
REQUIRE(first.get("symb") == std::vector<std::string>{"a"});
auto second = parser.next().value();
REQUIRE(second.get("id") == std::vector<std::string>{"2"});
REQUIRE(second.get("symb") == std::vector<std::string>{"b"});
auto third = parser.next().value();
REQUIRE(third.get("id") == std::vector<std::string>{"3"});
REQUIRE(third.get("symb") == std::vector<std::string>{"c"});
}
TEST_CASE("csv_parser: smoke test - only labels", "[parsing]") {
std::string input_str = "id, symb\n"
"670edd27, Received symbol b\n"
"670edd27, Received symbol b\n"
"670edd28, Received symbol b";
std::istringstream input(input_str);
auto parser = csv_parser(input,
csv::CSVFormat().trim({' '}));
auto first = parser.next().value();
REQUIRE(first.get("id") == std::vector<std::string>{"670edd27"});
REQUIRE(first.get("symb") == std::vector<std::string>{"Received symbol b"});
auto second = parser.next().value();
REQUIRE(second.get("id") == std::vector<std::string>{"670edd27"});
REQUIRE(second.get("symb") == std::vector<std::string>{"Received symbol b"});
auto third = parser.next().value();
REQUIRE(third.get("id") == std::vector<std::string>{"670edd28"});
REQUIRE(third.get("symb") == std::vector<std::string>{"Received symbol b"});
}
TEST_CASE("csv_parser: smoke test with attr", "[parsing]") {
std::string input = "id, symb, attr/d:test\n"
"1, a, 1.0\n"
"2, b, 2.0\n"
"3, c, 3.0";
std::istringstream inputstream(input);
auto parser = csv_parser(
std::make_unique<csv::CSVReader>(
inputstream,
csv::CSVFormat().trim({' '})
)
);
auto first = parser.next().value();
REQUIRE(first.get_str("id") == "1");
REQUIRE(first.get_str("symb") == "a");
REQUIRE(first.get_symb_attr_info().at(0).get_value() == "1.0");
REQUIRE(first.get_symb_attr_info().at(0).get_name() == "test");
REQUIRE(first.get_symb_attr_info().at(0).is_discrete());
auto second = parser.next().value();
REQUIRE(second.get_str("id") == "2");
REQUIRE(second.get_str("symb") == "b");
REQUIRE(second.get_symb_attr_info().at(0).get_value() == "2.0");
REQUIRE(second.get_symb_attr_info().at(0).get_name() == "test");
REQUIRE(second.get_symb_attr_info().at(0).is_discrete());
auto third = parser.next().value();
REQUIRE(third.get_str("id") == "3");
REQUIRE(third.get_str("symb") == "c");
REQUIRE(third.get_symb_attr_info().at(0).get_value() == "3.0");
REQUIRE(third.get_symb_attr_info().at(0).get_name() == "test");
REQUIRE(third.get_symb_attr_info().at(0).is_discrete());
}
TEST_CASE("csv_parser: smoke test with tattr", "[parsing]") {
std::string input = "id, symb, tattr/d:test\n"
"1, a, 1.0\n"
"1, b, \n"
"3, c, 3.0";
std::istringstream inputstream(input);
auto parser = csv_parser(
std::make_unique<csv::CSVReader>(
inputstream,
csv::CSVFormat().trim({' '})
)
);
auto first = parser.next().value();
auto first_tattr = first.get_trace_attr_info();
REQUIRE(first.get_str("id") == "1");
REQUIRE(first.get_str("symb") == "a");
REQUIRE(first_tattr->at(0).get_value() == "1.0");
auto second = parser.next().value();
auto second_tattr = second.get_trace_attr_info();
REQUIRE(second.get_str("id") == "1");
REQUIRE(second.get_str("symb") == "b");
REQUIRE(second_tattr->at(0).get_value() == "1.0");
REQUIRE(second_tattr == first_tattr);
REQUIRE(second_tattr->size() == 1);
auto third = parser.next().value();
auto third_tattr = third.get_trace_attr_info();
REQUIRE(third.get_str("id") == "3");
REQUIRE(third.get_str("symb") == "c");
REQUIRE(third_tattr->at(0).get_value() == "3.0");
}
TEST_CASE("csv_parser: smoke test with duplicate tattr", "[parsing]") {
std::string input = "id, symb, tattr/d:test\n"
"1, a, 1.0\n"
"1, b, 2.0\n" // <- This is not allowed, this redefines the trace attribute "test" for trace with id 1
"3, c, 3.0";
std::istringstream inputstream(input);
auto parser = csv_parser(
std::make_unique<csv::CSVReader>(
inputstream,
csv::CSVFormat().trim({' '})
)
);
auto first = parser.next().value();
auto first_tattr = first.get_trace_attr_info();
REQUIRE(first.get_str("id") == "1");
REQUIRE(first.get_str("symb") == "a");
REQUIRE(first_tattr->at(0).get_value() == "1.0");
REQUIRE_THROWS_WITH(parser.next().value(), "Error: duplicate trace attribute value \"test\" specified for trace with id: 1");
}