aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/diceparser.cpp
diff options
context:
space:
mode:
authorRenaud G <renaud@rolisteam.org>2019-07-11 22:57:21 +0200
committerRenaud G <renaud@rolisteam.org>2019-07-11 23:28:42 +0200
commit48c470b72cf32c49dc146f5859d67708759997b2 (patch)
tree4205c6ef6b95830edb507cc8ee68bb1bf7c00ab4 /diceparser.cpp
parent69373b4ec96b7d510e16fccfa1b9f2a2ec790508 (diff)
downloadOneRoll-48c470b72cf32c49dc146f5859d67708759997b2.tar.gz
OneRoll-48c470b72cf32c49dc146f5859d67708759997b2.zip
rework diceparser to run unit tests
Diffstat (limited to 'diceparser.cpp')
-rw-r--r--diceparser.cpp50
1 files changed, 31 insertions, 19 deletions
diff --git a/diceparser.cpp b/diceparser.cpp
index f5d543f..18be076 100644
--- a/diceparser.cpp
+++ b/diceparser.cpp
@@ -33,7 +33,6 @@
#include "node/groupnode.h"
#include "node/helpnode.h"
#include "node/ifnode.h"
-#include "node/uniquenode.h"
#include "node/jumpbackwardnode.h"
#include "node/keepdiceexecnode.h"
#include "node/listaliasnode.h"
@@ -49,8 +48,15 @@
#include "node/splitnode.h"
#include "node/startingnode.h"
#include "node/stringnode.h"
+#include "node/uniquenode.h"
#include "node/variablenode.h"
+#include "booleancondition.h"
+#include "node/dicerollernode.h"
+#include "parsingtoolbox.h"
+#include "range.h"
+#include "validator.h"
+
#define DEFAULT_FACES_NUMBER 10
DiceParser::DiceParser()
@@ -174,7 +180,8 @@ bool DiceParser::parseLine(QString str, bool allowAlias)
bool value= hasInstruction;
if(!hasInstruction)
{
- m_errorMap.insert(ExecutionNode::NOTHING_UNDERSTOOD,
+ m_errorMap.insert(
+ ExecutionNode::NOTHING_UNDERSTOOD,
QObject::tr("Nothing was understood. To roll dice: !1d6 - full documation: "
"<a "
"href=\"https://github.com/Rolisteam/DiceParser/blob/master/HelpMe.md\">https://github.com/"
@@ -183,7 +190,8 @@ bool DiceParser::parseLine(QString str, bool allowAlias)
else if(hasInstruction && !str.isEmpty())
{
auto i= m_command.size() - str.size();
- m_warningMap.insert(ExecutionNode::UNEXPECTED_CHARACTER,
+ m_warningMap.insert(
+ ExecutionNode::UNEXPECTED_CHARACTER,
QObject::tr("Unexpected character at %1 - end of command was ignored \"%2\"").arg(i).arg(str));
}
@@ -221,7 +229,7 @@ bool DiceParser::readExpression(QString& str, ExecutionNode*& node)
else
{
m_warningMap.insert(ExecutionNode::BAD_SYNTAXE,
- QObject::tr("Expected closing parenthesis - can't validate the inside."));
+ QObject::tr("Expected closing parenthesis - can't validate the inside."));
}
}
}
@@ -465,7 +473,7 @@ void DiceParser::getDiceResultFromAllInstruction(QList<ExportedDiceResult>& resu
faces= die->getFaces();
// qDebug() << "face" << faces;
HighLightDice hlDice(die->getListValue(), die->isHighlighted(), die->getColor(),
- die->hasBeenDisplayed(), die->getFaces());
+ die->hasBeenDisplayed(), die->getFaces());
list.append(hlDice);
}
nodeResult.insert(faces, list);
@@ -512,8 +520,8 @@ void DiceParser::getLastDiceResult(QList<ExportedDiceResult>& diceValuesList, bo
valuesResult.append(i);
}
}
- HighLightDice hlDice(
- valuesResult, die->isHighlighted(), die->getColor(), die->hasBeenDisplayed(), 0);
+ HighLightDice hlDice(valuesResult, die->isHighlighted(), die->getColor(),
+ die->hasBeenDisplayed(), 0);
listpair.append(hlDice);
}
}
@@ -649,7 +657,8 @@ bool DiceParser::readDice(QString& str, ExecutionNode*& node)
{
if(max < 1)
{
- m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,
+ m_errorMap.insert(
+ ExecutionNode::BAD_SYNTAXE,
QObject::tr("Dice with %1 face(s) does not exist. Please, put a value higher than 0").arg(max));
return false;
}
@@ -703,7 +712,8 @@ bool DiceParser::readDice(QString& str, ExecutionNode*& node)
}
else
{
- m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,
+ m_errorMap.insert(
+ ExecutionNode::BAD_SYNTAXE,
QObject::tr(
"List is missing after the L operator. Please, add it (e.g : 1L[sword,spear,gun,arrow])"));
}
@@ -1032,7 +1042,7 @@ bool DiceParser::readOption(QString& str, ExecutionNode* previous) //,
else
{
m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,
- QObject::tr("Validator is missing after the c operator. Please, change it"));
+ QObject::tr("Validator is missing after the c operator. Please, change it"));
}
}
break;
@@ -1046,7 +1056,8 @@ bool DiceParser::readOption(QString& str, ExecutionNode* previous) //,
{
if(!m_parsingToolbox->isValidValidator(previous, validator))
{
- m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,
+ m_errorMap.insert(
+ ExecutionNode::BAD_SYNTAXE,
QObject::tr("Validator is missing after the %1 operator. Please, change it")
.arg(operatorName == Reroll ? "r" : "a"));
}
@@ -1067,11 +1078,12 @@ bool DiceParser::readOption(QString& str, ExecutionNode* previous) //,
else
{
m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,
- QObject::tr("Validator is missing after the %1 operator. Please, change it")
- .arg(operatorName == Reroll ? QStringLiteral("r") :
- operatorName == RerollUntil ?
- QStringLiteral("R") :
- operatorName == RerollAndAdd ? QStringLiteral("a") : ""));
+ QObject::tr("Validator is missing after the %1 operator. Please, change it")
+ .arg(operatorName == Reroll ?
+ QStringLiteral("r") :
+ operatorName == RerollUntil ?
+ QStringLiteral("R") :
+ operatorName == RerollAndAdd ? QStringLiteral("a") : ""));
}
}
break;
@@ -1083,8 +1095,8 @@ bool DiceParser::readOption(QString& str, ExecutionNode* previous) //,
if(!m_parsingToolbox->isValidValidator(previous, validator))
{
m_errorMap.insert(ExecutionNode::ENDLESS_LOOP_ERROR,
- QObject::tr("This condition %1 introduces an endless loop. Please, change it")
- .arg(validator->toString()));
+ QObject::tr("This condition %1 introduces an endless loop. Please, change it")
+ .arg(validator->toString()));
}
ExplodeDiceNode* explodedNode= new ExplodeDiceNode();
explodedNode->setValidator(validator);
@@ -1095,7 +1107,7 @@ bool DiceParser::readOption(QString& str, ExecutionNode* previous) //,
else
{
m_errorMap.insert(ExecutionNode::BAD_SYNTAXE,
- QObject::tr("Validator is missing after the e operator. Please, change it"));
+ QObject::tr("Validator is missing after the e operator. Please, change it"));
}
}
break;