Pastakhov has submitted this change and it was merged.
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, 21 insertions(+), 4 deletions(-)
Approvals:
Pastakhov: Verified; Looks good to me, approved
diff --git a/includes/Runtime.php b/includes/Runtime.php
index b13ab6c..e9697a5 100644
--- a/includes/Runtime.php
+++ b/includes/Runtime.php
@@ -50,15 +50,13 @@
public 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 +87,7 @@
}
public function addOperator( $operator ) {
- if( $this->mathMemory && ($operator=='+'||$operator=='-') ){
+ if( $this->mathMemory &&
($operator=='+'||$operator=='-'||$operator=='.') ){
if( $this->mathMemory[1] == '+' ) {
$this->lastParam = $this->mathMemory[0] +
$this->lastParam;
} elseif ( $this->mathMemory[1] == '-' ) {
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: merged
Gerrit-Change-Id: I982a546cb8ebcdaf7e9ace216575f35366df5aff
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Foxway
Gerrit-Branch: master
Gerrit-Owner: Pastakhov <[email protected]>
Gerrit-Reviewer: Pastakhov <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits