mediawiki-extensions-Math/tests/phpunit/unit/TexVC/Nodes/CurlyTest.php
Stegmujo ba47c32e1d
Add Node and Util fixes for Parser.php
For development history of this changeset see:
Id96a4b1b55e3959aab81f4ba436c5ac125f2a1bb

Bug: T312528

Change-Id: I61cfdbd63f8d50b072ada05927a134686fdd53d3
2022-10-19 16:33:15 +02:00

79 lines
2.6 KiB
PHP

<?php
namespace MediaWiki\Extension\Math\Tests\TexVC\Nodes;
use ArgumentCountError;
use MediaWiki\Extension\Math\TexVC\Nodes\Curly;
use MediaWiki\Extension\Math\TexVC\Nodes\DQ;
use MediaWiki\Extension\Math\TexVC\Nodes\Literal;
use MediaWiki\Extension\Math\TexVC\Nodes\TexArray;
use MediaWiki\Extension\Math\TexVC\Nodes\TexNode;
use MediaWikiUnitTestCase;
use RuntimeException;
use TypeError;
/**
* @covers \MediaWiki\Extension\Math\TexVC\Nodes\Curly
*/
class CurlyTest extends MediaWikiUnitTestCase {
public function testEmptyDollar() {
$this->expectException( ArgumentCountError::class );
new Curly();
throw new ArgumentCountError( 'Should not create an empty curly' );
}
public function testOneArgumentCurly() {
$this->expectException( ArgumentCountError::class );
new Curly( new TexArray( new TexNode( 'a' ) ), new TexArray( new TexNode( 'b' ) ) );
throw new ArgumentCountError( 'Should not create a curly with more than one argument' );
}
public function testIncorrectTypeCurly() {
$this->expectException( TypeError::class );
new Curly( new TexNode() );
throw new RuntimeException( 'Should not create a curly with incorrect type' );
}
public function testRenderTexCurly() {
$curly = new Curly( new TexArray() );
$this->assertEquals( '{}', $curly->render(), 'Should render a curly with empty tex array' );
}
public function testRenderListCurly() {
$curly = new Curly( new TexArray(
new Literal( 'hello' ),
new Literal( ' ' ),
new Literal( 'world' )
) );
$this->assertEquals( '{hello world}', $curly->render(), 'Should render a list' );
}
public function testGetters() {
$curly = new Curly( new TexArray( new Literal( 'b' ) ) );
$this->assertNotEmpty( $curly->getArgs() );
$this->assertNotEmpty( $curly->getArg() );
}
public function testNoExtraCurliesDQ() {
$dq = new DQ( new Literal( 'a' ),
new Curly( new TexArray( new Literal( 'b' ) ) ) );
$this->assertEquals( 'a_{b}', $dq->render(), 'Should not create extra curlies from dq' );
}
public function testNoExtraCurliesCurly() {
$curly = new Curly( new TexArray( new Literal( 'a' ) ) );
$this->assertEquals( '{a}', $curly->inCurlies(), 'Should not create extra curlies from curly' );
}
public function testExtractIdentifierModsCurly() {
$curly = new Curly( new TexArray( new Literal( 'b' ) ) );
$this->assertEquals( 'b', $curly->getModIdent(), 'Should extract identifier modifications' );
}
public function testExtractSubscirpts() {
$curly = new Curly( new TexArray( new Literal( 'b' ) ) );
$this->assertEquals( 'b', $curly->extractSubscripts(), 'Should extract subscripts' );
}
}