2022-08-17 13:26:25 +00:00
|
|
|
<?php
|
|
|
|
|
2023-11-24 09:30:05 +00:00
|
|
|
namespace MediaWiki\Extension\Math\Tests\WikiTexVC\Nodes;
|
2022-08-17 13:26:25 +00:00
|
|
|
|
|
|
|
use ArgumentCountError;
|
2023-11-24 09:30:05 +00:00
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmrow;
|
2024-10-13 19:13:56 +00:00
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmsub;
|
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmunder;
|
2023-11-24 09:30:05 +00:00
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\DQ;
|
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\Literal;
|
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\TexArray;
|
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\TexNode;
|
2022-08-17 13:26:25 +00:00
|
|
|
use MediaWikiUnitTestCase;
|
|
|
|
use RuntimeException;
|
|
|
|
use TypeError;
|
|
|
|
|
|
|
|
/**
|
2023-11-24 09:30:05 +00:00
|
|
|
* @covers \MediaWiki\Extension\Math\WikiTexVC\Nodes\DQ
|
2022-08-17 13:26:25 +00:00
|
|
|
*/
|
|
|
|
class DQTest extends MediaWikiUnitTestCase {
|
|
|
|
|
|
|
|
public function testEmptyDQ() {
|
|
|
|
$this->expectException( ArgumentCountError::class );
|
|
|
|
new DQ();
|
|
|
|
throw new ArgumentCountError( 'Should not create an empty dq' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOneArgumentDQ() {
|
|
|
|
$this->expectException( ArgumentCountError::class );
|
|
|
|
new DQ( new Literal( 'a' ) );
|
|
|
|
throw new ArgumentCountError( 'Should not create a dq with one argument' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIncorrectTypeDQ() {
|
|
|
|
$this->expectException( TypeError::class );
|
|
|
|
new DQ( 'a', 'b' );
|
|
|
|
throw new RuntimeException( 'Should not create a dq with incorrect type' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testBasicDQ() {
|
|
|
|
$dq = new DQ( new Literal( 'a' ), new Literal( 'b' ) );
|
|
|
|
$this->assertEquals( 'a_{b}', $dq->render(), 'Should create a basic dq' );
|
|
|
|
}
|
|
|
|
|
2022-10-10 13:34:23 +00:00
|
|
|
public function testGetters() {
|
|
|
|
$dq = new DQ( new Literal( 'a' ), new Literal( 'b' ) );
|
|
|
|
$this->assertNotEmpty( $dq->getBase() );
|
|
|
|
$this->assertNotEmpty( $dq->getDown() );
|
|
|
|
}
|
|
|
|
|
2022-08-17 13:26:25 +00:00
|
|
|
public function testEmptyBaseDQ() {
|
|
|
|
$dq = new DQ( new TexNode(), new Literal( 'b' ) );
|
|
|
|
$this->assertEquals( '_{b}', $dq->render(), 'Should create an empty base dq' );
|
|
|
|
}
|
2023-03-21 15:06:32 +00:00
|
|
|
|
|
|
|
public function testRenderEmptyDq() {
|
2024-02-17 23:02:37 +00:00
|
|
|
$dq = new DQ( TexArray::newCurly(), new Literal( 'b' ) );
|
2023-03-21 15:06:32 +00:00
|
|
|
$this->assertStringContainsString( ( new MMLmrow() )->getEmpty(), $dq->renderMML() );
|
|
|
|
}
|
|
|
|
|
2024-10-13 19:13:56 +00:00
|
|
|
public function testBigSum() {
|
|
|
|
$dq = new DQ( new Literal( '\\sum' ), new Literal( 'i' ) );
|
|
|
|
$this->assertStringContainsString( ( new MMLmunder() )->getStart(), $dq->renderMML() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSmallSum() {
|
|
|
|
$dq = new DQ( new Literal( '\\sum' ), new Literal( 'i' ) );
|
|
|
|
$this->assertStringContainsString(
|
|
|
|
( new MMLmsub() )->getStart(),
|
|
|
|
$dq->renderMML( [], [ 'styleargs' => [ 'displaystle' => 'false' ] ] ) );
|
|
|
|
}
|
|
|
|
|
2022-08-17 13:26:25 +00:00
|
|
|
}
|