| 5 | #include "unittest.h" |
| 6 | |
| 7 | int main() |
| 8 | { |
| 9 | int rv = 0; |
| 10 | |
| 11 | std::string loc = "de_DE"; // uses comma (,) as decimal separator |
| 12 | try |
| 13 | { |
| 14 | std::locale::global(std::locale(loc.c_str())); |
| 15 | } |
| 16 | catch (const std::exception& ex) |
| 17 | { |
| 18 | std::cout << "locale " << loc << " not available (" << ex.what() |
| 19 | << "), skipping test.\n"; |
| 20 | // pass test for systems without locale present. for ci testing, make.sh |
| 21 | // ensures that the necessary locale is installed. |
| 22 | return 0; |
| 23 | } |
| 24 | |
| 25 | std::string path = unittest::TempPath(); |
| 26 | |
| 27 | try |
| 28 | { |
| 29 | { |
| 30 | std::string csv = |
| 31 | "-;A;B;C\n" |
| 32 | "1;1;10;100\n" |
| 33 | "2;0,1;0,01;0,001\n" |
| 34 | ; |
| 35 | |
| 36 | unittest::WriteFile(path, csv); |
| 37 | |
| 38 | rapidcsv::Document doc(path, rapidcsv::LabelParams(0, 0), |
| 39 | rapidcsv::SeparatorParams(';' /* pSeparator */)); |
| 40 | unittest::ExpectEqual(float, doc.GetCell<float>("A", "2"), 0.1f); |
| 41 | unittest::ExpectEqual(float, doc.GetCell<float>("B", "2"), 0.01f); |
| 42 | unittest::ExpectEqual(float, doc.GetCell<float>("C", "2"), 0.001f); |
| 43 | } |
| 44 | |
| 45 | { |
| 46 | std::string csv = |
| 47 | "-,A,B,C\n" |
| 48 | "1,1,10,100\n" |
| 49 | "2,0.1,0.01,0.001\n" |
| 50 | ; |
| 51 | |
| 52 | unittest::WriteFile(path, csv); |
| 53 | |
| 54 | rapidcsv::LabelParams labelParams(0, 0); |
| 55 | rapidcsv::SeparatorParams separatorParams; |
| 56 | rapidcsv::ConverterParams converterParams; |
| 57 | converterParams.mNumericLocale = false; // do not honor numeric locale |
| 58 | rapidcsv::Document doc(path, labelParams, separatorParams, converterParams); |
| 59 | unittest::ExpectEqual(float, doc.GetCell<float>("A", "2"), 0.1f); |
| 60 | unittest::ExpectEqual(float, doc.GetCell<float>("B", "2"), 0.01f); |
| 61 | unittest::ExpectEqual(float, doc.GetCell<float>("C", "2"), 0.001f); |
| 62 | } |
| 63 | } |
| 64 | catch (const std::exception& ex) |
nothing calls this directly
no test coverage detected