mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ParserFunctions
synced 2024-11-15 20:09:43 +00:00
0fb7807e9a
In trying to fix bug 35866, I32c9eca6 changed the behavior of 'mod' to no longer cast its arguments to integers, which conventiently also solved bug 6068. However, this also broke many existing uses that depended on that casting. This change reverts 'mod' to its old behavior while still solving bug 35866, and at the same time adds a new 'fmod' operator with the new behavior to keep bug 6068 fixed as well. Change-Id: I6114c6e769119e6ced61b3b55b6f70b03b5b1ebe
77 lines
1.8 KiB
PHP
77 lines
1.8 KiB
PHP
<?php
|
|
class ExpressionTest extends MediaWikiTestCase {
|
|
|
|
/**
|
|
* @var ExprParser
|
|
*/
|
|
protected $parser;
|
|
|
|
protected function setUp() {
|
|
parent::setUp();
|
|
$this->parser = new ExprParser();
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideExpressions
|
|
*/
|
|
function testExpression( $input, $expected ) {
|
|
$this->assertEquals(
|
|
$expected,
|
|
$this->parser->doExpression( $input )
|
|
);
|
|
}
|
|
|
|
function provideExpressions() {
|
|
return array(
|
|
array( '1 or 0', '1' ),
|
|
array( 'not (1 and 0)', '1' ),
|
|
array( 'not 0', '1' ),
|
|
array( '4 < 5', '1' ),
|
|
array( '-5 < 2', '1' ),
|
|
array( '-2 <= -2', '1' ),
|
|
array( '4 > 3', '1' ),
|
|
array( '4 > -3', '1' ),
|
|
array( '5 >= 2', '1' ),
|
|
array( '2 >= 2', '1' ),
|
|
array( '1 != 2', '1' ),
|
|
array( '-4 * -4 = 4 * 4', '1' ),
|
|
array( 'not (1 != 1)', '1' ),
|
|
array( '1 + 1', '2' ),
|
|
array( '-1 + 1', '0' ),
|
|
array( '+1 + 1', '2' ),
|
|
array( '4 * 4', '16' ),
|
|
array( '(1/3) * 3', '1' ),
|
|
array( '3 / 1.5', '2' ),
|
|
array( '3 / 0.2', '15' ),
|
|
array( '3 / ( 2.0 * 0.1 )', '15' ),
|
|
array( '3 / ( 2.0 / 10 )', '15' ),
|
|
array( '3 / (- 0.2 )', '-15' ),
|
|
array( '3 / abs( 0.2 )', '15' ),
|
|
array( '3 mod 2', '1' ),
|
|
array( '1e4', '10000' ),
|
|
array( '1e-2', '0.01' ),
|
|
array( '4.0 round 0', '4' ),
|
|
array( 'ceil 4', '4' ),
|
|
array( 'floor 4', '4' ),
|
|
array( '4.5 round 0', '5' ),
|
|
array( '4.2 round 0', '4' ),
|
|
array( '-4.2 round 0', '-4' ),
|
|
array( '-4.5 round 0', '-5' ),
|
|
array( '-2.0 round 0', '-2' ),
|
|
array( 'ceil -3', '-3' ),
|
|
array( 'floor -6.0', '-6' ),
|
|
array( 'ceil 4.2', '5' ),
|
|
array( 'ceil -4.5', '-4' ),
|
|
array( 'floor -4.5', '-5' ),
|
|
array( 'abs(-2)', '2' ),
|
|
array( 'ln(exp(1))', '1' ),
|
|
array( 'trunc(4.5)', '4' ),
|
|
array( 'trunc(-4.5)', '-4' ),
|
|
array( '123 fmod (2^64-1)', '123' ),
|
|
array( '5.7 mod 1.3', '0' ),
|
|
array( '5.7 fmod 1.3', '0.5' ),
|
|
);
|
|
}
|
|
}
|
|
|