| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Math\Tests\WikiTexVC\Nodes; |
| 4 |
|
| 5 |
use ArgumentCountError; |
| 6 |
use MediaWiki\Extension\Math\WikiTexVC\Nodes\Fun1nb; |
| 7 |
use MediaWiki\Extension\Math\WikiTexVC\Nodes\Literal; |
| 8 |
use MediaWiki\Extension\Math\WikiTexVC\Nodes\TexNode; |
| 9 |
use MediaWiki\Extension\Math\WikiTexVC\Nodes\UQ; |
| 10 |
use MediaWikiUnitTestCase; |
| 11 |
use RuntimeException; |
| 12 |
use TypeError; |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
class UQTest extends MediaWikiUnitTestCase { |
| 18 |
|
| 19 |
public function testEmptyUQ() { |
| 20 |
$this->expectException( ArgumentCountError::class ); |
| 21 |
new UQ(); |
| 22 |
throw new ArgumentCountError( 'Should not create an empty uq' ); |
| 23 |
} |
| 24 |
|
| 25 |
public function testOneArgumentUQ() { |
| 26 |
$this->expectException( ArgumentCountError::class ); |
| 27 |
new UQ( new Literal( 'a' ) ); |
| 28 |
throw new ArgumentCountError( 'Should not create a uq with one argument' ); |
| 29 |
} |
| 30 |
|
| 31 |
public function testIncorrectTypeUQ() { |
| 32 |
$this->expectException( TypeError::class ); |
| 33 |
new UQ( 'a', 'b' ); |
| 34 |
throw new RuntimeException( 'Should not create a uq with incorrect type' ); |
| 35 |
} |
| 36 |
|
| 37 |
public function testBasicUQ() { |
| 38 |
$uq = new UQ( new Literal( 'a' ), new Literal( 'b' ) ); |
| 39 |
$this->assertEquals( 'a^{b}', $uq->render(), 'Should create a basic uq' ); |
| 40 |
} |
| 41 |
|
| 42 |
public function testGetters() { |
| 43 |
$uq = new UQ( new Literal( 'a' ), new Literal( 'b' ) ); |
| 44 |
$this->assertNotEmpty( $uq->getBase() ); |
| 45 |
$this->assertNotEmpty( $uq->getUp() ); |
| 46 |
} |
| 47 |
|
| 48 |
public function testEmptyBaseUQ() { |
| 49 |
$uq = new UQ( new TexNode(), new Literal( 'b' ) ); |
| 50 |
$this->assertEquals( '^{b}', $uq->render(), 'Should create an empty base uq' ); |
| 51 |
} |
| 52 |
|
| 53 |
public function testOperatorname() { |
| 54 |
$uq = new UQ( new Fun1nb( '\\operatorname', new Literal( 'a' ) ), new Literal( 'b' ) ); |
| 55 |
$this->assertStringContainsString( '<msup', $uq->renderMML(), |
| 56 |
'Operator superscript should be rendered after the operator.' ); |
| 57 |
} |
| 58 |
|
| 59 |
public function testOverOperator() { |
| 60 |
$uq = new UQ( new Fun1nb( '\\overarc', new Literal( 'a' ) ), new Literal( 'b' ) ); |
| 61 |
$this->assertStringContainsString( '<mover', $uq->renderMML(), |
| 62 |
'Over_operators be rendered over the operator.' ); |
| 63 |
} |
| 64 |
} |