Debian Codegraph @

extensions/Math/tests/phpunit/unit/WikiTexVC/Nodes/Fun2Test.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\Fun2;
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\Fun2
14 */
15 class Fun2Test extends MediaWikiUnitTestCase {
16
17 public function testEmptyFun2() {
18 $this->expectException( ArgumentCountError::class );
19 new Fun2();
20 throw new ArgumentCountError( 'Should not create an empty fun2' );
21 }
22
23 public function testOneArgumentFun2() {
24 $this->expectException( ArgumentCountError::class );
25 new Fun2( '\\f' );
26 throw new ArgumentCountError( 'Should not create a fun2 with one argument' );
27 }
28
29 public function testIncorrectTypeFun2() {
30 $this->expectException( TypeError::class );
31 new Fun2( '\\f', 'x', 'y' );
32 throw new RuntimeException( 'Should not create a fun2 with incorrect types' );
33 }
34
35 public function testBasicFunctionFun2() {
36 $f = new Fun2( '\\f', new Literal( 'a' ), new Literal( 'b' ) );
37 $this->assertEquals( '{\\f {a}{b}}', $f->render(),
38 'Should create a basic function' );
39 }
40
41 public function testGetters() {
42 $f = new Fun2( '\\f', new Literal( 'a' ), new Literal( 'b' ) );
43 $this->assertNotEmpty( $f->getFname() );
44 $this->assertNotEmpty( $f->getArg1() );
45 $this->assertNotEmpty( $f->getArg2() );
46 }
47
48 public function testCurliesFun2() {
49 $f = new Fun2( '\\f', new Literal( 'a' ), new Literal( 'b' ) );
50 $this->assertEquals( '{\\f {a}{b}}', $f->inCurlies(),
51 'Should create exactly one set of curlies' );
52 }
53
54 public function testExtractIdentifiersFun2() {
55 $f = new Fun2( '\\f', new Literal( 'a' ), new Literal( 'b' ) );
56 $this->assertEquals( [ 'a', 'b' ], $f->extractIdentifiers(),
57 'Should extract identifiers' );
58 }
59 }