Pastakhov has uploaded a new change for review.
https://gerrit.wikimedia.org/r/56904
Change subject: fix for math with variables
......................................................................
fix for math with variables
fix for failed test function testRun_echo_math_variables()
echo "\$foo * \$bar = $foo * $bar = ", $foo * $bar, "\n\n";
Change-Id: I162e218cf308b7b97f0affc8ba0fc6d785010e9d
---
M includes/Interpreter.php
M tests/phpunit/includes/InterpreterTest.php
2 files changed, 16 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Foxway
refs/changes/04/56904/1
diff --git a/includes/Interpreter.php b/includes/Interpreter.php
index 58ad48e..0f2d4ba 100644
--- a/includes/Interpreter.php
+++ b/includes/Interpreter.php
@@ -192,7 +192,6 @@
$debug[] = '<span
style="color:#CE7B00" title="'. token_name($id) . '">' .
htmlspecialchars($text) . '</span>';
}
$runtime->addParam(
self::process_slashes($text, false) );
- $runtime->addOperator('.');
break;
case T_VARIABLE:
if( $expected && in_array(T_VARIABLE,
$expected) ) {
@@ -256,8 +255,8 @@
$pattern = array('/(\\\\\\\\)*+\\\\\'/', '/\\\\\\\\/');
$replacement = array('$1\'', '\\');
} else {
- //
(\\)*+\" \n \r
\t \v \$ \\
- $pattern = array('/(\\\\\\\\)*+\\\\"/', '/\\\\n/',
'/\\\\r/', '/\\\\t/', '/\\\\v/', '/\\\\$/', '/\\\\\\\\/');
+ //
(\\)*+\" (\\)*+\n
(\\)*+\r (\\)*+\t
(\\)*+\v (\\)*+\$ \\
+ $pattern = array('/(\\\\\\\\)*+\\\\"/',
'/(\\\\\\\\)*+\\\\n/', '/(\\\\\\\\)*+\\\\r/', '/(\\\\\\\\)*+\\\\t/',
'/(\\\\\\\\)*+\\\\v/', '/(\\\\\\\\)*+\\\\\$/', '/\\\\\\\\/');
$replacement = array('$1"', "\n", "\r", "\t", "\v",
'$', '\\');
}
return preg_replace($pattern, $replacement, $string);
diff --git a/tests/phpunit/includes/InterpreterTest.php
b/tests/phpunit/includes/InterpreterTest.php
index ed05291..e4226ce 100644
--- a/tests/phpunit/includes/InterpreterTest.php
+++ b/tests/phpunit/includes/InterpreterTest.php
@@ -145,4 +145,18 @@
"10 + 5 * 5 = 35\n\n"
);
}
+
+ public function testRun_echo_math_variables() {
+ $this->assertEquals(
+ Interpreter::run('
+$foo = 100;
+$bar = \'5\';
+echo "\$foo * \$bar = $foo * $bar = ", $foo * $bar, "\n\n";'),
+ "\$foo * \$bar = 100 * 5 = 500\n\n"
+ );
+ $this->assertEquals(
+ Interpreter::run('echo "\$foo / \$bar = $foo /
$bar = ", $foo / $bar, "\n\n";'),
+ "\$foo / \$bar = 100 / 5 = 20\n\n"
+ );
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/56904
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I162e218cf308b7b97f0affc8ba0fc6d785010e9d
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