2023-03-02 10:40:10 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\Math\Tests\TexVC;
|
|
|
|
|
2023-03-21 15:06:32 +00:00
|
|
|
use MediaWiki\Extension\Math\TexVC\MMLmappings\TexConstants\Tag;
|
2023-03-02 10:40:10 +00:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2023-03-02 14:28:26 +00:00
|
|
|
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, );
|
|
|
|
}
|
|
|
|
|
2023-03-16 12:24:05 +00:00
|
|
|
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, );
|
|
|
|
}
|
|
|
|
|
2023-03-21 15:06:32 +00:00
|
|
|
public function testPrecedingSubscriptsFQ() {
|
|
|
|
$input = "{}_1^2\\!\\Omega_3^4";
|
|
|
|
$mathMLtexVC = $this->generateMML( $input );
|
|
|
|
$this->assertStringContainsString( "<mrow " . Tag::CLASSTAG . "=\"ORD\"/>", $mathMLtexVC );
|
|
|
|
$this->assertStringContainsString( "msubsup", $mathMLtexVC, );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPrecedingSubscriptsDQ() {
|
|
|
|
$input = "{}_pF_q";
|
|
|
|
$mathMLtexVC = $this->generateMML( $input );
|
|
|
|
$this->assertStringContainsString( "<mrow " . Tag::CLASSTAG . "=\"ORD\"/>", $mathMLtexVC );
|
|
|
|
$this->assertStringContainsString( "msub", $mathMLtexVC, );
|
|
|
|
}
|
|
|
|
|
2023-03-21 14:03:16 +00:00
|
|
|
public function testPilcrowAndSectionSign() {
|
|
|
|
$input = "\\P P \\S S";
|
|
|
|
$mathMLtexVC = $this->generateMML( $input );
|
|
|
|
$this->assertStringContainsString( "<mi>P", $mathMLtexVC );
|
|
|
|
$this->assertStringContainsString( "<mi>S", $mathMLtexVC, );
|
|
|
|
$this->assertStringContainsString( "¶", $mathMLtexVC, );
|
|
|
|
$this->assertStringContainsString( "§", $mathMLtexVC, );
|
|
|
|
}
|
|
|
|
|
2023-03-15 14:33:34 +00:00
|
|
|
public function testDerivatives1() {
|
|
|
|
$input = "b_{f''}";
|
|
|
|
$mathMLtexVC = $this->generateMML( $input );
|
|
|
|
$this->assertStringContainsString( "<mo>″", $mathMLtexVC );
|
|
|
|
$this->assertStringContainsString( "msup", $mathMLtexVC, );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDerivatives2() {
|
|
|
|
$input = "f''''(x)";
|
|
|
|
$mathMLtexVC = $this->generateMML( $input );
|
|
|
|
$this->assertStringContainsString( "<mo>⁗", $mathMLtexVC );
|
|
|
|
$this->assertStringContainsString( "msup", $mathMLtexVC, );
|
|
|
|
}
|
|
|
|
|
2023-03-17 13:57:03 +00:00
|
|
|
public function testLimitsTextstyle() {
|
|
|
|
$input = "\\textstyle \\lim_{n \\to \\infty}x_n";
|
|
|
|
$mathMLtexVC = $this->generateMML( $input );
|
|
|
|
$this->assertStringContainsString( "lim", $mathMLtexVC );
|
|
|
|
$this->assertStringContainsString( "munder", $mathMLtexVC, );
|
|
|
|
$this->assertStringContainsString( "movablelimits=\"true\"", $mathMLtexVC );
|
|
|
|
}
|
|
|
|
|
2023-03-22 09:01:32 +00:00
|
|
|
public function testColorGeneration1() {
|
|
|
|
$input = "\\color{Dandelion}{Dandelion}";
|
|
|
|
$mathMLtexVC = $this->generateMML( $input );
|
|
|
|
$this->assertStringContainsString( "#FDBC42", $mathMLtexVC );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testColorGeneration2() {
|
|
|
|
$input = "\\color{ForestGreen}{ForestGreen}";
|
|
|
|
$mathMLtexVC = $this->generateMML( $input );
|
|
|
|
$this->assertStringContainsString( "#009B55", $mathMLtexVC );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testColorGeneration3() {
|
|
|
|
$input = "\\color{Rhodamine}{Rhodamine}";
|
|
|
|
$mathMLtexVC = $this->generateMML( $input );
|
|
|
|
$this->assertStringContainsString( "#EF559F", $mathMLtexVC );
|
|
|
|
}
|
|
|
|
|
2023-03-02 10:40:10 +00:00
|
|
|
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>";
|
|
|
|
}
|
|
|
|
}
|