Pastakhov has uploaded a new change for review.

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


Change subject: fix for math multiple params
......................................................................

fix for math multiple params

fix for failed test function testRun_echo_math_params()
echo '10 + 5 * 5 = ', 10 + 5 * 5, "\n\n";

Change-Id: I8638fa21bbe373b90cd80c3a4abf7587416da3dc
---
M includes/Interpreter.php
M includes/Runtime.php
M tests/phpunit/includes/InterpreterTest.php
3 files changed, 35 insertions(+), 7 deletions(-)


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

diff --git a/includes/Interpreter.php b/includes/Interpreter.php
index bf592c0..58ad48e 100644
--- a/includes/Interpreter.php
+++ b/includes/Interpreter.php
@@ -69,6 +69,9 @@
                                                $expectQuotesClose = true;
                                                $expected = 
array(T_ENCAPSED_AND_WHITESPACE, T_CURLY_OPEN, T_VARIABLE, '"');
                                        }
+                                       if($expectListParams){
+                                               $expected[] = ',';
+                                       }
                                        break;
                                case ';':
                                        $return .= 
$runtime->getCommandResult($debug);
@@ -128,7 +131,7 @@
                                                        T_VARIABLE,
                                                        T_CURLY_OPEN,
                                                        '"',
-                                                       ';',
+                                                       //';',
                                                        );
                                        } else {
                                                $return .= '<br><span 
class="error">' . wfMessage( 'foxway-php-syntax-error-unexpected', '\' } \'', 
$line )->escaped() . '</span>';
@@ -180,6 +183,9 @@
                                        }
                                        $runtime->addParam( $text );
                                        $expected = array(';', '.', '+', '-', 
'*', '/');
+                                       if($expectListParams){
+                                               $expected[] = ',';
+                                       }
                                        break;
                                case T_ENCAPSED_AND_WHITESPACE:
                                        if($is_debug) {
diff --git a/includes/Runtime.php b/includes/Runtime.php
index caca417..b13ab6c 100644
--- a/includes/Runtime.php
+++ b/includes/Runtime.php
@@ -52,28 +52,35 @@
                        switch ( $this->lastOperator ) {
                                case '.':
                                        $this->lastParam .= $param;
-                                       $this->lastOperator = false;
                                        break;
                                case '*':
                                        $this->lastParam *= $param;
-                                       $this->lastOperator = false;
                                        break;
                                case '/':
                                        $this->lastParam /= $param;
-                                       $this->lastOperator = false;
                                        break;
                                case '+':
                                case '-':
                                        $this->mathMemory = 
array($this->lastParam, $this->lastOperator);
                                        $this->lastParam = $param;
-                                       $this->lastOperator = false;
                                        break;
                                default:
                                        // TODO
                                        \MWDebug::log( 'Error! Unknown operator 
"' . htmlspecialchars($this->lastOperator) . '" in ' . __METHOD__ );
                                        break;
                        }
+                       $this->lastOperator = false;
                } else {
+                       if( $this->mathMemory ) {
+                               if( $this->mathMemory[1] == '+' ) {
+                                       $this->lastParam = $this->mathMemory[0] 
+ $this->lastParam;
+                               } elseif ( $this->mathMemory[1] == '-' ) {
+                                       $this->lastParam = $this->mathMemory[0] 
- $this->lastParam;
+                               } else { // $this->mathMemory[1] == '.'
+                                       $this->lastParam = $this->mathMemory[0] 
. $this->lastParam;
+                               }
+                               $this->mathMemory = false;
+                       }
                        if( !is_null($this->lastParam) ) {
                                $this->listParams[] = $this->lastParam;
                        }
@@ -85,8 +92,10 @@
                if( $this->mathMemory && ($operator=='+'||$operator=='-') ){
                        if( $this->mathMemory[1] == '+' ) {
                                $this->lastParam = $this->mathMemory[0] + 
$this->lastParam;
-                       } else { // $this->mathMemory[1] == '-'
+                       } elseif ( $this->mathMemory[1] == '-' ) {
                                $this->lastParam = $this->mathMemory[0] - 
$this->lastParam;
+                       } else { // $this->mathMemory[1] == '.'
+                               $this->lastParam = $this->mathMemory[0] . 
$this->lastParam;
                        }
                        $this->mathMemory = false;
                }
@@ -97,8 +106,10 @@
                if( $this->mathMemory ) {
                        if( $this->mathMemory[1] == '+' ) {
                                $this->lastParam = $this->mathMemory[0] + 
$this->lastParam;
-                       } else { // $this->mathMemory[1] == '-'
+                       } elseif ( $this->mathMemory[1] == '-' ) {
                                $this->lastParam = $this->mathMemory[0] - 
$this->lastParam;
+                       } else { // $this->mathMemory[1] == '.'
+                               $this->lastParam = $this->mathMemory[0] . 
$this->lastParam;
                        }
                        $this->mathMemory = false;
                }
diff --git a/tests/phpunit/includes/InterpreterTest.php 
b/tests/phpunit/includes/InterpreterTest.php
index 5d0bd1c..ed05291 100644
--- a/tests/phpunit/includes/InterpreterTest.php
+++ b/tests/phpunit/includes/InterpreterTest.php
@@ -100,6 +100,10 @@
                                Interpreter::run('echo "start" . $foo . 
"end";'),
                                'startfoobarend'
                                );
+               $this->assertEquals(
+                               Interpreter::run('echo "This ", \'string \', 
"was $foo ", \'with multiple parameters.\';'),
+                               'This string was foobar with multiple 
parameters.'
+                               );
        }
 
        public function testRun_echo_escaping() {
@@ -134,4 +138,11 @@
                                '-395.55555555556'
                                );
        }
+
+       public function testRun_echo_math_params() {
+               $this->assertEquals(
+                               Interpreter::run('echo \'10 + 5 * 5 = \', 10 + 
5 * 5, "\n\n";'),
+                               "10 + 5 * 5 = 35\n\n"
+                               );
+       }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8638fa21bbe373b90cd80c3a4abf7587416da3dc
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Foxway
Gerrit-Branch: master
Gerrit-Owner: Pastakhov <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to