| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Math\Tests\WikiTexVC\Nodes; |
| 4 |
|
| 5 |
use ArgumentCountError; |
| 6 |
use MediaWiki\Extension\Math\WikiTexVC\Nodes\Declh; |
| 7 |
use MediaWiki\Extension\Math\WikiTexVC\Nodes\Literal; |
| 8 |
use MediaWiki\Extension\Math\WikiTexVC\Nodes\TexArray; |
| 9 |
use MediaWikiUnitTestCase; |
| 10 |
use RuntimeException; |
| 11 |
use TypeError; |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
class DeclhTest extends MediaWikiUnitTestCase { |
| 17 |
|
| 18 |
public function testEmptyDeclh() { |
| 19 |
$this->expectException( ArgumentCountError::class ); |
| 20 |
new Declh(); |
| 21 |
throw new ArgumentCountError( 'Should not create an empty Declh' ); |
| 22 |
} |
| 23 |
|
| 24 |
public function testOneArgumentDeclh() { |
| 25 |
$this->expectException( ArgumentCountError::class ); |
| 26 |
new Declh( '\\f' ); |
| 27 |
throw new ArgumentCountError( 'Should not create a Declh with one argument' ); |
| 28 |
} |
| 29 |
|
| 30 |
public function testIncorrectTypeDeclh() { |
| 31 |
$this->expectException( TypeError::class ); |
| 32 |
new Declh( '\\f', 'x' ); |
| 33 |
throw new RuntimeException( 'Should not create a Declh with incorrect type' ); |
| 34 |
} |
| 35 |
|
| 36 |
public function testBasicFunctionDeclh() { |
| 37 |
$f = new Declh( '\\rm', new TexArray( new Literal( 'a' ) ) ); |
| 38 |
$this->assertEquals( '{\\rm {a}}', $f->render(), 'Should create a basic function' ); |
| 39 |
} |
| 40 |
|
| 41 |
public function testGetters() { |
| 42 |
$f = new Declh( '\\rm', new TexArray( new Literal( 'a' ) ) ); |
| 43 |
$this->assertNotEmpty( $f->getFname() ); |
| 44 |
$this->assertNotEmpty( $f->getArg() ); |
| 45 |
} |
| 46 |
|
| 47 |
public function testTwoArgsFunctionDeclh() { |
| 48 |
$f = new Declh( '\\rm', |
| 49 |
new TexArray( new Literal( 'a' ), new Literal( 'b' ) ) ); |
| 50 |
$this->assertEquals( '{\\rm {ab}}', |
| 51 |
$f->render(), 'Should create a function with two arguments' ); |
| 52 |
} |
| 53 |
|
| 54 |
public function testCurliesDeclh() { |
| 55 |
$f = new Declh( '\\f', new TexArray( new Literal( 'a' ) ) ); |
| 56 |
$this->assertEquals( '{\\f {a}}', $f->inCurlies(), 'Should create exactly one set of curlies' ); |
| 57 |
} |
| 58 |
|
| 59 |
public function testExtractIdentifiersDeclh() { |
| 60 |
$f = new Declh( '\\rm', new TexArray( new Literal( 'a' ) ) ); |
| 61 |
$this->assertEquals( [ 'a' ], $f->extractIdentifiers(), 'Should extract identifiers' ); |
| 62 |
} |
| 63 |
|
| 64 |
public function testExtractNoIdentifiersDeclh() { |
| 65 |
$f = new Declh( '\\rm', new TexArray() ); |
| 66 |
$this->assertEquals( [], $f->extractIdentifiers(), 'Should extract identifiers' ); |
| 67 |
} |
| 68 |
|
| 69 |
public function testExtractIdentifiersMultiDeclh() { |
| 70 |
$f = new Declh( '\\rm', new TexArray( new Literal( 'a' ), new Literal( 'b' ) ) ); |
| 71 |
$this->assertEquals( [ 'ab' ], $f->extractIdentifiers(), 'Should extract multiple identifiers' ); |
| 72 |
} |
| 73 |
|
| 74 |
public function testNotExtractSomeSubscripts() { |
| 75 |
$f = new Declh( '\\bf', new TexArray( new Literal( '' ) ) ); |
| 76 |
$this->assertEquals( [], $f->extractSubscripts(), |
| 77 |
'Should not extract empty font modifier subscripts identifiers' ); |
| 78 |
} |
| 79 |
|
| 80 |
public function testSubscriptsForFontMod() { |
| 81 |
$mods = [ 'rm', 'it', 'cal', 'bf' ]; |
| 82 |
foreach ( $mods as $mod ) { |
| 83 |
$f = new Declh( "\\{$mod}", new TexArray( new Literal( 'a' ) ) ); |
| 84 |
$this->assertEquals( [ "\\math{$mod}{a}" ], $f->extractSubscripts(), |
| 85 |
"Should extract subscripts for {$mod} font modification" ); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
public function testRenderMML() { |
| 90 |
$f = new Declh( '\\bf', new TexArray( new Literal( 'a' ) ) ); |
| 91 |
$this->assertStringContainsString( 'mathvariant="bold"', $f->renderMML(), 'MathML should render bold' ); |
| 92 |
} |
| 93 |
} |