Debian Codegraph @

extensions/Math/tests/phpunit/unit/WikiTexVC/Nodes/DollarTest.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\Dollar;
7 use MediaWiki\Extension\Math\WikiTexVC\Nodes\Literal;
8 use MediaWiki\Extension\Math\WikiTexVC\Nodes\TexArray;
9 use MediaWiki\Extension\Math\WikiTexVC\Nodes\TexNode;
10 use MediaWikiUnitTestCase;
11 use RuntimeException;
12 use TypeError;
13
14 /**
15 * @covers \MediaWiki\Extension\Math\WikiTexVC\Nodes\Dollar
16 */
17 class DollarTest extends MediaWikiUnitTestCase {
18
19 public function testEmptyDollar() {
20 $this->expectException( ArgumentCountError::class );
21 new Dollar();
22 throw new ArgumentCountError( 'Should not create an empty dollar' );
23 }
24
25 public function testOneArgumentDollar() {
26 $this->expectException( ArgumentCountError::class );
27 new Dollar( new TexArray(), new TexArray() );
28 throw new ArgumentCountError( 'Should not create a dollar with more than one argument' );
29 }
30
31 public function testIncorrectTypeDollar() {
32 $this->expectException( TypeError::class );
33 new Dollar( new TexNode() );
34 throw new RuntimeException( 'Should not create a dollar with incorrect type' );
35 }
36
37 public function testRenderTexDollar() {
38 $dollar = new Dollar( new TexArray() );
39 $this->assertEquals( '$$', $dollar->render(), 'Should render a dollar with empty tex array' );
40 }
41
42 public function testRenderListDollar() {
43 $dollar = new Dollar( new TexArray(
44 new Literal( 'hello' ),
45 new Literal( ' ' ),
46 new Literal( 'world' )
47 ) );
48 $this->assertEquals( '$hello world$', $dollar->render(), 'Should render a list' );
49 }
50
51 public function testExtractIdentifiersDollar() {
52 $dollar = new Dollar( new TexArray(
53 new Literal( 'a' ),
54 new Literal( 'b' ),
55 new Literal( 'c' )
56 ) );
57 $this->assertEquals( [], $dollar->extractIdentifiers(), 'Should extract identifiers' );
58 }
59 }