#2576 Command File : Add support for comments

This commit is contained in:
Magne Sjaastad
2018-03-06 12:35:02 +01:00
parent ce2b4febbb
commit ec96edf266
4 changed files with 85 additions and 4 deletions

View File

@@ -79,3 +79,12 @@ QChar RicfMessages::peekNextChar(QTextStream& inputStream)
}
return ch;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicfMessages::skipLineWithLineNumberCount(QTextStream& inputStream)
{
inputStream.readLine();
m_currentLineNumber++;
}

View File

@@ -37,6 +37,8 @@ public:
void addError(const QString& message);
void skipWhiteSpaceWithLineNumberCount(QTextStream& inputStream);
void skipLineWithLineNumberCount(QTextStream& inputStream);
QChar readCharWithLineNumberCount(QTextStream& inputStream);
QChar peekNextChar(QTextStream& inputStream);

View File

@@ -45,9 +45,15 @@ std::vector<RicfCommandObject*> RicfCommandFileReader::readCommands(QTextStream&
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
while ( !inputStream.atEnd() )
{
QChar currentChar;
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
if ( currentChar.isSpace() )
QChar currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
if (currentChar == QChar('#'))
{
errorMessageContainer->skipLineWithLineNumberCount(inputStream);
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
currentChar = QChar();
}
else if ( currentChar.isSpace() )
{
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
QChar isBracket('a');
@@ -65,7 +71,11 @@ std::vector<RicfCommandObject*> RicfCommandFileReader::readCommands(QTextStream&
{
break;
}
commandName += currentChar;
if (!currentChar.isNull())
{
commandName += currentChar;
}
}
}

View File

@@ -205,3 +205,63 @@ TEST(RicfCommands, TransformFileCommandObjectsToExecutableCommandObjects)
delete(obj);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(RicfCommands, IgnoreCommentLines)
{
QString commandString = R"(
replaceCase(newGridFile="/1.EGRID", caseId=1)
# replaceCase(newGridFile="/2.EGRID", caseId=2)
openProject(path="/home/user/ResInsightProject.rsp")
replaceCase(newGridFile="/3.EGRID", caseId=3)
# replaceCase(newGridFile="/4.EGRID", caseId=4)
exportSnapshots()
replaceCase(newGridFile="/6.EGRID", caseId=6)
replaceCase(newGridFile="/7.EGRID", caseId=7)
closeProject()
)";
QTextStream inputStream(&commandString);
RicfMessages errors;
auto objects = RicfCommandFileReader::readCommands(inputStream, caf::PdmDefaultObjectFactory::instance(), &errors);
EXPECT_TRUE(errors.m_messages.empty());
EXPECT_EQ((size_t)7, objects.size());
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST(RicfCommands, IgnoreCommentLinesShowErrorLine)
{
QString commandString = R"(
replaceCase(newGridFile="/1.EGRID", caseId=1)
# replaceCase(newGridFile="/2.EGRID", caseId=2)
openProject(path="/home/user/ResInsightProject.rsp")
replaceCase(newGridFile="/3.EGRID", caseId=3)
# replaceCase(newGridFile="/4.EGRID", caseId=4)
exportSnapshots()
sdareplaceCase(newGridFile="/6.EGRID", caseId=6)
replaceCase(newGridFile="/7.EGRID", caseId=7)
closeProject()
)";
QTextStream inputStream(&commandString);
RicfMessages errors;
auto objects = RicfCommandFileReader::readCommands(inputStream, caf::PdmDefaultObjectFactory::instance(), &errors);
EXPECT_EQ((size_t)1, errors.m_messages.size());
EXPECT_EQ((size_t)6, objects.size());
}