2022-10-10 14:03:14 +00:00
|
|
|
<?php
|
|
|
|
|
2023-11-24 09:30:05 +00:00
|
|
|
namespace MediaWiki\Extension\Math\Tests\WikiTexVC;
|
2022-10-10 14:03:14 +00:00
|
|
|
|
2023-11-24 09:30:05 +00:00
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Parser;
|
2022-10-10 14:03:14 +00:00
|
|
|
use MediaWikiUnitTestCase;
|
|
|
|
|
|
|
|
/**
|
2023-11-24 09:30:05 +00:00
|
|
|
* @covers \MediaWiki\Extension\Math\WikiTexVC\Parser
|
2022-10-10 14:03:14 +00:00
|
|
|
*/
|
|
|
|
class ParserTest extends MediaWikiUnitTestCase {
|
2024-08-30 12:09:35 +00:00
|
|
|
|
2024-08-25 12:22:07 +00:00
|
|
|
/** @var Parser */
|
2022-10-10 14:03:14 +00:00
|
|
|
private $parser;
|
|
|
|
|
|
|
|
protected function setUp(): void {
|
|
|
|
parent::setUp();
|
|
|
|
$this->parser = new Parser();
|
2024-08-30 12:09:35 +00:00
|
|
|
}
|
2022-10-10 14:03:14 +00:00
|
|
|
|
2024-08-30 12:09:35 +00:00
|
|
|
public function provideTestCases() {
|
|
|
|
yield [ '' ];
|
|
|
|
yield [ 'a' ];
|
|
|
|
yield [ 'a^2' ];
|
|
|
|
yield [ 'a^2+b^{2}' ];
|
|
|
|
yield [ 'l_a^2+l_b^2=l_c^2' ];
|
2022-10-10 14:03:14 +00:00
|
|
|
}
|
|
|
|
|
2024-08-30 12:09:35 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider provideTestCases
|
|
|
|
*/
|
|
|
|
public function testSimpleParse( string $input ) {
|
|
|
|
$this->parser->parse( $input, [ 'debug' => true ] );
|
|
|
|
$this->addToAssertionCount( 1 );
|
2022-10-10 14:03:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testExample() {
|
|
|
|
$this->parser->parse( '\\sin(x)+{}{}\\cos(x)^2 newcommand', [ 'debug' => true ] );
|
2024-08-30 12:09:35 +00:00
|
|
|
$this->addToAssertionCount( 1 );
|
2022-10-10 14:03:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSpecific() {
|
|
|
|
$resultR = $this->parser->parse( '\\reals' );
|
|
|
|
$resultS = $this->parser->parse( '\\mathbb{R}' );
|
|
|
|
$this->assertEquals( $resultR, $resultS, 'Should parse texVC specific functions' );
|
|
|
|
}
|
|
|
|
}
|