forked from d99kris/rapidcsv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test068.cpp
65 lines (55 loc) · 1.96 KB
/
test068.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
// test068.cpp - test automatic dequote disabled
#include "rapidcsv.h"
#include "unittest.h"
int main()
{
int rv = 0;
std::string csv =
"\"col 1\"\n"
"\"\"\n"
"\" \"\n"
"\"a b\"\n"
"\"\"\"a b\"\"\"\n"
"\" \"\"a\"\" \"\n"
;
std::string csvreadref =
"\"col 1\"\n"
"\" \"\n"
"\"a b\"\n"
"\"\"\"a b\"\"\"\n"
"\" \"\"a\"\" \"\n"
;
std::string path = unittest::TempPath();
unittest::WriteFile(path, csv);
try
{
// read
{
rapidcsv::Document doc(path, rapidcsv::LabelParams(0 /* pColumnNameIdx */, -1 /* pRowNameIdx */),
rapidcsv::SeparatorParams(',', false /* pTrim */, rapidcsv::sPlatformHasCR /* pHasCR */,
false /* pQuotedLinebreaks */, false /* pAutoQuote */));
unittest::ExpectEqual(std::string, doc.GetCell<std::string>("\"col 1\"", 0), "\"\"");
unittest::ExpectEqual(std::string, doc.GetCell<std::string>("\"col 1\"", 1), "\" \"");
unittest::ExpectEqual(std::string, doc.GetCell<std::string>("\"col 1\"", 2), "\"a b\"");
unittest::ExpectEqual(std::string, doc.GetCell<std::string>("\"col 1\"", 3), "\"\"\"a b\"\"\"");
unittest::ExpectEqual(std::string, doc.GetCell<std::string>("\"col 1\"", 4), "\" \"\"a\"\" \"");
}
// write
{
unittest::WriteFile(path, csvreadref);
rapidcsv::Document doc(path, rapidcsv::LabelParams(0 /* pColumnNameIdx */, -1 /* pRowNameIdx */),
rapidcsv::SeparatorParams(',', false /* pTrim */, rapidcsv::sPlatformHasCR /* pHasCR */,
false /* pQuotedLinebreaks */, false /* pAutoQuote */));
doc.Save();
const std::string& csvread = unittest::ReadFile(path);
unittest::ExpectEqual(std::string, csvreadref, csvread);
}
}
catch (const std::exception& ex)
{
std::cout << ex.what() << std::endl;
rv = 1;
}
unittest::DeleteFile(path);
return rv;
}