2024-01-27 17:12:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\Math\Tests\WikiTexVC\MMLmappings;
|
|
|
|
|
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\MMLmappings\BaseParsing;
|
2024-01-27 19:02:08 +00:00
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\DQ;
|
2024-01-27 17:12:03 +00:00
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\Fun1;
|
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\Literal;
|
2024-05-26 20:37:07 +00:00
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\Matrix;
|
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\TexArray;
|
2024-06-02 18:00:20 +00:00
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\TexVC;
|
2024-01-27 17:12:03 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \MediaWiki\Extension\Math\WikiTexVC\MMLmappings\BaseParsing
|
|
|
|
*/
|
|
|
|
class BaseParsingTest extends TestCase {
|
|
|
|
|
|
|
|
public function testAccent() {
|
|
|
|
$node = new Fun1(
|
|
|
|
'\\widetilde',
|
|
|
|
( new Literal( 'a' ) )
|
|
|
|
);
|
|
|
|
$result = BaseParsing::accent( $node, [], null, 'widetilde', '007E' );
|
|
|
|
$this->assertStringContainsString( '~', $result );
|
|
|
|
$this->assertStringContainsString( 'mover', $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAccentArgPassing() {
|
|
|
|
$node = new Fun1(
|
|
|
|
'\\widetilde',
|
|
|
|
( new Literal( 'a' ) )
|
|
|
|
);
|
|
|
|
$result = BaseParsing::accent( $node, [ 'k' => 'v' ], null, 'widetilde', '007E' );
|
|
|
|
$this->assertStringContainsString( '<mi k="v"', $result );
|
|
|
|
}
|
2024-01-27 19:02:08 +00:00
|
|
|
|
2024-05-26 20:37:07 +00:00
|
|
|
public function testArray() {
|
|
|
|
$node = new Matrix( 'matrix',
|
|
|
|
new TexArray( new TexArray( new Literal( 'a' ) ) ) );
|
|
|
|
|
|
|
|
$result = BaseParsing::array( $node, [], null, 'array', '007E' );
|
|
|
|
$this->assertStringContainsString( '<mi>a</mi>', $result );
|
|
|
|
}
|
|
|
|
|
2024-09-20 06:59:27 +00:00
|
|
|
public function testBoldGreek() {
|
|
|
|
$node = new Fun1(
|
|
|
|
'\\boldsymbol',
|
|
|
|
( new Literal( '\\alpha' ) )
|
|
|
|
);
|
|
|
|
$result = BaseParsing::boldsymbol( $node, [], null, 'boldsymbol' );
|
|
|
|
$this->assertStringContainsString( 'mathvariant="bold-italic"', $result );
|
|
|
|
}
|
|
|
|
|
2024-05-26 20:37:07 +00:00
|
|
|
public function testBoldSymbol() {
|
|
|
|
$node = new Fun1(
|
|
|
|
'\\boldsymbol',
|
|
|
|
( new Literal( 'a' ) )
|
|
|
|
);
|
|
|
|
$result = BaseParsing::boldsymbol( $node, [], null, 'boldsymbol' );
|
|
|
|
$this->assertStringContainsString( 'mathvariant="bold-italic"', $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCancel() {
|
|
|
|
$node = new Fun1(
|
|
|
|
'\\cancel',
|
|
|
|
( new Literal( 'a' ) )
|
|
|
|
);
|
|
|
|
$result = BaseParsing::cancel( $node, [], null, 'cancel', 'something' );
|
|
|
|
$this->assertStringContainsString( '<menclose notation="something"><mi>a</mi></menclose>',
|
|
|
|
$result );
|
|
|
|
}
|
|
|
|
|
2024-01-27 19:02:08 +00:00
|
|
|
public function testUnderOver() {
|
|
|
|
$node = new Fun1(
|
|
|
|
'\\overline',
|
|
|
|
( new Literal( 'a' ) )
|
|
|
|
);
|
|
|
|
$result = BaseParsing::underover( $node, [], null, 'oXXX', '00AF' );
|
|
|
|
$this->assertStringStartsWith( '<mrow', $result );
|
|
|
|
$this->assertStringContainsString( 'mover', $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUnderOverUnder() {
|
|
|
|
$node = new Fun1(
|
|
|
|
'\\overline',
|
|
|
|
( new Literal( 'a' ) )
|
|
|
|
);
|
|
|
|
$result = BaseParsing::underover( $node, [], null, 'uXXX', '00AF' );
|
|
|
|
$this->assertStringContainsString( 'munder', $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUnderOverDqUnder() {
|
|
|
|
$node = new DQ(
|
|
|
|
( new Literal( 'a' ) ),
|
|
|
|
( new Literal( 'b' ) )
|
|
|
|
);
|
|
|
|
$result = BaseParsing::underover( $node, [], null, 'uXXX', '00AF' );
|
|
|
|
$this->assertStringContainsString( 'munder', $result );
|
|
|
|
$this->assertStringContainsString( 'mrow', $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUnderArgPassing() {
|
|
|
|
$node = new Fun1(
|
|
|
|
'\\overline',
|
|
|
|
( new Literal( 'a' ) )
|
|
|
|
);
|
|
|
|
$result = BaseParsing::underover( $node, [ 'k' => 'v' ], null, 'oXXX', '00AF' );
|
|
|
|
$this->assertStringContainsString( '<mi k="v"', $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUnderBadArgPassing() {
|
|
|
|
$node = new Fun1(
|
|
|
|
'\\overline',
|
|
|
|
( new Literal( 'a' ) )
|
|
|
|
);
|
|
|
|
$result = BaseParsing::underover( $node,
|
|
|
|
[ 'k' => '"<script>alert("problem")</script>"' ], null, 'oXXX', '00AF' );
|
|
|
|
$this->assertStringContainsString( 'k=""<script>alert("problem")', $result );
|
|
|
|
}
|
2024-04-12 15:43:24 +00:00
|
|
|
|
|
|
|
public function testAlignAt() {
|
|
|
|
$matrix = new Matrix( 'alignat',
|
|
|
|
new TexArray( new TexArray( new Literal( '\\sin' ) ) ) );
|
|
|
|
$result = BaseParsing::alignAt( $matrix, [], null, 'alignat', '002A' );
|
|
|
|
$this->assertStringContainsString( 'mtable', $result );
|
|
|
|
}
|
2024-06-02 18:00:20 +00:00
|
|
|
|
|
|
|
public function testHLineTop() {
|
|
|
|
$matrix = new Matrix( 'matrix',
|
|
|
|
new TexArray( new TexArray( new TexArray( new Literal( '\\hline ' ), new Literal( 'a'
|
|
|
|
) ) ) ) );
|
|
|
|
$result = BaseParsing::matrix( $matrix, [], null, 'matrix', '002A' );
|
|
|
|
$this->assertStringContainsString( 'top', $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testHLineBottom() {
|
|
|
|
$matrix = new Matrix( 'matrix',
|
|
|
|
new TexArray( new TexArray( new Literal( 'a' ) ),
|
|
|
|
new TexArray( new TexArray( new Literal( '\\hline ' ) ) ) ) );
|
|
|
|
$result = BaseParsing::matrix( $matrix, [], null, 'matrix', '002A' );
|
|
|
|
$this->assertStringContainsString( 'bottom', $result );
|
|
|
|
$this->assertStringContainsString( '<mi>a</mi>', $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testHLineLastLine() {
|
|
|
|
$matrix = new Matrix( 'matrix',
|
|
|
|
new TexArray( new TexArray( new Literal( 'a' ) ),
|
|
|
|
new TexArray( new TexArray( new Literal( '\\hline ' ), new Literal( 'a'
|
|
|
|
) ) ) ) );
|
|
|
|
$result = BaseParsing::matrix( $matrix, [], null, 'matrix', '002A' );
|
|
|
|
$this->assertStringContainsString( 'solid', $result );
|
|
|
|
$this->assertStringContainsString( '<mi>a</mi>', $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testComplicatedHline() {
|
|
|
|
$matrix = ( new TexVC() )->parse( '\\begin{array}{c}
|
|
|
|
\\hline a\\\\
|
|
|
|
\\hline 1\\\\
|
|
|
|
2\\\\
|
|
|
|
\\hline
|
|
|
|
\\end{array}' )[0];
|
|
|
|
$result = BaseParsing::matrix( $matrix, [], null, 'matrix', '002A' );
|
|
|
|
$this->assertStringContainsString( 'solid none', $result );
|
|
|
|
$this->assertStringContainsString( 'top bottom', $result );
|
|
|
|
}
|
|
|
|
|
2024-10-13 20:30:16 +00:00
|
|
|
public function testHandleOperatorName() {
|
|
|
|
$node = new Fun1(
|
|
|
|
'\\operatorname',
|
|
|
|
( new Literal( 'sn' ) )
|
|
|
|
);
|
|
|
|
$result = BaseParsing::handleOperatorName( $node, [], [
|
|
|
|
"foundNamedFct" => [ true, true ]
|
|
|
|
], 'operatorname' );
|
|
|
|
$this->assertStringContainsString( 'sn</mi>', $result );
|
|
|
|
$this->assertStringContainsString( '<mo>⁡</mo>', $result );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testHandleOperatorLast() {
|
|
|
|
$node = new Fun1(
|
|
|
|
'\\operatorname',
|
|
|
|
( new Literal( 'sn' ) )
|
|
|
|
);
|
|
|
|
$result = BaseParsing::handleOperatorName( $node, [], [
|
|
|
|
"foundNamedFct" => [ true, false ]
|
|
|
|
], 'operatorname' );
|
|
|
|
$this->assertStringContainsString( 'sn</mi>', $result );
|
|
|
|
$this->assertStringNotContainsString( '<mo>⁡</mo>', $result );
|
|
|
|
}
|
|
|
|
|
2024-10-12 22:54:33 +00:00
|
|
|
public function testColumnSpecs() {
|
|
|
|
$matrix = ( new TexVC() )->parse( '\\begin{array}{lcr}
|
|
|
|
z & = & a \\\\
|
|
|
|
f(x,y,z) & = & x + y + z
|
|
|
|
\\end{array}' )[0];
|
|
|
|
$result = BaseParsing::matrix( $matrix, [], null, 'matrix', '002A' );
|
|
|
|
$this->assertStringContainsString( 'left center right ', $result );
|
|
|
|
}
|
2024-01-27 17:12:03 +00:00
|
|
|
}
|