From aee95695b85c0a5d9e7decde46046b2f3ca40974 Mon Sep 17 00:00:00 2001 From: physikerwelt Date: Sat, 9 Nov 2024 07:29:40 +0100 Subject: [PATCH] Don't stretch delimiters and operators when used as literals * Adjust tests Bug: T375959 Change-Id: I02de8244b73c4b98a1467011a0035df059917c13 --- src/WikiTexVC/MMLmappings/BaseMethods.php | 2 +- src/WikiTexVC/Nodes/Literal.php | 7 +++++-- .../unit/WikiTexVC/Mhchem/MhchemBasicMMLTest.php | 6 +++--- tests/phpunit/unit/WikiTexVC/Nodes/LiteralTest.php | 12 ++++++++++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/WikiTexVC/MMLmappings/BaseMethods.php b/src/WikiTexVC/MMLmappings/BaseMethods.php index 79d5a357b..8bf289bb7 100644 --- a/src/WikiTexVC/MMLmappings/BaseMethods.php +++ b/src/WikiTexVC/MMLmappings/BaseMethods.php @@ -91,7 +91,7 @@ class BaseMethods { return $this->parseOperatorDict( $node, $passedArgs, $operatorContent, $input, false ); } // Atm just do simple parsing for elements in operator dictionary - $mmlMo = new MMLmo(); + $mmlMo = new MMLmo( '', $passedArgs ); return $mmlMo->encapsulateRaw( $input ); } } diff --git a/src/WikiTexVC/Nodes/Literal.php b/src/WikiTexVC/Nodes/Literal.php index b2d916852..b4df7f960 100644 --- a/src/WikiTexVC/Nodes/Literal.php +++ b/src/WikiTexVC/Nodes/Literal.php @@ -92,7 +92,10 @@ class Literal extends TexNode { // Sieve for Operators $bm = new BaseMethods(); - $ret = $bm->checkAndParseOperator( $inputP, $this, $arguments, $operatorContent, $state, false ); + $noStretchArgs = $arguments; + // Delimiters and operators should not be stretchy by default when used as literals + $noStretchArgs['stretchy'] ??= 'false'; + $ret = $bm->checkAndParseOperator( $inputP, $this, $noStretchArgs, $operatorContent, $state, false ); if ( $ret ) { return $ret; } @@ -109,7 +112,7 @@ class Literal extends TexNode { return $ret; } // Sieve for Delimiters - $ret = $bm->checkAndParseDelimiter( $input, $this, $arguments, $operatorContent ); + $ret = $bm->checkAndParseDelimiter( $input, $this, $noStretchArgs, $operatorContent ); if ( $ret ) { return $ret; } diff --git a/tests/phpunit/unit/WikiTexVC/Mhchem/MhchemBasicMMLTest.php b/tests/phpunit/unit/WikiTexVC/Mhchem/MhchemBasicMMLTest.php index 6fafb6246..ed94ad6c6 100644 --- a/tests/phpunit/unit/WikiTexVC/Mhchem/MhchemBasicMMLTest.php +++ b/tests/phpunit/unit/WikiTexVC/Mhchem/MhchemBasicMMLTest.php @@ -56,7 +56,7 @@ final class MhchemBasicMMLTest extends MediaWikiUnitTestCase { $mml = $res['input']->renderMML(); $this->assertStringContainsString( 'assertStringContainsString( $result . '', $mml ); - $this->assertStringContainsString( '', $mml ); + $this->assertStringContainsString( '∼', $mml ); } public function testHarpoonsLeftRight() { @@ -77,7 +77,7 @@ final class MhchemBasicMMLTest extends MediaWikiUnitTestCase { $warnings = []; $res = $texVC->check( $input, $options, $warnings, true ); $mml = $res['input']->renderMML(); - $this->assertStringContainsString( '', $mml ); + $this->assertStringContainsString( '−', $mml ); $this->assertStringContainsString( '⇀', $mml ); $this->assertStringContainsString( '', $mml ); $this->assertStringContainsString( 'check( $input, [ "usemhchem" => true, "usemhchemtexified" => true ], $warnings, true ); - $this->assertStringContainsString( '', + $this->assertStringContainsString( '−', $checkRes["input"]->renderMML() ); } diff --git a/tests/phpunit/unit/WikiTexVC/Nodes/LiteralTest.php b/tests/phpunit/unit/WikiTexVC/Nodes/LiteralTest.php index 0749390e4..d107e4487 100644 --- a/tests/phpunit/unit/WikiTexVC/Nodes/LiteralTest.php +++ b/tests/phpunit/unit/WikiTexVC/Nodes/LiteralTest.php @@ -106,4 +106,16 @@ class LiteralTest extends MediaWikiUnitTestCase { 'colon should render as special operator.' ); } + public function testRangle() { + $n = new Literal( '\\rangle' ); + $this->assertStringContainsString( 'stretchy="false"', $n->renderMML(), + 'colon should render as special operator.' ); + } + + public function testVert() { + $n = new Literal( '|' ); + $this->assertStringContainsString( 'stretchy="false"', $n->renderMML(), + '| should render as special operator.' ); + } + }