43 using std::make_tuple;
75 using error::LUMIERA_ERROR_STATE;
94 verify_persistentDataFile();
95 demonnstrate_CSV_Notation();
106 CHECK (not isnil (tab));
107 CHECK (1 == tab.size());
108 CHECK (
"" ==
string{tab.id});
109 CHECK (0.0 == tab.val);
110 CHECK ( 0 == tab.off);
115 CHECK (2 == tab.size());
116 CHECK (
"one" ==
string{tab.id});
117 CHECK ( 1.0 == tab.val);
118 CHECK ( 0 == tab.off);
123 CHECK (
"two" ==
string{tab.id});
124 CHECK ( 5.0 == tab.val);
125 CHECK ( -23 == tab.off);
127 CHECK (tab.off.header ==
"Offset");
128 CHECK (tab.off.data == vector({0,-23}));
138 CHECK (3 == tab.columnCnt);
141 CHECK (0 == tab.size());
142 CHECK (0 == tab.id.data.size());
143 CHECK (0 == tab.val.data.size());
144 CHECK (0 == tab.off.data.size());
145 CHECK (
"ID" == tab.id.header);
146 CHECK (
"Value" == tab.val.header);
147 CHECK (
"Offset" == tab.off.header);
156 tab.val.data.push_back (5.5);
157 CHECK (tab.val == 5.5);
159 CHECK (1 == tab.val.data.size());
160 CHECK (0 == tab.off.data.size());
161 CHECK (0 == tab.id.data.size());
162 CHECK (0 == tab.size());
166 CHECK (
"" ==
string{tab.id});
167 CHECK (5.5 == tab.val);
168 CHECK ( 0 == tab.off);
169 CHECK (1 == tab.val.data.size());
170 CHECK (1 == tab.off.data.size());
171 CHECK (1 == tab.id.data.size());
172 CHECK (1 == tab.size());
173 CHECK (not isnil (tab));
174 CHECK (tab.off.data == vector({0}));
175 CHECK (tab.val.data == vector({5.5}));
177 tab.allColumns() = make_tuple(
"●", 2.3, -11);
178 CHECK (
"●" ==
string{tab.id});
179 CHECK (2.3 == tab.val);
180 CHECK (-11 == tab.off);
185 CHECK (tab.off.data == vector({-11,-11}));
186 CHECK (tab.val.data == vector({2.3,42.0}));
187 CHECK (tab.id.data == vector<string>({
"●",
"◆"}));
190 CHECK (tab.id.data.capacity() >= 100);
191 CHECK (tab.val.data.capacity() >= 100);
192 CHECK (tab.off.data.capacity() >= 100);
193 CHECK (tab.id.data.size() == 2);
194 CHECK (tab.val.data.size() == 2);
195 CHECK (tab.off.data.size() == 2);
196 CHECK (2 == tab.size());
197 CHECK (
"◆" ==
string{tab.id});
198 CHECK ( 42 == tab.val);
199 CHECK (-11 == tab.off);
201 meta::forEach (tab.allColumns()
202 ,[](
auto& col){ col.data.resize(2); }
204 CHECK (2 == tab.size());
205 CHECK (
"◆" ==
string{tab.id});
206 CHECK ( 42 == tab.val);
207 CHECK (-11 == tab.off);
210 CHECK (1 == tab.size());
211 CHECK (
"●" ==
string{tab.id});
212 CHECK (2.3 == tab.val);
213 CHECK (-11 == tab.off);
214 CHECK (tab.val.data.size() == 1);
215 CHECK (tab.val.data.capacity() >= 100);
219 CHECK (tab.val.data.size() == 0);
220 CHECK (tab.val.data.capacity() >= 100);
228 double val = 1.0 / 3;
229 CHECK (util::toString(val) ==
"0.33333333"_expect );
230 CHECK (util::showDecimal(val) ==
"0.333333333333333"_expect );
231 CHECK (util::showComplete(val) ==
"0.33333333333333331"_expect);
232 CHECK (boost::lexical_cast<string>(val) ==
"0.33333333333333331"_expect);
234 CHECK (format4Csv(
double(1) / 3) ==
"0.333333333333333"_expect );
235 CHECK (format4Csv(
float(1) / 3) ==
"0.333333"_expect );
236 CHECK (format4Csv(f128(1) / 3) ==
"0.333333333333333333"_expect);
237 CHECK (format4Csv(
bool(1)) ==
"true"_expect );
238 CHECK (format4Csv(
bool(0)) ==
"false"_expect);
239 CHECK (format4Csv(
"Starship-3") ==
"\"Starship-3\""_expect );
240 CHECK (format4Csv(
Time(1,2,25,13)) ==
"\"13:25:02.001\""_expect);
244 int64_t ii = -100000;
248 CHECK (line ==
"-100000"_expect);
250 CHECK (line ==
"-100000,0.333333333333333"_expect);
252 CHECK (line ==
"-100000,0.333333333333333,true"_expect);
254 CHECK (line ==
"-100000,0.333333333333333,true,\"Raptor\""_expect);
258 CHECK (parse.isValid());
259 CHECK (*parse ==
"-100000"_expect);
260 CHECK (-100000 == parseAs<int>(*parse));
262 CHECK (parse.isValid());
263 CHECK (*parse ==
"0.333333333333333"_expect);
264 CHECK (0.333333343f == parseAs<float>(*parse));
266 CHECK (parse.isValid());
268 CHECK (*parse ==
"true"_expect);
269 CHECK (
true == parseAs<bool>(*parse));
271 CHECK (parse.isValid());
272 CHECK (*parse ==
"Raptor"_expect);
273 CHECK (
"Raptor" == parseAs<string>(*parse));
275 CHECK (not parse.isValid());
277 line =
" ◐0◑. ; \t \"' \" \n ,oh my ;";
279 CHECK (
"◐0◑." == *horror);
280 CHECK (0 == horror.getParsedFieldCnt());
282 CHECK (1 == horror.getParsedFieldCnt());
283 CHECK (
"' " == *horror);
285 CHECK (
"oh" == *horror);
286 CHECK (2 == horror.getParsedFieldCnt());
291 CHECK (not horror.isValid());
292 CHECK (horror.isParseFail());
305 fs::path f = temp.makeFile(
"dataz.csv");
306 std::ofstream content{f};
307 content << R
"("ID", "Value", "Offset")"<<endl 308 << R"( "one" , 5.5 ; +1 )"<<endl 309 << R"(;" 0 ";0)" <<endl; 313 CHECK (2 == dat.size());
314 CHECK (
"ID" == dat.id.header);
315 CHECK (
"Value" == dat.val.header);
316 CHECK (
"Offset" == dat.off.header);
318 CHECK (
"one" ==
string{dat.id});
319 CHECK ( 5.5 == dat.val);
320 CHECK ( 1 == dat.off);
321 CHECK (dat.id.data == vector<string>({
"",
"one"}));
322 CHECK (dat.val.data == vector<double>({0 ,5.5 }));
323 CHECK (dat.off.data == vector<int> ({0 ,1 }));
331 CHECK (dat.renderCSV() ==
332 R
"("ID","Value","Offset" 342 std::ifstream readback{f};
343 std::ostringstream inBuff;
344 inBuff << readback.rdbuf();
345 CHECK (inBuff.str() ==
346 R
"("ID","Value","Offset" 360 CHECK (
CSVLine(1,
"2",3.4,5555/55) ==
"1,\"2\",3.4,101"_expect);
361 CHECK (
CSVLine(
string{
"himself"}) ==
"\"himself\""_expect);
363 CHECK (
CSVLine{} ==
""_expect);
366 CHECK (appended ==
"5.5,\"⟂\""_expect);
368 CHECK (
CSVData({
"eeny",
"meeny",
"miny",
"moe"}) ==
"\"eeny\",\"meeny\",\"miny\",\"moe\"\n"_expect);
369 CHECK (
CSVData({
"eeny , meeny",
"miny",
"moe"}) ==
"\"eeny , meeny\"\n\"miny\"\n\"moe\"\n"_expect);
371 auto csv =
CSVData{{
"la",
"la",
"schland"}
373 ,{
"mit",
string{
"mia"},
Literal(
"ned")}
378 CHECK (csv.size() == 6);
379 CHECK (
string(csv) ==
380 R
"("la","la","schland" 388 VERIFY_FAIL ("Header mismatch in CSV file", TestTab{csv} );
390 csv =
CSVData{{
"ID",
"Value",
"Offset"}
393 VERIFY_FAIL (
"unable to parse \"toe\"", TestTab{csv} );
395 csv =
CSVData{{
"ID",
"Value",
"Offset"}
400 CHECK (dat.val == 1.0101e4);
401 CHECK (dat.renderCSV() == string(csv));
Wrapper to simplify notation in tests.
void appendCsvField(string &csv, VAL const &val)
Format and append a data value to a CSV string representation.
void verify_persistentDataFile()
inline string literal This is a marker type to indicate that
A string with the ability to construct or append the CSV-rendering of data fields.
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
Manage a temporary directory for storage, with automated clean-up.
Implementation namespace for support and library code.
Lumiera's internal time value datatype.
Token or Atom with distinct identity.
Manage a table with data records, stored persistently as CSV.
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
A collection of frequently used helper functions to support unit testing.
A RAII style temporary directory.
Table with data values, stored persistently as CSV file.
void demonnstrate_CSV_Notation()
a family of time value like entities and their relationships.
Parser to split one line of CSV data into fields.
#define VERIFY_FAIL(FAILURE_MSG, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises a std::exception, which additionally contains some FAI...