2022-08-29 10:15:58 +00:00
|
|
|
<?php
|
|
|
|
|
2023-11-24 09:30:05 +00:00
|
|
|
namespace MediaWiki\Extension\Math\Tests\WikiTexVC\Nodes;
|
2022-08-29 10:15:58 +00:00
|
|
|
|
|
|
|
use ArgumentCountError;
|
2023-11-24 09:30:05 +00:00
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\Box;
|
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\Literal;
|
2022-08-29 10:15:58 +00:00
|
|
|
use MediaWikiUnitTestCase;
|
|
|
|
use RuntimeException;
|
|
|
|
use TypeError;
|
|
|
|
|
|
|
|
/**
|
2023-11-24 09:30:05 +00:00
|
|
|
* @covers \MediaWiki\Extension\Math\WikiTexVC\Nodes\Box
|
2022-08-29 10:15:58 +00:00
|
|
|
*/
|
|
|
|
class BoxTest extends MediaWikiUnitTestCase {
|
|
|
|
|
|
|
|
public function testEmptyBox() {
|
|
|
|
$this->expectException( ArgumentCountError::class );
|
|
|
|
new Box();
|
|
|
|
throw new ArgumentCountError( 'Should not create an empty box' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOneArgumentBox() {
|
|
|
|
$this->expectException( ArgumentCountError::class );
|
|
|
|
new Box( '\\hbox' );
|
|
|
|
throw new ArgumentCountError( 'Should not create a box with one argument' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIncorrectTypeBox() {
|
|
|
|
$this->expectException( TypeError::class );
|
|
|
|
new Box( '\\hbox', new Literal( 'a' ) );
|
|
|
|
throw new RuntimeException( 'Should not create a box with incorrect type' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testBasicFunctionBox() {
|
|
|
|
$box = new Box( '\\hbox', 'a' );
|
|
|
|
$this->assertEquals( '{\\hbox{a}}', $box->render(), 'Should create a basic function' );
|
|
|
|
}
|
|
|
|
|
2022-10-10 13:34:23 +00:00
|
|
|
public function testGetters() {
|
|
|
|
$box = new Box( '\\hbox', 'a' );
|
|
|
|
$this->assertNotEmpty( $box->getArg() );
|
|
|
|
$this->assertNotEmpty( $box->getFname() );
|
|
|
|
}
|
|
|
|
|
2022-08-29 10:15:58 +00:00
|
|
|
public function testExtractIdentifiersBox() {
|
|
|
|
$box = new Box( '\\hbox', 'a' );
|
|
|
|
$this->assertEquals( [], $box->extractIdentifiers(), 'Should extract identifiers' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCurliesBox() {
|
|
|
|
$box = new Box( '\\hbox', 'a' );
|
|
|
|
$this->assertEquals( '{\\hbox{a}}', $box->inCurlies(), 'Should create exactly one set of curlies' );
|
|
|
|
}
|
2022-12-28 15:05:59 +00:00
|
|
|
|
|
|
|
public function testRenderMML() {
|
|
|
|
$box = new Box( '\\hbox', 'a' );
|
|
|
|
$this->assertStringContainsString( '</mtext>', $box->renderMML(), 'Render MathML as text.' );
|
|
|
|
}
|
2023-03-16 14:47:26 +00:00
|
|
|
|
|
|
|
public function testTrailingSpaceBoxMML() {
|
|
|
|
$box = new Box( '\\hbox', 'a ' );
|
|
|
|
$this->assertStringContainsString( ' ', $box->renderMML(), 'Should have trailing rendered space' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPrecedingSpaceBoxMML() {
|
|
|
|
$box = new Box( '\\hbox', ' a' );
|
|
|
|
$this->assertStringContainsString( ' ', $box->renderMML(), 'Should have preceding rendered space' );
|
|
|
|
}
|
2022-08-29 10:15:58 +00:00
|
|
|
}
|