Debian Codegraph @

extensions/Math/tests/phpunit/unit/WikiTexVC/Nodes/LiteralTest.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\Nodes\Literal;
7 use MediaWiki\Extension\Math\WikiTexVC\Nodes\TexNode;
8 use MediaWikiUnitTestCase;
9 use TypeError;
10
11 /**
12 * @covers \MediaWiki\Extension\Math\WikiTexVC\Nodes\Literal
13 */
14 class LiteralTest extends MediaWikiUnitTestCase {
15
16 public function testBaseclass() {
17 $this->expectException( ArgumentCountError::class );
18 new Literal();
19 throw new ArgumentCountError( 'Should not create an empty literal' );
20 }
21
22 public function testOneArgument() {
23 $this->expectException( ArgumentCountError::class );
24 new Literal( 'a', 'b' );
25 throw new ArgumentCountError( 'Should not create a literal with more than one argument' );
26 }
27
28 public function testArgumentType() {
29 $this->expectException( TypeError::class );
30 new Literal( new Texnode() );
31 throw new TypeError( 'Should not create a literal with incorrect type' );
32 }
33
34 public function testOnlyOneArgument() {
35 $lit = new Literal( 'hello world' );
36 $this->assertEquals( 'hello world', $lit->render(),
37 'Should create an literal with only one argument' );
38 }
39
40 public function testRenderNodeBase() {
41 $lit = new Literal( 'hello world' );
42 $node = new TexNode( $lit );
43 $this->assertEquals( 'hello world', $node->render(),
44 'Should render within node base class' );
45 }
46
47 public function testNode() {
48 $lit = new Literal( 'hello world' );
49 $node = new TexNode( $lit );
50 $this->assertEquals( 'hello world', $node->render(),
51 'Should render within node base class' );
52 }
53
54 public function testExtractIdentifierModifications() {
55 $n = new Literal( 'a' );
56 $this->assertEquals( [ 'a' ], $n->getModIdent(),
57 'Should extract identifier modifications' );
58 }
59
60 public function testExtraSpace() {
61 $n = new Literal( '\\ ' );
62 $this->assertEquals( [ '\\ ' ], $n->getModIdent(),
63 'Identifier modifications should report extra space' );
64 }
65
66 public function testGetters() {
67 $lit = new Literal( 'hello world' );
68 $this->assertNotEmpty( $lit->getExtendedLiterals() );
69 $this->assertNotEmpty( $lit->getLiterals() );
70 $this->assertNotEmpty( $lit->getArg() );
71 }
72
73 public function testExtractSubscripts() {
74 $n = new Literal( '\\beta' );
75 $this->assertEquals( [ '\\beta' ], $n->extractSubscripts(),
76 'Should extract subscripts' );
77 }
78
79 public function testVLineNotInMatrix() {
80 $n = new Literal( '\\vline' );
81 $this->assertEquals( '<mi>\vline</mi>', $n->renderMML(),
82 'vline should fall through' );
83 }
84
85 public function testVLineInMatrix() {
86 $n = new Literal( '\\vline' );
87 $state = [ 'inMatrix' => true ];
88 $this->assertStringContainsString( '|</mo>', $n->renderMML( [], $state ),
89 'vline should render a vertical bar operator in matrix context.' );
90 }
91
92 public function testHBoxLiterals() {
93 $n = new Literal( 'in box' );
94 $state = [ 'inHBox' => true ];
95 $this->assertStringContainsString( 'in box', $n->renderMML( [], $state ),
96 'hboxes should not be wrapped in to mi elements.' );
97 }
98
99 public function testDoubleVerticalLine() {
100 $n = new Literal( '\\|' );
101 $this->assertStringContainsString( '&#x2016;</mo>', $n->renderMML(),
102 'double vertical line should render as special operator.' );
103 }
104
105 public function testColon() {
106 $n = new Literal( ':' );
107 $this->assertStringContainsString( ':</mo>', $n->renderMML(),
108 'colon should render as special operator.' );
109 }
110
111 public function testRangle() {
112 $n = new Literal( '\\rangle' );
113 $this->assertStringContainsString( 'stretchy="false"', $n->renderMML(),
114 'colon should render as special operator.' );
115 }
116
117 public function testVert() {
118 $n = new Literal( '|' );
119 $this->assertStringContainsString( 'stretchy="false"', $n->renderMML(),
120 '| should render as special operator.' );
121 }
122
123 public function testExclamationMark() {
124 $n = new Literal( '!' );
125 $this->assertStringContainsString( '!</mo>', $n->renderMML(),
126 'exclamation mark should render as special operator.' );
127 }
128
129 public function testDivide() {
130 $n = new Literal( '/' );
131 $real = $n->renderMML();
132 $this->assertStringContainsString( '/</mo>', $real,
133 'divide should render as special operator.' );
134 $this->assertStringContainsString( 'lspace="0" rspace="0"', $real,
135 'divide should have no spacing.' );
136 }
137
138 }