| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Math\Tests\WikiTexVC\Nodes; |
| 4 |
|
| 5 |
use ArgumentCountError; |
| 6 |
use MediaWiki\Extension\Math\WikiTexVC\Nodes\Literal; |
| 7 |
use MediaWiki\Extension\Math\WikiTexVC\Nodes\Lr; |
| 8 |
use MediaWiki\Extension\Math\WikiTexVC\Nodes\TexArray; |
| 9 |
use MediaWikiUnitTestCase; |
| 10 |
use TypeError; |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
class LrTest extends MediaWikiUnitTestCase { |
| 16 |
|
| 17 |
public function testEmptyLr() { |
| 18 |
$this->expectException( ArgumentCountError::class ); |
| 19 |
new Lr(); |
| 20 |
throw new ArgumentCountError( 'Should not create an empty lr' ); |
| 21 |
} |
| 22 |
|
| 23 |
public function testOneArgumentLr() { |
| 24 |
$this->expectException( ArgumentCountError::class ); |
| 25 |
new Lr( '(' ); |
| 26 |
throw new ArgumentCountError( 'Should not create a lr with one argument' ); |
| 27 |
} |
| 28 |
|
| 29 |
public function testIncorrectTypeLr() { |
| 30 |
$this->expectException( TypeError::class ); |
| 31 |
new Lr( '(', ')', new Literal( 'a' ) ); |
| 32 |
throw new TypeError( 'Should not create a lr with incorrect type' ); |
| 33 |
} |
| 34 |
|
| 35 |
public function testBasicLr() { |
| 36 |
$f = new Lr( '(', ')', new TexArray( new Literal( 'a' ) ) ); |
| 37 |
$this->assertEquals( '\\left(a\\right)', $f->render(), 'Should create a basic function' ); |
| 38 |
} |
| 39 |
|
| 40 |
public function testGetters() { |
| 41 |
$f = new Lr( '(', ')', new TexArray( new Literal( 'a' ) ) ); |
| 42 |
$this->assertNotEmpty( $f->getLeft() ); |
| 43 |
$this->assertNotEmpty( $f->getRight() ); |
| 44 |
$this->assertNotEmpty( $f->getArg() ); |
| 45 |
} |
| 46 |
|
| 47 |
public function testCurliesLr() { |
| 48 |
$f = new Lr( '(', ')', new TexArray( new Literal( 'a' ), new Literal( 'b' ) ) ); |
| 49 |
$this->assertEquals( '{\\left(ab\\right)}', $f->inCurlies(), |
| 50 |
'Should create exactly one set of curlies' ); |
| 51 |
} |
| 52 |
|
| 53 |
public function testExtractIdentifiersLr() { |
| 54 |
$n = new Lr( '(', ')', new TexArray( new Literal( 'a' ), new Literal( 'b' ) ) ); |
| 55 |
$this->assertEquals( [ 'a', 'b' ], $n->extractIdentifiers(), |
| 56 |
'Should extract identifiers' ); |
| 57 |
} |
| 58 |
|
| 59 |
public function testRenderA() { |
| 60 |
$n = new Lr( '(', ')', new TexArray( new Literal( 'A' ) ) ); |
| 61 |
$mml = $n->renderMML(); |
| 62 |
$this->assertStringContainsString( 'A</mi>', $mml ); |
| 63 |
$this->assertStringContainsString( ')</mo>', $mml ); |
| 64 |
} |
| 65 |
|
| 66 |
public function testRenderADeriv() { |
| 67 |
$n = new Lr( '(', ')', new TexArray( new Literal( 'A' ) ) ); |
| 68 |
$state = [ 'deriv' => 1 ]; |
| 69 |
$mml = $n->renderMML( [], $state ); |
| 70 |
$this->assertStringNotContainsString( '′</mo>', $mml ); |
| 71 |
} |
| 72 |
|
| 73 |
} |