Debian Codegraph @

extensions/Math/tests/phpunit/unit/WikiTexVC/Nodes/Fun4Test.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\Fun4;
7 use MediaWiki\Extension\Math\WikiTexVC\Nodes\Literal;
8 use MediaWikiUnitTestCase;
9 use RuntimeException;
10 use TypeError;
11
12 /**
13 * @covers \MediaWiki\Extension\Math\WikiTexVC\Nodes\Fun4
14 */
15 class Fun4Test extends MediaWikiUnitTestCase {
16
17 public function testEmptyFun4() {
18 $this->expectException( ArgumentCountError::class );
19 new Fun4();
20 throw new ArgumentCountError( 'Should not create an empty fun4' );
21 }
22
23 public function testOneArgumentFun4() {
24 $this->expectException( ArgumentCountError::class );
25 new Fun4( '\\f' );
26 throw new ArgumentCountError( 'Should not create a fun4 with one argument' );
27 }
28
29 public function testIncorrectTypeFun4() {
30 $this->expectException( TypeError::class );
31 new Fun4( '\\f', 'a', 'b', 'c', 'd' );
32 throw new RuntimeException( 'Should not create a fun4 with incorrect types' );
33 }
34
35 public function testBasicFunctionFun4() {
36 $f = new Fun4( '\\f',
37 new Literal( 'a' ),
38 new Literal( 'b' ),
39 new Literal( 'c' ),
40 new Literal( 'd' ) );
41 $this->assertEquals( '{\\f {a}{b}{c}{d}}', $f->render(),
42 'Should create a basic function' );
43 }
44
45 public function testGetters() {
46 $f = new Fun4( '\\f',
47 new Literal( 'a' ),
48 new Literal( 'b' ),
49 new Literal( 'c' ),
50 new Literal( 'd' ) );
51 $this->assertNotEmpty( $f->getFname() );
52 $this->assertNotEmpty( $f->getArg1() );
53 $this->assertNotEmpty( $f->getArg2() );
54 $this->assertNotEmpty( $f->getArg3() );
55 $this->assertNotEmpty( $f->getArg4() );
56 }
57
58 public function testCurliesFun4() {
59 $f = new Fun4( '\\f',
60 new Literal( 'a' ),
61 new Literal( 'b' ),
62 new Literal( 'c' ),
63 new Literal( 'd' ) );
64 $this->assertEquals( '{\\f {a}{b}{c}{d}}', $f->inCurlies(),
65 'Should create exactly one set of curlies' );
66 }
67
68 public function testExtractIdentifiersFun4() {
69 $f = new Fun4( '\\f',
70 new Literal( 'a' ),
71 new Literal( 'b' ),
72 new Literal( 'c' ),
73 new Literal( 'd' ) );
74 $this->assertEquals( [ 'a', 'b', 'c', 'd' ], $f->extractIdentifiers(),
75 'Should extract identifiers' );
76 }
77 }