-
Notifications
You must be signed in to change notification settings - Fork 186
/
Copy pathtest092.cpp
73 lines (61 loc) · 1.92 KB
/
test092.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
// test092.cpp - numeric c++ locale
#include <clocale>
#include <rapidcsv.h>
#include "unittest.h"
int main()
{
int rv = 0;
std::string loc = "de_DE"; // uses comma (,) as decimal separator
try
{
std::locale::global(std::locale(loc.c_str()));
}
catch (const std::exception& ex)
{
std::cout << "locale " << loc << " not available (" << ex.what()
<< "), skipping test.\n";
// pass test for systems without locale present. for ci testing, make.sh
// ensures that the necessary locale is installed.
return 0;
}
std::string path = unittest::TempPath();
try
{
{
std::string csv =
"-;A;B;C\n"
"1;1;10;100\n"
"2;0,1;0,01;0,001\n"
;
unittest::WriteFile(path, csv);
rapidcsv::Document doc(path, rapidcsv::LabelParams(0, 0),
rapidcsv::SeparatorParams(';' /* pSeparator */));
unittest::ExpectEqual(float, doc.GetCell<float>("A", "2"), 0.1f);
unittest::ExpectEqual(float, doc.GetCell<float>("B", "2"), 0.01f);
unittest::ExpectEqual(float, doc.GetCell<float>("C", "2"), 0.001f);
}
{
std::string csv =
"-,A,B,C\n"
"1,1,10,100\n"
"2,0.1,0.01,0.001\n"
;
unittest::WriteFile(path, csv);
rapidcsv::LabelParams labelParams(0, 0);
rapidcsv::SeparatorParams separatorParams;
rapidcsv::ConverterParams converterParams;
converterParams.mNumericLocale = false; // do not honor numeric locale
rapidcsv::Document doc(path, labelParams, separatorParams, converterParams);
unittest::ExpectEqual(float, doc.GetCell<float>("A", "2"), 0.1f);
unittest::ExpectEqual(float, doc.GetCell<float>("B", "2"), 0.01f);
unittest::ExpectEqual(float, doc.GetCell<float>("C", "2"), 0.001f);
}
}
catch (const std::exception& ex)
{
std::cout << ex.what() << std::endl;
rv = 1;
}
unittest::DeleteFile(path);
return rv;
}