Debian Codegraph @

extensions/Math/tests/phpunit/unit/WikiTexVC/Nodes/InfixTest.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\Infix;
7 use MediaWiki\Extension\Math\WikiTexVC\Nodes\Literal;
8 use MediaWiki\Extension\Math\WikiTexVC\Nodes\TexArray;
9 use MediaWikiUnitTestCase;
10 use TypeError;
11
12 /**
13 * @covers \MediaWiki\Extension\Math\WikiTexVC\Nodes\Infix
14 */
15 class InfixTest extends MediaWikiUnitTestCase {
16
17 public function testEmptyInfix() {
18 $this->expectException( ArgumentCountError::class );
19 new Infix();
20 throw new ArgumentCountError( 'Should not create an empty infix' );
21 }
22
23 public function testOneArgumentInfix() {
24 $this->expectException( ArgumentCountError::class );
25 new Infix( '\\f' );
26 throw new ArgumentCountError( 'Should not create an infix with one argument' );
27 }
28
29 public function testIncorrectTypeInfix() {
30 $this->expectException( TypeError::class );
31 new Infix( '\\atop', 'x', 'y' );
32 throw new TypeError( 'Should not create an infix with incorrect type' );
33 }
34
35 public function testBasicInfix() {
36 $infix = new Infix( '\\atop',
37 new TexArray( new Literal( 'a' ) ),
38 new TexArray( new Literal( 'b' ) ) );
39 $this->assertEquals( '{a \\atop b}', $infix->render(), 'Should create a basic infix' );
40 }
41
42 public function testGetters() {
43 $infix = new Infix( '\\atop',
44 new TexArray( new Literal( 'a' ) ),
45 new TexArray( new Literal( 'b' ) ) );
46 $this->assertNotEmpty( $infix->getOp() );
47 $this->assertNotEmpty( $infix->getArg1() );
48 $this->assertNotEmpty( $infix->getArg2() );
49 }
50
51 public function testCurliesInfix() {
52 $f = new Infix( '\\atop',
53 new TexArray( new Literal( 'a' ) ),
54 new TexArray( new Literal( 'b' ) ) );
55 $this->assertEquals( '{a \\atop b}', $f->inCurlies(),
56 'Should create exactly one set of curlies' );
57 }
58
59 public function testExtractIdentifiersInfix() {
60 $f = new Infix( '\\atop',
61 new TexArray( new Literal( 'a' ) ),
62 new TexArray( new Literal( 'b' ) ) );
63 $this->assertEquals( [ 'a', 'b' ], $f->extractIdentifiers(),
64 'Should extract identifiers' );
65 }
66 }