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\Declh;
|
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\Literal;
|
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\TexArray;
|
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\Declh
|
2022-08-29 10:15:58 +00:00
|
|
|
*/
|
|
|
|
class DeclhTest extends MediaWikiUnitTestCase {
|
|
|
|
|
|
|
|
public function testEmptyDeclh() {
|
|
|
|
$this->expectException( ArgumentCountError::class );
|
|
|
|
new Declh();
|
|
|
|
throw new ArgumentCountError( 'Should not create an empty Declh' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOneArgumentDeclh() {
|
|
|
|
$this->expectException( ArgumentCountError::class );
|
|
|
|
new Declh( '\\f' );
|
|
|
|
throw new ArgumentCountError( 'Should not create a Declh with one argument' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIncorrectTypeDeclh() {
|
|
|
|
$this->expectException( TypeError::class );
|
|
|
|
new Declh( '\\f', 'x' );
|
|
|
|
throw new RuntimeException( 'Should not create a Declh with incorrect type' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testBasicFunctionDeclh() {
|
|
|
|
$f = new Declh( '\\rm', new TexArray( new Literal( 'a' ) ) );
|
|
|
|
$this->assertEquals( '{\\rm {a}}', $f->render(), 'Should create a basic function' );
|
|
|
|
}
|
|
|
|
|
2022-10-10 13:34:23 +00:00
|
|
|
public function testGetters() {
|
|
|
|
$f = new Declh( '\\rm', new TexArray( new Literal( 'a' ) ) );
|
|
|
|
$this->assertNotEmpty( $f->getFname() );
|
|
|
|
$this->assertNotEmpty( $f->getArg() );
|
|
|
|
}
|
|
|
|
|
2022-08-29 10:15:58 +00:00
|
|
|
public function testTwoArgsFunctionDeclh() {
|
|
|
|
$f = new Declh( '\\rm',
|
|
|
|
new TexArray( new Literal( 'a' ), new Literal( 'b' ) ) );
|
|
|
|
$this->assertEquals( '{\\rm {ab}}',
|
|
|
|
$f->render(), 'Should create a function with two arguments' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCurliesDeclh() {
|
|
|
|
$f = new Declh( '\\f', new TexArray( new Literal( 'a' ) ) );
|
|
|
|
$this->assertEquals( '{\\f {a}}', $f->inCurlies(), 'Should create exactly one set of curlies' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExtractIdentifiersDeclh() {
|
|
|
|
$f = new Declh( '\\rm', new TexArray( new Literal( 'a' ) ) );
|
|
|
|
$this->assertEquals( [ 'a' ], $f->extractIdentifiers(), 'Should extract identifiers' );
|
|
|
|
}
|
|
|
|
|
2022-12-27 23:08:59 +00:00
|
|
|
public function testExtractNoIdentifiersDeclh() {
|
|
|
|
$f = new Declh( '\\rm', new TexArray() );
|
|
|
|
$this->assertEquals( [], $f->extractIdentifiers(), 'Should extract identifiers' );
|
|
|
|
}
|
|
|
|
|
2022-08-29 10:15:58 +00:00
|
|
|
public function testExtractIdentifiersMultiDeclh() {
|
|
|
|
$f = new Declh( '\\rm', new TexArray( new Literal( 'a' ), new Literal( 'b' ) ) );
|
|
|
|
$this->assertEquals( [ 'ab' ], $f->extractIdentifiers(), 'Should extract multiple identifiers' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNotExtractSomeSubscripts() {
|
|
|
|
$f = new Declh( '\\bf', new TexArray( new Literal( '' ) ) );
|
|
|
|
$this->assertEquals( [], $f->extractSubscripts(),
|
|
|
|
'Should not extract empty font modifier subscripts identifiers' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSubscriptsForFontMod() {
|
2023-08-19 02:51:13 +00:00
|
|
|
$mods = [ 'rm', 'it', 'cal', 'bf' ];
|
2022-08-29 10:15:58 +00:00
|
|
|
foreach ( $mods as $mod ) {
|
2022-11-05 00:08:02 +00:00
|
|
|
$f = new Declh( "\\{$mod}", new TexArray( new Literal( 'a' ) ) );
|
|
|
|
$this->assertEquals( [ "\\math{$mod}{a}" ], $f->extractSubscripts(),
|
|
|
|
"Should extract subscripts for {$mod} font modification" );
|
2022-08-29 10:15:58 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-28 15:05:59 +00:00
|
|
|
|
|
|
|
public function testRenderMML() {
|
|
|
|
$f = new Declh( '\\bf', new TexArray( new Literal( 'a' ) ) );
|
|
|
|
$this->assertStringContainsString( 'mathvariant="bold"', $f->renderMML(), 'MathML should render bold' );
|
|
|
|
}
|
2022-08-29 10:15:58 +00:00
|
|
|
}
|