From 48c470b72cf32c49dc146f5859d67708759997b2 Mon Sep 17 00:00:00 2001 From: Renaud G Date: Thu, 11 Jul 2019 22:57:21 +0200 Subject: rework diceparser to run unit tests --- diceparser.cpp | 50 +++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 19 deletions(-) (limited to 'diceparser.cpp') 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: " "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& 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& 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; -- cgit v1.2.3-70-g09d2