Activate chem and inline-tex type input in LocalChecker

Bug: T321262

Change-Id: Ib8e55290cc77cdc07274e7f1dbd27d20db0f3227
This commit is contained in:
Stegmujo 2022-10-20 21:36:00 +00:00
parent 551bc174c9
commit c74ced3716
No known key found for this signature in database
GPG key ID: FEFA628F883FAE29
2 changed files with 17 additions and 7 deletions

View file

@ -21,13 +21,13 @@ class LocalChecker extends BaseChecker {
*/
public function __construct( $tex = '', $type = 'tex' ) {
parent::__construct( $tex );
if ( $type !== 'tex' ) {
// this type check will be refactored with the introduction of chem-types:
// see: https://phabricator.wikimedia.org/T321262
if ( $type === 'tex' || $type === 'chem' || $type === 'inline-tex' ) {
$this->texVC = new TexVC();
$options = $type === 'chem' ? [ "usemhchem" => true ] : null;
$this->result = $this->texVC->check( $tex, $options );
} else {
throw new InvalidArgumentException( "Non supported type passed to LocalChecker: " . $type );
}
$this->texVC = new TexVC();
$this->result = $this->texVC->check( $tex );
}
/**

View file

@ -24,14 +24,24 @@ class LocalCheckerTest extends MediaWikiIntegrationTestCase {
$this->assertSame( '\\sin x^{2}', $checker->getValidTex() );
}
public function testValidType() {
public function testValidTypeTex() {
$checker = new LocalChecker( '\sin x^2', 'tex' );
$this->assertTrue( $checker->isValid() );
}
public function testValidTypeChem() {
$checker = new LocalChecker( '{\\displaystyle {\\ce {\\cdot OHNO_{2}}}}', 'chem' );
$this->assertTrue( $checker->isValid() );
}
public function testValidTypeInline() {
$checker = new LocalChecker( '{\\textstyle \\log2 }', 'inline-tex' );
$this->assertTrue( $checker->isValid() );
}
public function testInvalidType() {
$this->expectException( InvalidArgumentException::class );
new LocalChecker( '\sin x^2', 'chem' );
new LocalChecker( '\sin x^2', 'INVALIDTYPE' );
}
public function testInvalid() {