Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4058918
MhchemParserTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
MhchemParserTest.php
View Options
<?php
namespace
MediaWiki\Extension\Math\WikiTexVC\Mhchem\Tests
;
use
MediaWiki\Extension\Math\WikiTexVC\Mhchem\MhchemParser
;
use
PHPUnit\Framework\TestCase
;
/**
* Unit tests for the MhchemParser::toTex method.
*
* The toTex method converts chemical notations or physical unit strings into TeX output.
*
* @covers \MediaWiki\Extension\Math\WikiTexVC\Mhchem\MhchemParser
* @covers \MediaWiki\Extension\Math\WikiTexVC\Mhchem\MhchemTexify
*/
class
MhchemParserTest
extends
TestCase
{
/**
* Test the toTex method with a simple chemical equation.
*/
public
function
testToTexWithSimpleChemicalEquation
()
{
$parser
=
new
MhchemParser
();
$input
=
'H2O'
;
$type
=
'ce'
;
$result
=
$parser
->
toTex
(
$input
,
$type
);
$this
->
assertIsString
(
$result
);
$this
->
assertEquals
(
'{
\m
athrm{H}{
\v
phantom{A}}_{
\s
mash[t]{2}}
\m
athrm{O}}'
,
$result
);
}
/**
* Test the toTex method with physical unit parsing.
*/
public
function
testToTexWithPhysicalUnit
()
{
$parser
=
new
MhchemParser
();
$input
=
'm/s^2'
;
$type
=
'pu'
;
$result
=
$parser
->
toTex
(
$input
,
$type
);
$this
->
assertIsString
(
$result
);
$this
->
assertEquals
(
'{
\m
athrm{m}/
\m
athrm{s^{2}}}'
,
$result
,
'The TeX output for physical units should match expected value'
);
}
/**
* Test the toTex method with an empty input.
*/
public
function
testToTexWithEmptyInput
()
{
$parser
=
new
MhchemParser
();
$input
=
''
;
$type
=
'ce'
;
$result
=
$parser
->
toTex
(
$input
,
$type
);
$this
->
assertIsString
(
$result
,
'The output should be a string'
);
$this
->
assertSame
(
''
,
$result
,
'The output for empty input should be empty'
);
}
/**
* Test the toTex method with optimization for TeX VC enabled.
*/
public
function
testToTexWithOptimizationForTexVC
()
{
$parser
=
new
MhchemParser
();
$input
=
'C
\b
ond{-~-}D'
;
$type
=
'ce'
;
$optimizeMhchemForTexVC
=
true
;
$result
=
$parser
->
toTex
(
$input
,
$type
,
$optimizeMhchemForTexVC
);
$this
->
assertIsString
(
$result
,
'The output should be a string'
);
$this
->
assertEquals
(
'{
\m
athrm{C}{
\r
lap{
\l
ower{.2em}{-}}
\r
lap{
\r
aise{.2em}{-}}
\t
ripledash}
\m
athrm{D}}'
,
$result
,
'The TeX output should include extra curlies for optimization'
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Aug 16 2026, 05:05 (12 w, 22 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
b9/07/f8593b9858ce6c82261963f6c9e6
Default Alt Text
MhchemParserTest.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment