Debian Codegraph @

extensions/Math/tests/phpunit/unit/WikiTexVC/Nodes/DQTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Extension\Math\Tests\WikiTexVC\Nodes;
4
5 use ArgumentCountError;
6 use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmrow;
7 use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmsub;
8 use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmunder;
9 use MediaWiki\Extension\Math\WikiTexVC\Nodes\DQ;
10 use MediaWiki\Extension\Math\WikiTexVC\Nodes\Literal;
11 use MediaWiki\Extension\Math\WikiTexVC\Nodes\TexArray;
12 use MediaWiki\Extension\Math\WikiTexVC\Nodes\TexNode;
13 use MediaWikiUnitTestCase;
14 use RuntimeException;
15 use TypeError;
16
17 /**
18 * @covers \MediaWiki\Extension\Math\WikiTexVC\Nodes\DQ
19 */
20 class DQTest extends MediaWikiUnitTestCase {
21
22 public function testEmptyDQ() {
23 $this->expectException( ArgumentCountError::class );
24 new DQ();
25 throw new ArgumentCountError( 'Should not create an empty dq' );
26 }
27
28 public function testOneArgumentDQ() {
29 $this->expectException( ArgumentCountError::class );
30 new DQ( new Literal( 'a' ) );
31 throw new ArgumentCountError( 'Should not create a dq with one argument' );
32 }
33
34 public function testIncorrectTypeDQ() {
35 $this->expectException( TypeError::class );
36 new DQ( 'a', 'b' );
37 throw new RuntimeException( 'Should not create a dq with incorrect type' );
38 }
39
40 public function testBasicDQ() {
41 $dq = new DQ( new Literal( 'a' ), new Literal( 'b' ) );
42 $this->assertEquals( 'a_{b}', $dq->render(), 'Should create a basic dq' );
43 }
44
45 public function testGetters() {
46 $dq = new DQ( new Literal( 'a' ), new Literal( 'b' ) );
47 $this->assertNotEmpty( $dq->getBase() );
48 $this->assertNotEmpty( $dq->getDown() );
49 }
50
51 public function testEmptyBaseDQ() {
52 $dq = new DQ( new TexNode(), new Literal( 'b' ) );
53 $this->assertEquals( '_{b}', $dq->render(), 'Should create an empty base dq' );
54 }
55
56 public function testRenderEmptyDq() {
57 $dq = new DQ( TexArray::newCurly(), new Literal( 'b' ) );
58 $this->assertStringContainsString( ( new MMLmrow() )->getEmpty(), $dq->renderMML() );
59 }
60
61 public function testRenderEmptyDisplaystyle() {
62 $dq = new DQ( new Literal( '\\displaystyle' ), new Literal( 'b' ) );
63 $this->assertStringContainsString( ( new MMLmrow() )->getEmpty(), $dq->renderMML() );
64 }
65
66 public function testBigSum() {
67 $dq = new DQ( new Literal( '\\sum' ), new Literal( 'i' ) );
68 $this->assertStringContainsString( ( new MMLmunder() )->getStart(), $dq->renderMML() );
69 }
70
71 public function testSmallSum() {
72 $dq = new DQ( new Literal( '\\sum' ), new Literal( 'i' ) );
73 $state = [ 'styleargs' => [ 'displaystle' => 'false' ] ];
74 $this->assertStringContainsString(
75 ( new MMLmsub() )->getStart(),
76 $dq->renderMML( [], $state ) );
77 }
78
79 }