1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-06-14 05:07:05 +01:00

consistency of tests

This commit is contained in:
Guido Cossu
2016-12-13 02:24:20 +00:00
parent 7bc2065113
commit ef72f322d2
4 changed files with 80 additions and 19 deletions

View File

@ -28,10 +28,14 @@
*************************************************************************************/
/* END LEGAL */
#include <Grid.h>
#include <ctype.h>
using namespace Grid;
using namespace std;
#define GRID_TEXT_INDENT 2 //number of spaces for indentation of levels
// Writer implementation ///////////////////////////////////////////////////////
TextWriter::TextWriter(const string &fileName)
: file_(fileName, ios::out)
@ -50,9 +54,8 @@ void TextWriter::pop(void)
void TextWriter::indent(void)
{
for (int i = 0; i < level_; ++i)
{
file_ << '\t';//is this portable?
}
for (int t = 0; t < GRID_TEXT_INDENT; t++)
file_ << ' ';
};
// Reader implementation ///////////////////////////////////////////////////////
@ -61,7 +64,7 @@ TextReader::TextReader(const string &fileName)
file_.open(fileName, ios::in);
if (!file_.is_open()) {
std::cout << GridLogMessage << "TextReader: Error opening file " << fileName << std::endl;
exit(0);// write better error handling
exit(1);// write better error handling
}
}
@ -81,12 +84,15 @@ void TextReader::checkIndent(void)
for (int i = 0; i < level_; ++i)
{
bool check = true;
for (int t = 0; t< GRID_TEXT_INDENT; t++){
file_.get(c);
if (c != '\t')
check = check && isspace(c);
}
if (!check)
{
cerr << "TextReader: mismatch on tab " << c << " level " << level_;
cerr << " i "<< i << endl;
abort();
cerr << "TextReader: mismatch on level " << level_ << std::endl;
exit(1);
}
}
}