Skip to content

Commit 5522e3b

Browse files
committed
csv cursor tests
1 parent e4dcdff commit 5522e3b

File tree

1 file changed

+85
-1
lines changed

1 file changed

+85
-1
lines changed

test/csv/src/csv_cursor_tests.cpp

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ EUR_LIBOR_06M,2015-10-27,0.0000001
4646
{
4747
auto options = csv::csv_options{}
4848
.assume_header(true)
49-
.mapping_kind(csv::csv_mapping_kind::n_rows);
49+
.mapping_kind(csv::csv_mapping_kind::n_rows);
5050
csv::csv_string_cursor cursor(data, options);
5151

5252
CHECK(cursor.current().event_type() == staj_event_type::begin_array);
@@ -107,6 +107,90 @@ EUR_LIBOR_06M,2015-10-27,0.0000001
107107
cursor.next();
108108
CHECK(cursor.done());
109109
}
110+
SECTION("n_objects test")
111+
{
112+
auto options = csv::csv_options{}
113+
.assume_header(true)
114+
.mapping_kind(csv::csv_mapping_kind::n_objects);
115+
csv::csv_string_cursor cursor(data, options);
116+
117+
jsoncons::json_decoder<jsoncons::json> decoder;
118+
119+
CHECK(cursor.current().event_type() == staj_event_type::begin_array);
120+
cursor.next();
121+
122+
CHECK(cursor.current().event_type() == staj_event_type::begin_object);
123+
cursor.next();
124+
CHECK(cursor.current().event_type() == staj_event_type::key);
125+
CHECK(cursor.current().get<std::string>() == std::string("index_id"));
126+
cursor.next();
127+
CHECK(cursor.current().event_type() == staj_event_type::string_value);
128+
CHECK(cursor.current().get<std::string>() == std::string("EUR_LIBOR_06M"));
129+
cursor.next();
130+
CHECK(cursor.current().event_type() == staj_event_type::key);
131+
CHECK(cursor.current().get<std::string>() == std::string("observation_date"));
132+
cursor.next();
133+
CHECK(cursor.current().event_type() == staj_event_type::string_value);
134+
CHECK(cursor.current().get<std::string>() == std::string("2015-10-23"));
135+
cursor.next();
136+
CHECK(cursor.current().event_type() == staj_event_type::key);
137+
CHECK(cursor.current().get<std::string>() == std::string("rate"));
138+
cursor.next();
139+
CHECK(cursor.current().event_type() == staj_event_type::double_value);
140+
cursor.next();
141+
CHECK(cursor.current().event_type() == staj_event_type::end_object);
142+
cursor.next();
143+
144+
CHECK(cursor.current().event_type() == staj_event_type::begin_object);
145+
cursor.read_to(decoder);
146+
147+
std::cout << decoder.get_result() << "\n";
148+
149+
/*cursor.next();
150+
CHECK(cursor.current().event_type() == staj_event_type::key);
151+
CHECK(cursor.current().get<std::string>() == std::string("index_id"));
152+
cursor.next();
153+
CHECK(cursor.current().event_type() == staj_event_type::string_value);
154+
CHECK(cursor.current().get<std::string>() == std::string("EUR_LIBOR_06M"));
155+
cursor.next();
156+
CHECK(cursor.current().event_type() == staj_event_type::key);
157+
CHECK(cursor.current().get<std::string>() == std::string("observation_date"));
158+
cursor.next();
159+
CHECK(cursor.current().event_type() == staj_event_type::string_value);
160+
cursor.next();
161+
CHECK(cursor.current().event_type() == staj_event_type::key);
162+
CHECK(cursor.current().get<std::string>() == std::string("rate"));
163+
cursor.next();
164+
CHECK(cursor.current().event_type() == staj_event_type::double_value);
165+
cursor.next();
166+
CHECK(cursor.current().event_type() == staj_event_type::end_object);
167+
cursor.next();*/
168+
169+
CHECK(cursor.current().event_type() == staj_event_type::begin_object);
170+
cursor.next();
171+
CHECK(cursor.current().event_type() == staj_event_type::key);
172+
CHECK(cursor.current().get<std::string>() == std::string("index_id"));
173+
cursor.next();
174+
CHECK(cursor.current().event_type() == staj_event_type::string_value);
175+
CHECK(cursor.current().get<std::string>() == std::string("EUR_LIBOR_06M"));
176+
cursor.next();
177+
CHECK(cursor.current().event_type() == staj_event_type::key);
178+
CHECK(cursor.current().get<std::string>() == std::string("observation_date"));
179+
cursor.next();
180+
CHECK(cursor.current().event_type() == staj_event_type::string_value);
181+
cursor.next();
182+
CHECK(cursor.current().event_type() == staj_event_type::key);
183+
CHECK(cursor.current().get<std::string>() == std::string("rate"));
184+
cursor.next();
185+
CHECK(cursor.current().event_type() == staj_event_type::double_value);
186+
cursor.next();
187+
CHECK(cursor.current().event_type() == staj_event_type::end_object);
188+
cursor.next();
189+
190+
CHECK(cursor.current().event_type() == staj_event_type::end_array);
191+
cursor.next();
192+
CHECK(cursor.done());
193+
}
110194
SECTION("m_columns test")
111195
{
112196
auto options = csv::csv_options{}

0 commit comments

Comments
 (0)