]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - extensions/ParserFunctions/tests/phpunit/ExpressionTest.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / extensions / ParserFunctions / tests / phpunit / ExpressionTest.php
1 <?php
2 class ExpressionTest extends MediaWikiTestCase {
3
4         /**
5          * @var ExprParser
6          */
7         protected $parser;
8
9         protected function setUp() {
10                 parent::setUp();
11                 $this->parser = new ExprParser();
12         }
13
14         /**
15          * @dataProvider provideExpressions
16          */
17         function testExpression( $input, $expected ) {
18                 $this->assertEquals(
19                         $expected,
20                         $this->parser->doExpression( $input )
21                 );
22         }
23
24         function provideExpressions() {
25                 return [
26                         [ '1 or 0', '1' ],
27                         [ 'not (1 and 0)', '1' ],
28                         [ 'not 0', '1' ],
29                         [ '4 < 5', '1' ],
30                         [ '-5 < 2', '1' ],
31                         [ '-2 <= -2', '1' ],
32                         [ '4 > 3', '1' ],
33                         [ '4 > -3', '1' ],
34                         [ '5 >= 2', '1' ],
35                         [ '2 >= 2', '1' ],
36                         [ '1 != 2', '1' ],
37                         [ '-4 * -4 = 4 * 4', '1' ],
38                         [ 'not (1 != 1)', '1' ],
39                         [ '1 + 1', '2' ],
40                         [ '-1 + 1', '0' ],
41                         [ '+1 + 1', '2' ],
42                         [ '4 * 4', '16' ],
43                         [ '(1/3) * 3', '1' ],
44                         [ '3 / 1.5', '2' ],
45                         [ '3 / 0.2', '15' ],
46                         [ '3 / ( 2.0 * 0.1 )', '15' ],
47                         [ '3 / ( 2.0 / 10 )', '15' ],
48                         [ '3 / (- 0.2 )', '-15' ],
49                         [ '3 / abs( 0.2 )', '15' ],
50                         [ '3 mod 2', '1' ],
51                         [ '1e4', '10000' ],
52                         [ '1e-2', '0.01' ],
53                         [ '4.0 round 0', '4' ],
54                         [ 'ceil 4', '4' ],
55                         [ 'floor 4', '4' ],
56                         [ '4.5 round 0', '5' ],
57                         [ '4.2 round 0', '4' ],
58                         [ '-4.2 round 0', '-4' ],
59                         [ '-4.5 round 0', '-5' ],
60                         [ '-2.0 round 0', '-2' ],
61                         [ 'ceil -3', '-3' ],
62                         [ 'floor -6.0', '-6' ],
63                         [ 'ceil 4.2', '5' ],
64                         [ 'ceil -4.5', '-4' ],
65                         [ 'floor -4.5', '-5' ],
66                         [ 'abs(-2)', '2' ],
67                         [ 'ln(exp(1))', '1' ],
68                         [ 'trunc(4.5)', '4' ],
69                         [ 'trunc(-4.5)', '-4' ],
70                         [ '123 fmod (2^64-1)', '123' ],
71                         [ '5.7 mod 1.3', '0' ],
72                         [ '5.7 fmod 1.3', '0.5' ],
73                 ];
74         }
75 }