2022-08-29 10:15:58 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\Math\Tests\TexVC\Nodes;
|
|
|
|
|
|
|
|
use ArgumentCountError;
|
|
|
|
use MediaWiki\Extension\Math\TexVC\Nodes\Box;
|
|
|
|
use MediaWiki\Extension\Math\TexVC\Nodes\Literal;
|
|
|
|
use MediaWikiUnitTestCase;
|
|
|
|
use RuntimeException;
|
|
|
|
use TypeError;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \MediaWiki\Extension\Math\TexVC\Nodes\Box
|
|
|
|
*/
|
|
|
|
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
|
|
|
}
|