mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-27 17:01:07 +00:00
Merge "Make TexArray iterable"
This commit is contained in:
commit
024cdbb00f
|
@ -4,6 +4,7 @@ declare( strict_types = 1 );
|
|||
|
||||
namespace MediaWiki\Extension\Math\WikiTexVC\Nodes;
|
||||
|
||||
use Generator;
|
||||
use InvalidArgumentException;
|
||||
use MediaWiki\Extension\Math\WikiTexVC\MMLmappings\BaseMappings;
|
||||
use MediaWiki\Extension\Math\WikiTexVC\MMLmappings\Util\MMLParsingUtil;
|
||||
|
@ -14,7 +15,7 @@ use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmstyle;
|
|||
use MediaWiki\Extension\Math\WikiTexVC\MMLnodes\MMLmsup;
|
||||
use MediaWiki\Extension\Math\WikiTexVC\TexUtil;
|
||||
|
||||
class TexArray extends TexNode {
|
||||
class TexArray extends TexNode implements \IteratorAggregate {
|
||||
protected bool $curly = false;
|
||||
|
||||
public static function newCurly( ...$args ) {
|
||||
|
@ -427,7 +428,7 @@ class TexArray extends TexNode {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return TexNode|string|null first value
|
||||
* @return TexNode|null first value
|
||||
*/
|
||||
public function first() {
|
||||
if ( isset( $this->args[0] ) ) {
|
||||
|
@ -438,7 +439,7 @@ class TexArray extends TexNode {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return TexNode|string|null second value
|
||||
* @return TexNode|null second value
|
||||
*/
|
||||
public function second() {
|
||||
if ( isset( $this->args[1] ) ) {
|
||||
|
@ -482,4 +483,10 @@ class TexArray extends TexNode {
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Generator<TexNode>
|
||||
*/
|
||||
public function getIterator(): Generator {
|
||||
yield from $this->args;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,4 +79,14 @@ class TexArrayTest extends MediaWikiUnitTestCase {
|
|||
$n->unshift( 'test1', 'test2' );
|
||||
$this->assertEquals( 3, $n->getLength(), 'Should unshift elements' );
|
||||
}
|
||||
|
||||
public function testGenerator() {
|
||||
$ta = new TexArray( new Literal( 'a' ), new Literal( 'b' ) );
|
||||
foreach ( $ta as $item ) {
|
||||
$this->assertInstanceOf(
|
||||
'MediaWiki\Extension\Math\WikiTexVC\Nodes\Literal',
|
||||
$item,
|
||||
'Should iterate over the elements' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue