mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#2031 Curve Calculator : Allow assignment without spaces around :=
This commit is contained in:
@@ -277,15 +277,17 @@ bool RimCalculation::calculate()
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
QString RimCalculation::findLeftHandSide(const QString& expresion)
|
QString RimCalculation::findLeftHandSide(const QString& expresion)
|
||||||
{
|
{
|
||||||
QString exprWithSpace = expresion;
|
int index = expresion.lastIndexOf(":=");
|
||||||
exprWithSpace.replace("\n", " ");
|
|
||||||
|
|
||||||
QStringList words = exprWithSpace.split(" ", QString::SkipEmptyParts);
|
|
||||||
|
|
||||||
int index = words.lastIndexOf(":=");
|
|
||||||
if (index > 0)
|
if (index > 0)
|
||||||
{
|
{
|
||||||
return words[index - 1];
|
QString s = expresion.left(index).simplified();
|
||||||
|
|
||||||
|
QStringList words = s.split(" ");
|
||||||
|
|
||||||
|
if (words.size() > 0)
|
||||||
|
{
|
||||||
|
return words.back();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
@@ -51,8 +51,9 @@ public:
|
|||||||
|
|
||||||
virtual caf::PdmFieldHandle* userDescriptionField() override;
|
virtual caf::PdmFieldHandle* userDescriptionField() override;
|
||||||
|
|
||||||
private:
|
|
||||||
static QString findLeftHandSide(const QString& expresion);
|
static QString findLeftHandSide(const QString& expresion);
|
||||||
|
|
||||||
|
private:
|
||||||
RimCalculationVariable* findByName(const QString& name) const;
|
RimCalculationVariable* findByName(const QString& name) const;
|
||||||
|
|
||||||
QString buildCalculationName() const;
|
QString buildCalculationName() const;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
#include "RimCalculation.h"
|
||||||
|
|
||||||
#include "expressionparser/ExpressionParser.h"
|
#include "expressionparser/ExpressionParser.h"
|
||||||
|
|
||||||
@@ -46,3 +47,33 @@ TEST(RicExpressionParserTest, DetectVariables)
|
|||||||
EXPECT_STREQ(variables[3].toStdString().data(), "y");
|
EXPECT_STREQ(variables[3].toStdString().data(), "y");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
TEST(RicExpressionParserTest, FindLeftHandSide)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
QString expr = "c := a";
|
||||||
|
|
||||||
|
QString s = RimCalculation::findLeftHandSide(expr);
|
||||||
|
|
||||||
|
EXPECT_STREQ(s.toStdString().data(), "c");
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
QString expr = "c:=a";
|
||||||
|
|
||||||
|
QString s = RimCalculation::findLeftHandSide(expr);
|
||||||
|
|
||||||
|
EXPECT_STREQ(s.toStdString().data(), "c");
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
QString expr = "\na:=b\n\nc:=a";
|
||||||
|
|
||||||
|
QString s = RimCalculation::findLeftHandSide(expr);
|
||||||
|
|
||||||
|
EXPECT_STREQ(s.toStdString().data(), "c");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user