Merge "Activate chem and inline-tex type input in LocalChecker"

This commit is contained in:
jenkins-bot 2022-10-25 17:50:31 +00:00 committed by Gerrit Code Review
commit ded8f70772
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() {