forked from d99kris/rapidcsv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test064.cpp
58 lines (46 loc) · 1.9 KB
/
test064.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
// test063.cpp - linebreaks in quoted text
#include <rapidcsv.h>
#include "unittest.h"
int main()
{
int rv = 0;
std::string csv =
"-,A,B,C\n"
"1,3,9,81\n"
"2,4,16,256\n"
"text,\"quoted text\",\"quoted\ntext\nwith\nlinebreaks\",\"\""
;
std::string path = unittest::TempPath();
unittest::WriteFile(path, csv);
try
{
rapidcsv::SeparatorParams seppar;
seppar.mQuotedLinebreaks = true;
rapidcsv::Document doc(path, rapidcsv::LabelParams(-1, -1), seppar, rapidcsv::ConverterParams());
unittest::ExpectEqual(size_t, doc.GetRowCount(), 4);
unittest::ExpectEqual(size_t, doc.GetColumnCount(), 4);
unittest::ExpectEqual(char, doc.GetCell<char>(0, 0), '-');
unittest::ExpectEqual(char, doc.GetCell<char>(1, 0), 'A');
unittest::ExpectEqual(char, doc.GetCell<char>(2, 0), 'B');
unittest::ExpectEqual(char, doc.GetCell<char>(3, 0), 'C');
unittest::ExpectEqual(int, doc.GetCell<int>(0, 1), 1);
unittest::ExpectEqual(int, doc.GetCell<int>(1, 1), 3);
unittest::ExpectEqual(int, doc.GetCell<int>(2, 1), 9);
unittest::ExpectEqual(int, doc.GetCell<int>(3, 1), 81);
unittest::ExpectEqual(unsigned int, doc.GetCell<unsigned int>(0, 2), 2);
unittest::ExpectEqual(unsigned int, doc.GetCell<unsigned int>(1, 2), 4);
unittest::ExpectEqual(unsigned int, doc.GetCell<unsigned int>(2, 2), 16);
unittest::ExpectEqual(unsigned int, doc.GetCell<unsigned int>(3, 2), 256);
unittest::ExpectEqual(std::string, doc.GetCell<std::string>(0, 3), "text");
unittest::ExpectEqual(std::string, doc.GetCell<std::string>(1, 3), "quoted text");
unittest::ExpectEqual(std::string, doc.GetCell<std::string>(2, 3), "quoted\ntext\nwith\nlinebreaks");
unittest::ExpectEqual(std::string, doc.GetCell<std::string>(3, 3), "");
}
catch (const std::exception& ex)
{
std::cout << ex.what() << std::endl;
rv = 1;
}
unittest::DeleteFile(path);
return rv;
}