2022-08-29 10:15:58 +00:00
|
|
|
<?php
|
|
|
|
|
2023-11-24 09:30:05 +00:00
|
|
|
namespace MediaWiki\Extension\Math\Tests\WikiTexVC\Nodes;
|
2022-08-29 10:15:58 +00:00
|
|
|
|
|
|
|
use ArgumentCountError;
|
2024-01-02 19:36:49 +00:00
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\DQ;
|
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\FQ;
|
2023-11-24 09:30:05 +00:00
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\Fun1;
|
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\Literal;
|
2024-01-02 19:36:49 +00:00
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\TexArray;
|
2022-08-29 10:15:58 +00:00
|
|
|
use MediaWikiUnitTestCase;
|
|
|
|
use RuntimeException;
|
|
|
|
use TypeError;
|
|
|
|
|
|
|
|
/**
|
2023-11-24 09:30:05 +00:00
|
|
|
* @covers \MediaWiki\Extension\Math\WikiTexVC\Nodes\Fun1
|
2022-08-29 10:15:58 +00:00
|
|
|
*/
|
|
|
|
class Fun1Test extends MediaWikiUnitTestCase {
|
|
|
|
|
|
|
|
public function testEmptyFun1() {
|
|
|
|
$this->expectException( ArgumentCountError::class );
|
|
|
|
new Fun1();
|
|
|
|
throw new ArgumentCountError( 'Should not create an empty fun1' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOneArgumentFun1() {
|
|
|
|
$this->expectException( ArgumentCountError::class );
|
|
|
|
new Fun1( '\\f' );
|
|
|
|
throw new ArgumentCountError( 'Should not create a fun1 with one argument' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIncorrectTypeFun1() {
|
|
|
|
$this->expectException( TypeError::class );
|
|
|
|
new Fun1( '\\f', 'x' );
|
|
|
|
throw new RuntimeException( 'Should not create a fun1 with incorrect type' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testBasicFunctionFun1() {
|
|
|
|
$f = new Fun1( '\\f', new Literal( 'a' ) );
|
|
|
|
$this->assertEquals( '{\\f {a}}', $f->render(),
|
|
|
|
'Should create a basic function' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCurliesFun1() {
|
|
|
|
$f = new Fun1( '\\f', new Literal( 'a' ) );
|
|
|
|
$this->assertEquals( '{\\f {a}}', $f->inCurlies(),
|
|
|
|
'Should create exactly one set of curlies' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExtractIdentifiersFun1() {
|
|
|
|
$f = new Fun1( '\\mathbf', new Literal( 'B' ) );
|
|
|
|
$this->assertEquals( [ '\\mathbf{B}' ], $f->extractIdentifiers(),
|
|
|
|
'Should extract identifiers' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExtractExtendedLiteralsFun1() {
|
|
|
|
$f = new Fun1( '\\mathbf', new Literal( '\\infty' ) );
|
|
|
|
$this->assertEquals( [], $f->extractIdentifiers(),
|
|
|
|
'Should not extract extended literals as identifiers.' );
|
|
|
|
}
|
|
|
|
|
2022-10-10 13:34:23 +00:00
|
|
|
public function testGetters() {
|
|
|
|
$f = new Fun1( '\\mathbf', new Literal( '\\infty' ) );
|
|
|
|
$this->assertNotEmpty( $f->getFname() );
|
|
|
|
$this->assertNotEmpty( $f->getArg() );
|
|
|
|
}
|
|
|
|
|
2022-08-29 10:15:58 +00:00
|
|
|
public function testExtractPhantomIdentifiers() {
|
|
|
|
$f = new Fun1( '\\hphantom', new Literal( 'A' ) );
|
|
|
|
$this->assertEquals( [], $f->extractIdentifiers(),
|
|
|
|
'Should not extract phantom identifiers.' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIgnoreUnknownFunctions() {
|
|
|
|
$f = new Fun1( '\\unknown', new Literal( 'A' ) );
|
|
|
|
$this->assertEquals( [ 'A' ], $f->extractIdentifiers(),
|
|
|
|
'Should ignore unknown functions.' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExtractIdentifierMods() {
|
|
|
|
$f = new Fun1( '\\mathbf', new Literal( 'B' ) );
|
|
|
|
$this->assertEquals( [ '\\mathbf{B}' ], $f->getModIdent(),
|
|
|
|
'Should extract identifier modifications.' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExtractSubscripts() {
|
|
|
|
$f = new Fun1( '\\mathbf', new Literal( 'B' ) );
|
|
|
|
$this->assertEquals( [ '\\mathbf{B}' ],
|
|
|
|
$f->extractSubscripts(), 'Should extract subscripts.' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExtractSubscriptsExtendedLits() {
|
|
|
|
$f = new Fun1( '\\mathbf', new Literal( '\\infty' ) );
|
|
|
|
$this->assertEquals( [ '\\mathbf{\\infty}' ], $f->extractSubscripts(),
|
|
|
|
'Should extract subscripts for extended literals.' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExtractSubscriptsEmptyMods() {
|
|
|
|
$f = new Fun1( '\\mathbf', new Literal( '' ) );
|
|
|
|
$this->assertEquals( [], $f->extractSubscripts(),
|
|
|
|
'Should not extract subscripts for empty mods.' );
|
|
|
|
}
|
|
|
|
|
2024-01-02 19:36:49 +00:00
|
|
|
public function testMathRmLiteral() {
|
|
|
|
$f = new Fun1( '\\mathrm', new Literal( 'b' ) );
|
|
|
|
$this->assertStringContainsString( 'mathvariant="normal"', $f->renderMML() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMathRmCurly() {
|
2024-02-17 23:02:37 +00:00
|
|
|
$f = new Fun1( '\\mathrm', TexArray::newCurly(
|
2024-01-02 19:36:49 +00:00
|
|
|
new Literal( 'a' ),
|
|
|
|
new Literal( 'b' ),
|
2024-02-17 23:02:37 +00:00
|
|
|
) );
|
2024-01-02 19:36:49 +00:00
|
|
|
$rendering = $f->renderMML();
|
|
|
|
preg_match_all( '/mathvariant="normal"/', $rendering, $matches );
|
|
|
|
$this->assertCount( 2, $matches[0] );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMathRmDq() {
|
2024-02-17 23:02:37 +00:00
|
|
|
$f = new Fun1( '\\mathrm', TexArray::newCurly(
|
2024-01-02 19:36:49 +00:00
|
|
|
new DQ( new Literal( 'a' ), new Literal( 'b' ) )
|
2024-02-17 23:02:37 +00:00
|
|
|
) );
|
2024-01-02 19:36:49 +00:00
|
|
|
$rendering = $f->renderMML();
|
|
|
|
preg_match_all( '/mathvariant="normal"/', $rendering, $matches );
|
|
|
|
$this->assertCount( 2, $matches[0] );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMathRmFq() {
|
2024-02-17 23:02:37 +00:00
|
|
|
$f = new Fun1( '\\mathrm', TexArray::newCurly(
|
2024-01-02 19:36:49 +00:00
|
|
|
new FQ( new Literal( 'a' ), new Literal( 'b' ), new Literal( 'c' ) )
|
2024-02-17 23:02:37 +00:00
|
|
|
) );
|
2024-01-02 19:36:49 +00:00
|
|
|
$rendering = $f->renderMML();
|
|
|
|
preg_match_all( '/mathvariant="normal"/', $rendering, $matches );
|
|
|
|
$this->assertCount( 2, $matches[0] );
|
|
|
|
}
|
2022-08-29 10:15:58 +00:00
|
|
|
}
|