2022-09-05 12:33:12 +00:00
|
|
|
<?php
|
|
|
|
|
2023-11-24 09:30:05 +00:00
|
|
|
namespace MediaWiki\Extension\Math\Tests\WikiTexVC\Nodes;
|
2022-09-05 12:33:12 +00:00
|
|
|
|
|
|
|
use ArgumentCountError;
|
2023-11-24 09:30:05 +00:00
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\Literal;
|
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\Lr;
|
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\TexArray;
|
2022-09-05 12:33:12 +00:00
|
|
|
use MediaWikiUnitTestCase;
|
|
|
|
use TypeError;
|
|
|
|
|
|
|
|
/**
|
2023-11-24 09:30:05 +00:00
|
|
|
* @covers \MediaWiki\Extension\Math\WikiTexVC\Nodes\Lr
|
2022-09-05 12:33:12 +00:00
|
|
|
*/
|
|
|
|
class LrTest extends MediaWikiUnitTestCase {
|
|
|
|
|
|
|
|
public function testEmptyLr() {
|
|
|
|
$this->expectException( ArgumentCountError::class );
|
|
|
|
new Lr();
|
|
|
|
throw new ArgumentCountError( 'Should not create an empty lr' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOneArgumentLr() {
|
|
|
|
$this->expectException( ArgumentCountError::class );
|
|
|
|
new Lr( '(' );
|
|
|
|
throw new ArgumentCountError( 'Should not create a lr with one argument' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIncorrectTypeLr() {
|
|
|
|
$this->expectException( TypeError::class );
|
|
|
|
new Lr( '(', ')', new Literal( 'a' ) );
|
|
|
|
throw new TypeError( 'Should not create a lr with incorrect type' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testBasicLr() {
|
|
|
|
$f = new Lr( '(', ')', new TexArray( new Literal( 'a' ) ) );
|
|
|
|
$this->assertEquals( '\\left(a\\right)', $f->render(), 'Should create a basic function' );
|
|
|
|
}
|
|
|
|
|
2022-10-10 13:34:23 +00:00
|
|
|
public function testGetters() {
|
|
|
|
$f = new Lr( '(', ')', new TexArray( new Literal( 'a' ) ) );
|
|
|
|
$this->assertNotEmpty( $f->getLeft() );
|
|
|
|
$this->assertNotEmpty( $f->getRight() );
|
|
|
|
$this->assertNotEmpty( $f->getArg() );
|
|
|
|
}
|
|
|
|
|
2022-09-05 12:33:12 +00:00
|
|
|
public function testCurliesLr() {
|
|
|
|
$f = new Lr( '(', ')', new TexArray( new Literal( 'a' ), new Literal( 'b' ) ) );
|
|
|
|
$this->assertEquals( '{\\left(ab\\right)}', $f->inCurlies(),
|
|
|
|
'Should create exactly one set of curlies' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExtractIdentifiersLr() {
|
|
|
|
$n = new Lr( '(', ')', new TexArray( new Literal( 'a' ), new Literal( 'b' ) ) );
|
|
|
|
$this->assertEquals( [ 'a', 'b' ], $n->extractIdentifiers(),
|
|
|
|
'Should extract identifiers' );
|
|
|
|
}
|
|
|
|
|
2024-11-29 00:13:15 +00:00
|
|
|
public function testRenderA() {
|
|
|
|
$n = new Lr( '(', ')', new TexArray( new Literal( 'A' ) ) );
|
|
|
|
$mml = $n->renderMML();
|
|
|
|
$this->assertStringContainsString( 'A</mi>', $mml );
|
|
|
|
$this->assertStringContainsString( ')</mo>', $mml );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRenderADeriv() {
|
|
|
|
$n = new Lr( '(', ')', new TexArray( new Literal( 'A' ) ) );
|
|
|
|
$mml = $n->renderMML( [], [ 'deriv' => 1 ] );
|
|
|
|
$this->assertStringNotContainsString( '′</mo>', $mml );
|
|
|
|
}
|
|
|
|
|
2022-09-05 12:33:12 +00:00
|
|
|
}
|