Skip to content
Permalink
Browse files

expression: more comments and test to avoid differences between opera…

…tors declaration and text values
  • Loading branch information
3nids committed Dec 12, 2014
1 parent d84af0d commit ea33122a5435fe8180ca8460b07866792adb86b0
Showing with 14 additions and 0 deletions.
  1. +2 −0 src/core/qgsexpression.cpp
  2. +9 −0 src/core/qgsexpression.h
  3. +3 −0 tests/src/core/testqgsexpression.cpp
@@ -212,6 +212,7 @@ inline bool isNull( const QVariant& v ) { return v.isNull(); }

const char* QgsExpression::BinaryOperatorText[] =
{
// this must correspond (number and order of element) to the declaration of the enum BinaryOperator
"OR", "AND",
"=", "<>", "<=", ">=", "<", ">", "~", "LIKE", "NOT LIKE", "ILIKE", "NOT ILIKE", "IS", "IS NOT",
"+", "-", "*", "/", "//", "%", "^",
@@ -220,6 +221,7 @@ const char* QgsExpression::BinaryOperatorText[] =

const char* QgsExpression::UnaryOperatorText[] =
{
// this must correspond (number and order of element) to the declaration of the enum UnaryOperator
"NOT", "-"
};

@@ -210,11 +210,20 @@ class CORE_EXPORT QgsExpression
*/
static double evaluateToDouble( const QString& text, const double fallbackValue );

/**
* @brief list of unary operators
* @note if any change is made here, the definition of QgsExpression::UnaryOperatorText[] must be adapted.
*/
enum UnaryOperator
{
uoNot,
uoMinus,
};

/**
* @brief list of binary operators
* @note if any change is made here, the definition of QgsExpression::BinaryOperatorText[] must be adapted.
*/
enum BinaryOperator
{
// logical
@@ -468,6 +468,9 @@ class TestQgsExpression: public QObject

void eval_precedence()
{
QCOMPARE(QgsExpression::BinaryOperatorText[QgsExpression::boDiv],"/");
QCOMPARE(QgsExpression::BinaryOperatorText[QgsExpression::boConcat],"||");

QgsExpression e0( "1+2*3" );
QCOMPARE( e0.evaluate().toInt(), 7 );

0 comments on commit ea33122

Please sign in to comment.
You can’t perform that action at this time.