mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-12-13 08:28:32 +00:00
ad2a6b7fef
* escaped semicolon/commas get rendered as spaces, non escaped get rendered as text * MMLFullCoverageTest cases: 4,5,66 Bug: T327391 Change-Id: Icfa557fc43a8ac87fbf856795cb9c26d0fb2c456
101 lines
3.7 KiB
PHP
101 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\Math\Tests\TexVC;
|
|
|
|
use MediaWiki\Extension\Math\TexVC\MMLmappings\Util\MMLTestUtil;
|
|
use MediaWiki\Extension\Math\TexVC\TexVC;
|
|
use MediaWikiUnitTestCase;
|
|
|
|
/**
|
|
* These are some specific testcases by MML-Rendering by TexVC.
|
|
* They are explicitly described here instead of in JSON files because
|
|
* Mathoid or LaTeXML do not generate suitable results for reference.
|
|
* @covers \MediaWiki\Extension\Math\TexVC\TexVC
|
|
*/
|
|
class MMLRenderTest extends MediaWikiUnitTestCase {
|
|
public function testSidesetError() {
|
|
$input = "\\sideset{_1^2}{_3^4}";
|
|
$mathMLtexVC = $this->generateMML( $input );
|
|
$this->assertTrue( str_contains( $mathMLtexVC, "merror" ) );
|
|
}
|
|
|
|
public function testSidesetSum() {
|
|
$input = "\\sideset{_1^2}{_3^4}\\sum";
|
|
$mathMLtexVC = $this->generateMML( $input );
|
|
$this->assertStringNotContainsString( "merror", $mathMLtexVC );
|
|
$this->assertStringContainsString( "mmultiscripts", $mathMLtexVC );
|
|
$this->assertStringContainsString( "<mprescripts/>", $mathMLtexVC );
|
|
$this->assertStringContainsString( ">∑", $mathMLtexVC );
|
|
}
|
|
|
|
public function testSidesetProd() {
|
|
$input = "\\sideset{_1^2}{_3^4}\\prod";
|
|
$mathMLtexVC = $this->generateMML( $input );
|
|
$this->assertStringNotContainsString( "merror", $mathMLtexVC );
|
|
$this->assertStringContainsString( "mmultiscripts", $mathMLtexVC );
|
|
$this->assertStringContainsString( "<mprescripts/>", $mathMLtexVC );
|
|
$this->assertStringContainsString( ">∏", $mathMLtexVC );
|
|
}
|
|
|
|
public function testSidesetFQ() {
|
|
$input = "\\sideset{_1^2}{_3^4}\prod_a^b";
|
|
$mathMLtexVC = $this->generateMML( $input );
|
|
$this->assertStringNotContainsString( "merror", $mathMLtexVC );
|
|
$this->assertStringContainsString( "mmultiscripts", $mathMLtexVC );
|
|
$this->assertStringContainsString( "<mprescripts/>", $mathMLtexVC );
|
|
$this->assertStringContainsString( ">∏", $mathMLtexVC );
|
|
$this->assertStringContainsString( "<mi>a</mi>", $mathMLtexVC );
|
|
$this->assertStringContainsString( "<mi>b</mi>", $mathMLtexVC );
|
|
$this->assertStringContainsString( "movablelimits", $mathMLtexVC );
|
|
}
|
|
|
|
public function testLimitsProd() {
|
|
$input = "\\prod\\limits_{j=1}^k A_{\\alpha_j}";
|
|
$mathMLtexVC = $this->generateMML( $input );
|
|
$this->assertStringContainsString( "munderover", $mathMLtexVC );
|
|
$this->assertStringContainsString( "∏", $mathMLtexVC, );
|
|
$this->assertStringContainsString( "msub", $mathMLtexVC, );
|
|
}
|
|
|
|
public function testLimitsSum() {
|
|
$input = "\\sum\\limits_{j=1}^k A_{\\alpha_j}";
|
|
$mathMLtexVC = $this->generateMML( $input );
|
|
$this->assertStringContainsString( "munderover", $mathMLtexVC );
|
|
$this->assertStringContainsString( "∑", $mathMLtexVC, );
|
|
$this->assertStringContainsString( "msub", $mathMLtexVC, );
|
|
}
|
|
|
|
public function testLimitsLim() {
|
|
$input = "\\lim_{x \\to 2}";
|
|
$mathMLtexVC = $this->generateMML( $input );
|
|
$this->assertStringContainsString( "lim", $mathMLtexVC );
|
|
$this->assertStringContainsString( "munder", $mathMLtexVC, );
|
|
}
|
|
|
|
public function testRenderSpaceSemicolon() {
|
|
$input = "{\\;}";
|
|
$mathMLtexVC = $this->generateMML( $input );
|
|
$this->assertStringContainsString( "mstyle", $mathMLtexVC );
|
|
$this->assertStringContainsString( "mspace", $mathMLtexVC, );
|
|
}
|
|
|
|
public function testSpacesAndCommas() {
|
|
$input = "{a}{b , c}\\,";
|
|
$mathMLtexVC = $this->generateMML( $input );
|
|
$this->assertStringContainsString( "<mo>,", $mathMLtexVC );
|
|
$this->assertStringContainsString( "mspace", $mathMLtexVC, );
|
|
}
|
|
|
|
private function generateMML( $input, $chem = false ) {
|
|
$texVC = new TexVC();
|
|
$resultT = $texVC->check( $input, [
|
|
'debug' => false,
|
|
'usemathrm' => false,
|
|
'oldtexvc' => false,
|
|
'usemhchem' => $chem
|
|
] );
|
|
|
|
return MMLTestUtil::getMMLwrapped( $resultT["input"] ) ?? "<math> error texvc </math>";
|
|
}
|
|
}
|