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
|
|
|
|
2023-11-24 09:30:05 +00:00
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\DQ;
|
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\Literal;
|
|
|
|
use MediaWiki\Extension\Math\WikiTexVC\Nodes\TexArray;
|
2022-08-29 10:15:58 +00:00
|
|
|
use MediaWikiUnitTestCase;
|
|
|
|
|
|
|
|
/**
|
2024-02-17 23:02:37 +00:00
|
|
|
* @covers \MediaWiki\Extension\Math\WikiTexVC\Nodes\TexArray
|
2022-08-29 10:15:58 +00:00
|
|
|
*/
|
|
|
|
class CurlyTest extends MediaWikiUnitTestCase {
|
|
|
|
|
|
|
|
public function testRenderTexCurly() {
|
2024-02-17 23:02:37 +00:00
|
|
|
$curly = TexArray::newCurly();
|
2022-08-29 10:15:58 +00:00
|
|
|
$this->assertEquals( '{}', $curly->render(), 'Should render a curly with empty tex array' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRenderListCurly() {
|
2024-02-17 23:02:37 +00:00
|
|
|
$curly = TexArray::newCurly(
|
|
|
|
new Literal( 'hello' ),
|
|
|
|
new Literal( ' ' ),
|
|
|
|
new Literal( 'world' )
|
|
|
|
);
|
2022-08-29 10:15:58 +00:00
|
|
|
$this->assertEquals( '{hello world}', $curly->render(), 'Should render a list' );
|
|
|
|
}
|
|
|
|
|
2022-10-10 13:34:23 +00:00
|
|
|
public function testGetters() {
|
2024-02-17 23:02:37 +00:00
|
|
|
$curly = TexArray::newCurly( new Literal( 'b' ) );
|
2022-10-10 13:34:23 +00:00
|
|
|
$this->assertNotEmpty( $curly->getArgs() );
|
|
|
|
}
|
|
|
|
|
2022-08-29 10:15:58 +00:00
|
|
|
public function testNoExtraCurliesDQ() {
|
|
|
|
$dq = new DQ( new Literal( 'a' ),
|
2024-02-17 23:02:37 +00:00
|
|
|
TexArray::newCurly( new Literal( 'b' ) ) );
|
2022-08-29 10:15:58 +00:00
|
|
|
$this->assertEquals( 'a_{b}', $dq->render(), 'Should not create extra curlies from dq' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNoExtraCurliesCurly() {
|
2024-02-17 23:02:37 +00:00
|
|
|
$curly = TexArray::newCurly( new Literal( 'a' ) );
|
2022-08-29 10:15:58 +00:00
|
|
|
$this->assertEquals( '{a}', $curly->inCurlies(), 'Should not create extra curlies from curly' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExtractIdentifierModsCurly() {
|
2024-02-17 23:02:37 +00:00
|
|
|
$curly = TexArray::newCurly( new Literal( 'b' ) );
|
2022-08-29 10:15:58 +00:00
|
|
|
$this->assertEquals( 'b', $curly->getModIdent(), 'Should extract identifier modifications' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testExtractSubscirpts() {
|
2024-02-17 23:02:37 +00:00
|
|
|
$curly = TexArray::newCurly( new Literal( 'b' ) );
|
2022-08-29 10:15:58 +00:00
|
|
|
$this->assertEquals( 'b', $curly->extractSubscripts(), 'Should extract subscripts' );
|
|
|
|
}
|
|
|
|
}
|