2022-08-17 13:26:25 +00:00
|
|
|
<?php
|
|
|
|
|
2023-11-24 09:30:05 +00:00
|
|
|
namespace MediaWiki\Extension\Math\Tests\WikiTexVC\Nodes;
|
2022-08-17 13:26:25 +00:00
|
|
|
|
|
|
|
use ArgumentCountError;
|
2023-11-24 09:30:05 +00:00
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\Literal;
|
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\TexNode;
|
2022-08-17 13:26:25 +00:00
|
|
|
use MediaWikiUnitTestCase;
|
|
|
|
use TypeError;
|
|
|
|
|
|
|
|
/**
|
2023-11-24 09:30:05 +00:00
|
|
|
* @covers \MediaWiki\Extension\Math\WikiTexVC\Nodes\Literal
|
2022-08-17 13:26:25 +00:00
|
|
|
*/
|
|
|
|
class LiteralTest extends MediaWikiUnitTestCase {
|
|
|
|
|
|
|
|
public function testBaseclass() {
|
|
|
|
$this->expectException( ArgumentCountError::class );
|
|
|
|
new Literal();
|
|
|
|
throw new ArgumentCountError( 'Should not create an empty literal' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOneArgument() {
|
|
|
|
$this->expectException( ArgumentCountError::class );
|
|
|
|
new Literal( 'a', 'b' );
|
|
|
|
throw new ArgumentCountError( 'Should not create a literal with more than one argument' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testArgumentType() {
|
|
|
|
$this->expectException( TypeError::class );
|
|
|
|
new Literal( new Texnode() );
|
|
|
|
throw new TypeError( 'Should not create a literal with incorrect type' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOnlyOneArgument() {
|
|
|
|
$lit = new Literal( 'hello world' );
|
|
|
|
$this->assertEquals( 'hello world', $lit->render(),
|
|
|
|
'Should create an literal with only one argument' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRenderNodeBase() {
|
|
|
|
$lit = new Literal( 'hello world' );
|
|
|
|
$node = new TexNode( $lit );
|
|
|
|
$this->assertEquals( 'hello world', $node->render(),
|
|
|
|
'Should render within node base class' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNode() {
|
|
|
|
$lit = new Literal( 'hello world' );
|
|
|
|
$node = new TexNode( $lit );
|
|
|
|
$this->assertEquals( 'hello world', $node->render(),
|
|
|
|
'Should render within node base class' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExtractIdentifierModifications() {
|
|
|
|
$n = new Literal( 'a' );
|
|
|
|
$this->assertEquals( [ 'a' ], $n->getModIdent(),
|
|
|
|
'Should extract identifier modifications' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExtraSpace() {
|
|
|
|
$n = new Literal( '\\ ' );
|
|
|
|
$this->assertEquals( [ '\\ ' ], $n->getModIdent(),
|
|
|
|
'Identifier modifications should report extra space' );
|
|
|
|
}
|
|
|
|
|
2022-10-10 13:34:23 +00:00
|
|
|
public function testGetters() {
|
|
|
|
$lit = new Literal( 'hello world' );
|
|
|
|
$this->assertNotEmpty( $lit->getExtendedLiterals() );
|
|
|
|
$this->assertNotEmpty( $lit->getLiterals() );
|
|
|
|
$this->assertNotEmpty( $lit->getArg() );
|
|
|
|
}
|
|
|
|
|
2022-08-17 13:26:25 +00:00
|
|
|
public function testExtractSubscripts() {
|
|
|
|
$n = new Literal( '\\beta' );
|
|
|
|
$this->assertEquals( [ '\\beta' ], $n->extractSubscripts(),
|
|
|
|
'Should extract subscripts' );
|
|
|
|
}
|
|
|
|
|
2023-02-08 12:39:01 +00:00
|
|
|
public function testVLineNotInMatrix() {
|
|
|
|
$n = new Literal( '\\vline' );
|
|
|
|
$this->assertEquals( '<mi>\vline</mi>', $n->renderMML(),
|
|
|
|
'vline should fall through' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testVLineInMatrix() {
|
|
|
|
$n = new Literal( '\\vline' );
|
|
|
|
$this->assertStringContainsString( '|</mo>', $n->renderMML( [], [ 'inMatrix' => true ] ),
|
|
|
|
'vline should render a vertical bar operator in matrix context.' );
|
|
|
|
}
|
|
|
|
|
2023-02-13 13:04:36 +00:00
|
|
|
public function testHBoxLiterals() {
|
|
|
|
$n = new Literal( 'in box' );
|
|
|
|
$this->assertStringContainsString( 'in box', $n->renderMML( [], [ 'inHBox' => true ] ),
|
|
|
|
'hboxes should not be wrapped in to mi elements.' );
|
|
|
|
}
|
|
|
|
|
2024-10-05 21:00:34 +00:00
|
|
|
public function testDoubleVerticalLine() {
|
|
|
|
$n = new Literal( '\\|' );
|
|
|
|
$this->assertStringContainsString( '‖</mo>', $n->renderMML(),
|
|
|
|
'double vertical line should render as special operator.' );
|
|
|
|
}
|
|
|
|
|
2022-08-17 13:26:25 +00:00
|
|
|
}
|