Pastakhov has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/56906


Change subject: fix for math with union operator
......................................................................

fix for math with union operator

fix for test function testRun_echo_math_union()
echo 10 + 5 . 5  * 9 . 4 - 5 . 8;

Change-Id: I982a546cb8ebcdaf7e9ace216575f35366df5aff
---
M includes/Runtime.php
M tests/phpunit/includes/InterpreterTest.php
2 files changed, 24 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Foxway 
refs/changes/06/56906/1

diff --git a/includes/Runtime.php b/includes/Runtime.php
index b13ab6c..28061ec 100644
--- a/includes/Runtime.php
+++ b/includes/Runtime.php
@@ -48,17 +48,16 @@
        }
 
        public function addParam( $param ) {
+               \MWDebug::log( "function addParam( $param )" );
                if( $this->lastOperator ) {
                        switch ( $this->lastOperator ) {
-                               case '.':
-                                       $this->lastParam .= $param;
-                                       break;
                                case '*':
                                        $this->lastParam *= $param;
                                        break;
                                case '/':
                                        $this->lastParam /= $param;
                                        break;
+                               case '.':
                                case '+':
                                case '-':
                                        $this->mathMemory = 
array($this->lastParam, $this->lastOperator);
@@ -89,7 +88,8 @@
        }
 
        public function addOperator( $operator ) {
-               if( $this->mathMemory && ($operator=='+'||$operator=='-') ){
+               \MWDebug::log( "function addOperator( $operator )" );
+               if( $this->mathMemory && 
($operator=='+'||$operator=='-'||$operator=='.') ){
                        if( $this->mathMemory[1] == '+' ) {
                                $this->lastParam = $this->mathMemory[0] + 
$this->lastParam;
                        } elseif ( $this->mathMemory[1] == '-' ) {
@@ -100,6 +100,7 @@
                        $this->mathMemory = false;
                }
                $this->lastOperator = $operator;
+               \MWDebug::log( $this->lastParam );
        }
 
        public function getCommandResult( &$debug ) {
diff --git a/tests/phpunit/includes/InterpreterTest.php 
b/tests/phpunit/includes/InterpreterTest.php
index e4226ce..74951d1 100644
--- a/tests/phpunit/includes/InterpreterTest.php
+++ b/tests/phpunit/includes/InterpreterTest.php
@@ -130,6 +130,10 @@
                                '55'
                                );
                $this->assertEquals(
+                               Interpreter::run('echo 5 + 5 + 10 + 20 - 50 - 
5;'),
+                               '-15'
+                               );
+               $this->assertEquals(
                                Interpreter::run('echo 5 + 5 / 10 + 50/100;'),
                                '6'
                                );
@@ -159,4 +163,19 @@
                                "\$foo / \$bar = 100 / 5 = 20\n\n"
                                );
        }
+
+       public function testRun_echo_math_union() {
+               $this->assertEquals(
+                               Interpreter::run('echo 10 + 5 . 5;'),
+                               '155'
+                               );
+               $this->assertEquals(
+                               Interpreter::run('echo 10 + 5 . 5  * 9;'),
+                               '1545'
+                               );
+               $this->assertEquals(
+                               Interpreter::run('echo 10 + 5 . 5  * 9 . 4 - 5 
. 8;'),
+                               '154498'
+                               );
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/56906
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I982a546cb8ebcdaf7e9ace216575f35366df5aff
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Foxway
Gerrit-Branch: master
Gerrit-Owner: Pastakhov <pastak...@yandex.ru>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to