use spaces instead of tab
This commit is contained in:
@@ -28,70 +28,70 @@ using namespace ebusd;
|
||||
static bool error = false;
|
||||
|
||||
void verify(bool expectFailMatch, string type, string input,
|
||||
bool match, string expectStr, string gotStr) {
|
||||
match = match && expectStr == gotStr;
|
||||
if (expectFailMatch) {
|
||||
if (match) {
|
||||
cout << " failed " << type << " match >" << input
|
||||
<< "< error: unexpectedly succeeded" << endl;
|
||||
error = true;
|
||||
} else {
|
||||
cout << " failed " << type << " match >" << input << "< OK" << endl;
|
||||
}
|
||||
} else if (match) {
|
||||
cout << " " << type << " match >" << input << "< OK" << endl;
|
||||
} else {
|
||||
cout << " " << type << " match >" << input << "< error: got >"
|
||||
<< gotStr << "<, expected >" << expectStr << "<" << endl;
|
||||
error = true;
|
||||
}
|
||||
bool match, string expectStr, string gotStr) {
|
||||
match = match && expectStr == gotStr;
|
||||
if (expectFailMatch) {
|
||||
if (match) {
|
||||
cout << " failed " << type << " match >" << input
|
||||
<< "< error: unexpectedly succeeded" << endl;
|
||||
error = true;
|
||||
} else {
|
||||
cout << " failed " << type << " match >" << input << "< OK" << endl;
|
||||
}
|
||||
} else if (match) {
|
||||
cout << " " << type << " match >" << input << "< OK" << endl;
|
||||
} else {
|
||||
cout << " " << type << " match >" << input << "< error: got >"
|
||||
<< gotStr << "<, expected >" << expectStr << "<" << endl;
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
istringstream ifs(
|
||||
"line 1 col 1,line 1 col 2,line 1 col 3\n"
|
||||
"line 2 col 1,\"line 2 col 2\",\"line 2 \"\"col 3\"\"\"\n"
|
||||
"line 4 col 1,\"line 4 col 2 part 1\n"
|
||||
"line 4 col 2 part 2\",line 4 col 3\n"
|
||||
",,,\n"
|
||||
"line 6 col 1,,line 6 col 3\n"
|
||||
"line 8 col 1,\"line 8 col 2 part 1;\n"
|
||||
"line 8 col 2 part 2\",line 8 col 3\n"
|
||||
);
|
||||
string resultlines[][3] = {
|
||||
{"line 1 col 1", "line 1 col 2", "line 1 col 3"},
|
||||
{"line 2 col 1", "line 2 col 2", "line 2 \"col 3\""},
|
||||
{"", "", ""},
|
||||
{"line 4 col 1", "line 4 col 2 part 1;line 4 col 2 part 2", "line 4 col 3"},
|
||||
{"", "", ""},
|
||||
{"line 6 col 1", "", "line 6 col 3"},
|
||||
{"", "", ""},
|
||||
{"line 8 col 1", "line 8 col 2 part 1;line 8 col 2 part 2", "line 8 col 3"},
|
||||
};
|
||||
unsigned int lineNo = 0;
|
||||
vector<string> row;
|
||||
istringstream ifs(
|
||||
"line 1 col 1,line 1 col 2,line 1 col 3\n"
|
||||
"line 2 col 1,\"line 2 col 2\",\"line 2 \"\"col 3\"\"\"\n"
|
||||
"line 4 col 1,\"line 4 col 2 part 1\n"
|
||||
"line 4 col 2 part 2\",line 4 col 3\n"
|
||||
",,,\n"
|
||||
"line 6 col 1,,line 6 col 3\n"
|
||||
"line 8 col 1,\"line 8 col 2 part 1;\n"
|
||||
"line 8 col 2 part 2\",line 8 col 3\n"
|
||||
);
|
||||
string resultlines[][3] = {
|
||||
{"line 1 col 1", "line 1 col 2", "line 1 col 3"},
|
||||
{"line 2 col 1", "line 2 col 2", "line 2 \"col 3\""},
|
||||
{"", "", ""},
|
||||
{"line 4 col 1", "line 4 col 2 part 1;line 4 col 2 part 2", "line 4 col 3"},
|
||||
{"", "", ""},
|
||||
{"line 6 col 1", "", "line 6 col 3"},
|
||||
{"", "", ""},
|
||||
{"line 8 col 1", "line 8 col 2 part 1;line 8 col 2 part 2", "line 8 col 3"},
|
||||
};
|
||||
unsigned int lineNo = 0;
|
||||
vector<string> row;
|
||||
|
||||
while (FileReader::splitFields(ifs, row, lineNo)) {
|
||||
cout << "line " << static_cast<unsigned>(lineNo) << ": split OK" << endl;
|
||||
string resultline[3] = resultlines[lineNo-1];
|
||||
if (row.empty()) {
|
||||
cout << " result empty";
|
||||
if (resultline[0] == "") {
|
||||
cout << ": OK" << endl;
|
||||
} else {
|
||||
cout << ": error" << endl;
|
||||
error = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
for (vector<string>::iterator it = row.begin(); it != row.end(); it++) {
|
||||
string got = *it;
|
||||
string expect = resultline[distance(row.begin(), it)];
|
||||
ostringstream type;
|
||||
type << "line " << static_cast<unsigned>(lineNo) << " col " << static_cast<size_t>(distance(row.begin(), it)+1);
|
||||
verify(false, type.str(), expect, got == expect, expect, got);
|
||||
}
|
||||
}
|
||||
while (FileReader::splitFields(ifs, row, lineNo)) {
|
||||
cout << "line " << static_cast<unsigned>(lineNo) << ": split OK" << endl;
|
||||
string resultline[3] = resultlines[lineNo-1];
|
||||
if (row.empty()) {
|
||||
cout << " result empty";
|
||||
if (resultline[0] == "") {
|
||||
cout << ": OK" << endl;
|
||||
} else {
|
||||
cout << ": error" << endl;
|
||||
error = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
for (vector<string>::iterator it = row.begin(); it != row.end(); it++) {
|
||||
string got = *it;
|
||||
string expect = resultline[distance(row.begin(), it)];
|
||||
ostringstream type;
|
||||
type << "line " << static_cast<unsigned>(lineNo) << " col " << static_cast<size_t>(distance(row.begin(), it)+1);
|
||||
verify(false, type.str(), expect, got == expect, expect, got);
|
||||
}
|
||||
}
|
||||
|
||||
return error ? 1 : 0;
|
||||
return error ? 1 : 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user