mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-12-20 19:32:39 +00:00
e0acf58460
Currently, information regarding individual LaTeX macros is distributed in various files. This is the first to attempt to collect declarative information regarding tex macros in the texutil.json file. As a proof of concept we start with only the cancel macros. * Adjust texutil tests so that whitespaces are allowed in the payload Change-Id: Iba2dfd5293ad96d8d8e4e2f555c8df9d1ae4d6ca
103 lines
3.4 KiB
PHP
103 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\Math\Tests\WikiTexVC\MMLmappings;
|
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\MMLmappings\BaseMappings;
|
|
use MediaWiki\Extension\Math\WikiTexVC\MMLmappings\BaseParsing;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* @covers \MediaWiki\Extension\Math\WikiTexVC\MMLmappings\BaseMappings
|
|
*/
|
|
class BaseMappingsTest extends TestCase {
|
|
|
|
public function testGetAll() {
|
|
$all = BaseMappings::getAll();
|
|
$this->assertIsArray( $all );
|
|
$this->assertNotEmpty( $all );
|
|
}
|
|
|
|
public function provideTestCases(): array {
|
|
// the second argument is an array of known problems which should be removed in the future
|
|
return [
|
|
'macros' => [ 'macros', [ 'SetSize', 'Overunderset', 'Root', 'MoveRoot', 'LeftRight', 'MoveLeftRight',
|
|
'rule', 'Rule', 'Nonscript', 'BuildRel', 'FBox', 'FrameBox', 'Strut', 'Cr', 'HFill', 'BeginEnd',
|
|
'HandleLabel', 'HandleRef', 'HandleNoTag', 'MmlToken' ]
|
|
],
|
|
'cancel' => [ 'cancel' ],
|
|
'mhchem' => [ 'mhchem' ],
|
|
'custom' => [ 'custom', [ 'Insert' ] ],
|
|
'special' => [ 'special', [ 'open', 'close', 'superscript', 'subscript', 'space', 'prime', 'comment',
|
|
'entry', 'hash' ] ], // only tilde exists
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideTestCases
|
|
*/
|
|
public function testValidMethods( $setName, $knownProblems = [] ) {
|
|
foreach ( BaseMappings::getAll()[$setName] as $symbol => $payload ) {
|
|
$methodName = is_array( $payload ) ? $payload[0] : $payload;
|
|
if ( in_array( $methodName, $knownProblems ) ) {
|
|
continue;
|
|
}
|
|
$this->assertTrue( method_exists( BaseParsing::class, $methodName ),
|
|
'Method ' . $methodName . ' for symbol ' . $symbol . ' does not exist in BaseParsing' );
|
|
|
|
}
|
|
}
|
|
|
|
public function testGetCancelByKey() {
|
|
$this->assertEquals( 'updiagonalstrike', BaseMappings::getCancelByKey( '\\cancel' )[1] );
|
|
$this->assertEquals( 'cancelTo', BaseMappings::getCancelByKey( '\\cancelto' )[0] );
|
|
$this->assertNull( BaseMappings::getCancelByKey( '\\notCancel' ) );
|
|
}
|
|
|
|
public function testGetOperatorByKey() {
|
|
$this->assertEquals( '√', BaseMappings::getOperatorByKey( '\\surd' )[0] );
|
|
$this->assertEquals( '−', BaseMappings::getOperatorByKey( '-' ) );
|
|
}
|
|
|
|
public function testGetCustomByKey() {
|
|
$this->assertEquals( '\u222E', BaseMappings::getCustomByKey( '\\oint' )[1] );
|
|
}
|
|
|
|
public function testGetDelimiterByKey() {
|
|
$this->assertEquals( '(', BaseMappings::getDelimiterByKey( '(' )[0] );
|
|
}
|
|
|
|
public function testGetMacroByKey() {
|
|
$this->assertEquals( 'D', BaseMappings::getMacroByKey( '\\displaystyle' )[1] );
|
|
}
|
|
|
|
public function testGetSpecialByKey() {
|
|
$this->assertEquals( 'tilde', BaseMappings::getSpecialByKey( '~' )[1] );
|
|
$this->assertNull( BaseMappings::getSpecialByKey( '_' ) );
|
|
}
|
|
|
|
public function testGetColorByKey() {
|
|
$this->assertEquals( '#ED1B23', BaseMappings::getColorByKey( 'red' )[0] );
|
|
}
|
|
|
|
public function testGetInstance() {
|
|
$this->assertInstanceOf( BaseMappings::class, BaseMappings::getInstance() );
|
|
}
|
|
|
|
public function testGetNullaryMacro() {
|
|
$this->assertEquals( 'Å', BaseMappings::getNullaryMacro( 'AA' )[0] );
|
|
}
|
|
|
|
public function testGetCharacterByKey() {
|
|
$this->assertEquals( '\u0393', BaseMappings::getCharacterByKey( '\\Gamma' ) );
|
|
}
|
|
|
|
public function testGetMhChemByKey() {
|
|
$this->assertEquals( 'ce', BaseMappings::getMhChemByKey( '\\ce' )[1] );
|
|
}
|
|
|
|
public function testGetIdentifierByKey() {
|
|
$this->assertEquals( 'α', BaseMappings::getIdentifierByKey( '\\alpha' )[0] );
|
|
}
|
|
|
|
}
|