| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Math\WikiTexVC\Mhchem; |
| 4 |
|
| 5 |
use MediaWiki\Extension\Math\WikiTexVC\TexVC; |
| 6 |
use MediaWikiUnitTestCase; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
final class MhchemBasicMMLTest extends MediaWikiUnitTestCase { |
| 17 |
|
| 18 |
public function testGUIStyleNotation() { |
| 19 |
$input = "{\displaystyle \ce{ C6H5-CHO }}"; |
| 20 |
$texVC = new TexVC(); |
| 21 |
$options = [ "usemhchem" => true, "usemhchemtexified" => true ]; |
| 22 |
$warnings = []; |
| 23 |
$res = $texVC->check( $input, $options, $warnings, true ); |
| 24 |
$mml = $res['input']->renderMML(); |
| 25 |
$this->assertStringContainsString( '<mpadded', $mml ); |
| 26 |
$this->assertStringContainsString( '<mphantom', $mml ); |
| 27 |
} |
| 28 |
|
| 29 |
public static function provideTestCasesLetters() { |
| 30 |
return [ |
| 31 |
[ "Alpha", "A" ], |
| 32 |
[ "Beta", "B" ], |
| 33 |
[ "Chi", "X" ], |
| 34 |
[ "Epsilon", "E" ], |
| 35 |
[ "Eta", "H" ], |
| 36 |
[ "Iota", "I" ], |
| 37 |
[ "Kappa", "K" ], |
| 38 |
[ "Mu", "M" ], |
| 39 |
[ "Nu", "N" ], |
| 40 |
[ "Omicron", "O" ], |
| 41 |
[ "Rho", "P" ], |
| 42 |
[ "Tau", "T" ], |
| 43 |
[ "Zeta", "Z" ] |
| 44 |
]; |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public function testmhchemLetters( $case, $result ) { |
| 51 |
$input = "\ce{\\" . $case . " \ca }"; |
| 52 |
$texVC = new TexVC(); |
| 53 |
$options = [ "usemhchem" => true, "usemhchemtexified" => true ]; |
| 54 |
$warnings = []; |
| 55 |
$res = $texVC->check( $input, $options, $warnings, true ); |
| 56 |
$mml = $res['input']->renderMML(); |
| 57 |
$this->assertStringContainsString( '<mi', $mml ); |
| 58 |
$this->assertStringContainsString( $result . '</mi>', $mml ); |
| 59 |
$this->assertStringContainsString( '∼</mo>', $mml ); |
| 60 |
} |
| 61 |
|
| 62 |
public function testHarpoonsLeftRight() { |
| 63 |
$input = "A \\longLeftrightharpoons L"; |
| 64 |
$texVC = new TexVC(); |
| 65 |
$options = [ "usemhchem" => true, "usemhchemtexified" => true ]; |
| 66 |
$warnings = []; |
| 67 |
$res = $texVC->check( $input, $options, $warnings, true ); |
| 68 |
$mml = $res['input']->renderMML(); |
| 69 |
$this->assertStringContainsString( '<mpadded height="0" depth="0">', $mml ); |
| 70 |
$this->assertStringContainsString( '<mspace ', $mml ); |
| 71 |
} |
| 72 |
|
| 73 |
public function testHarpoonsRightLeft() { |
| 74 |
$input = "A \\longRightleftharpoons R"; |
| 75 |
$texVC = new TexVC(); |
| 76 |
$options = [ "usemhchem" => true, "usemhchemtexified" => true ]; |
| 77 |
$warnings = []; |
| 78 |
$res = $texVC->check( $input, $options, $warnings, true ); |
| 79 |
$mml = $res['input']->renderMML(); |
| 80 |
$this->assertStringContainsString( '−</mo>', $mml ); |
| 81 |
$this->assertStringContainsString( '⇀', $mml ); |
| 82 |
$this->assertStringContainsString( '<mpadded height="0" depth="0">', $mml ); |
| 83 |
$this->assertStringContainsString( '<mspace ', $mml ); |
| 84 |
} |
| 85 |
|
| 86 |
public function testArrowsLeftRight() { |
| 87 |
$input = "A \\longleftrightarrows C"; |
| 88 |
$texVC = new TexVC(); |
| 89 |
$options = [ "usemhchem" => true, "usemhchemtexified" => true ]; |
| 90 |
$warnings = []; |
| 91 |
$res = $texVC->check( $input, $options, $warnings, true ); |
| 92 |
$mml = $res['input']->renderMML(); |
| 93 |
$this->assertStringContainsString( '<mo stretchy="false">⟵</mo>', $mml ); |
| 94 |
$this->assertStringContainsString( '<mo stretchy="false">⟶</mo>', $mml ); |
| 95 |
$this->assertStringContainsString( '<mpadded height="0" depth="0">', $mml ); |
| 96 |
$this->assertStringContainsString( '<mspace ', $mml ); |
| 97 |
} |
| 98 |
|
| 99 |
public function testTripleDash() { |
| 100 |
$input = "\\tripledash \\frac{a}{b}"; |
| 101 |
$texVC = new TexVC(); |
| 102 |
$options = [ "usemhchem" => true, "usemhchemtexified" => true ]; |
| 103 |
$warnings = []; |
| 104 |
$res = $texVC->check( $input, $options, $warnings, true ); |
| 105 |
$this->assertStringContainsString( '<mo>—</mo>', |
| 106 |
$res['input']->renderMML() ); |
| 107 |
} |
| 108 |
|
| 109 |
public function testMathchoiceDisplaystyle() { |
| 110 |
$input = "\\displaystyle{\\mathchoice{a}{b}{c}{d}}"; |
| 111 |
$texVC = new TexVC(); |
| 112 |
$options = [ "usemhchem" => true, "usemhchemtexified" => true ]; |
| 113 |
$warnings = []; |
| 114 |
$res = $texVC->check( $input, $options, $warnings, true ); |
| 115 |
$this->assertStringContainsString( '<mstyle displaystyle="true" scriptlevel="0"><mi>a</mi></mstyle>', |
| 116 |
$res['input']->renderMML() ); |
| 117 |
} |
| 118 |
|
| 119 |
public function testMathchoiceTextstyle() { |
| 120 |
$input = "\\textstyle{\\mathchoice{a}{b}{c}{d}}"; |
| 121 |
$texVC = new TexVC(); |
| 122 |
$options = [ "usemhchem" => true, "usemhchemtexified" => true ]; |
| 123 |
$warnings = []; |
| 124 |
$res = $texVC->check( $input, $options, $warnings, true ); |
| 125 |
$this->assertStringContainsString( '<mstyle displaystyle="false" scriptlevel="0"><mi>b</mi></mstyle>', |
| 126 |
$res['input']->renderMML() ); |
| 127 |
} |
| 128 |
|
| 129 |
public function testMathchoiceScriptstyle() { |
| 130 |
$input = "\\scriptstyle{\\mathchoice{a}{b}{c}{d}}"; |
| 131 |
$texVC = new TexVC(); |
| 132 |
$options = [ "usemhchem" => true, "usemhchemtexified" => true ]; |
| 133 |
$warnings = []; |
| 134 |
$res = $texVC->check( $input, $options, $warnings, true ); |
| 135 |
$this->assertStringContainsString( '<mstyle displaystyle="false" scriptlevel="1"><mi>c</mi></mstyle>', |
| 136 |
$res['input']->renderMML() ); |
| 137 |
} |
| 138 |
|
| 139 |
public function testMathchoiceScriptScriptstyle() { |
| 140 |
$input = "\\scriptscriptstyle{\\mathchoice{a}{b}{c}{d}}"; |
| 141 |
$texVC = new TexVC(); |
| 142 |
$options = [ "usemhchem" => true, "usemhchemtexified" => true ]; |
| 143 |
$warnings = []; |
| 144 |
$res = $texVC->check( $input, $options, $warnings, true ); |
| 145 |
$this->assertStringContainsString( '<mstyle displaystyle="false" scriptlevel="2"><mi>d</mi></mstyle>', |
| 146 |
$res['input']->renderMML() ); |
| 147 |
} |
| 148 |
|
| 149 |
public function testMskip() { |
| 150 |
$input = "\\ce{Cr^{+3}(aq)}"; |
| 151 |
$texVC = new TexVC(); |
| 152 |
$options = [ "usemhchem" => true, "usemhchemtexified" => true ]; |
| 153 |
$warnings = []; |
| 154 |
$checkRes = $texVC->check( $input, $options, $warnings, true ); |
| 155 |
$this->assertStringContainsString( '<mspace width="0.111em"></mspace>', |
| 156 |
$checkRes["input"]->renderMML() ); |
| 157 |
} |
| 158 |
|
| 159 |
public function testMkern() { |
| 160 |
$input = "\\ce{A, B}"; |
| 161 |
$texVC = new TexVC(); |
| 162 |
$options = [ "usemhchem" => true, "usemhchemtexified" => true ]; |
| 163 |
$warnings = []; |
| 164 |
$checkRes = $texVC->check( $input, $options, $warnings, true ); |
| 165 |
$this->assertStringContainsString( '<mspace width="0.333em"></mspace>', |
| 166 |
$checkRes["input"]->renderMML() ); |
| 167 |
} |
| 168 |
|
| 169 |
public function testRaise() { |
| 170 |
$input = "\\raise{.2em}{-}"; |
| 171 |
$texVC = new TexVC(); |
| 172 |
$warnings = []; |
| 173 |
$checkRes = $texVC->check( $input, [ "usemhchem" => true, "usemhchemtexified" => true ], |
| 174 |
$warnings, true ); |
| 175 |
$this->assertStringContainsString( '<mpadded height="+.2em" depth="-.2em" voffset="+.2em">', |
| 176 |
$checkRes["input"]->renderMML() ); |
| 177 |
} |
| 178 |
|
| 179 |
public function testLower() { |
| 180 |
$input = "\\lower{1em}{-}"; |
| 181 |
$texVC = new TexVC(); |
| 182 |
$warnings = []; |
| 183 |
$checkRes = $texVC->check( $input, [ "usemhchem" => true, "usemhchemtexified" => true ], |
| 184 |
$warnings, true ); |
| 185 |
$this->assertStringContainsString( '<mpadded height="-1em" depth="+1em" voffset="-1em">', |
| 186 |
$checkRes["input"]->renderMML() ); |
| 187 |
} |
| 188 |
|
| 189 |
public function testLower2() { |
| 190 |
$input = "\\lower{-1em}{b}"; |
| 191 |
$texVC = new TexVC(); |
| 192 |
$warnings = []; |
| 193 |
$checkRes = $texVC->check( $input, [ "usemhchem" => true, "usemhchemtexified" => true ], |
| 194 |
$warnings, true ); |
| 195 |
$this->assertStringContainsString( '<mpadded height="+1em" depth="-1em" voffset="+1em">', |
| 196 |
$checkRes["input"]->renderMML() ); |
| 197 |
} |
| 198 |
|
| 199 |
public function testLlap() { |
| 200 |
$input = "\\llap{4}"; |
| 201 |
$texVC = new TexVC(); |
| 202 |
$warnings = []; |
| 203 |
$checkRes = $texVC->check( $input, [ "usemhchem" => true, "usemhchemtexified" => true ], |
| 204 |
$warnings, true ); |
| 205 |
$this->assertStringContainsString( '<mpadded width="0" lspace="-1width"><mn>4</mn></mpadded>', |
| 206 |
$checkRes["input"]->renderMML() ); |
| 207 |
} |
| 208 |
|
| 209 |
public function testRlap() { |
| 210 |
$input = "\\rlap{-}"; |
| 211 |
$texVC = new TexVC(); |
| 212 |
$warnings = []; |
| 213 |
$checkRes = $texVC->check( $input, [ "usemhchem" => true, "usemhchemtexified" => true ], |
| 214 |
$warnings, true ); |
| 215 |
$this->assertStringContainsString( '−</mo></mpadded>', |
| 216 |
$checkRes["input"]->renderMML() ); |
| 217 |
} |
| 218 |
|
| 219 |
public function testSmash1() { |
| 220 |
$input = "\ce{\\smash[t]{2}}"; |
| 221 |
$texVC = new TexVC(); |
| 222 |
$warnings = []; |
| 223 |
$checkRes = $texVC->check( $input, [ "usemhchem" => true, "usemhchemtexified" => true ], |
| 224 |
$warnings, true ); |
| 225 |
$this->assertStringContainsString( '<mpadded height="0">', $checkRes["input"]->renderMML() ); |
| 226 |
} |
| 227 |
|
| 228 |
public function testSmash2() { |
| 229 |
$input = "\ce{\\smash[b]{x}}"; |
| 230 |
$texVC = new TexVC(); |
| 231 |
$warnings = []; |
| 232 |
$checkRes = $texVC->check( $input, [ "usemhchem" => true, "usemhchemtexified" => true ], |
| 233 |
$warnings, true ); |
| 234 |
$this->assertStringContainsString( '<mpadded depth="0">', $checkRes["input"]->renderMML() ); |
| 235 |
} |
| 236 |
|
| 237 |
public function testSmash3() { |
| 238 |
$input = "\ce{\\smash[bt]{2}}"; |
| 239 |
$texVC = new TexVC(); |
| 240 |
$warnings = []; |
| 241 |
$checkRes = $texVC->check( $input, [ "usemhchem" => true, "usemhchemtexified" => true ], |
| 242 |
$warnings, true ); |
| 243 |
$this->assertStringContainsString( '<mpadded height="0" depth="0">', |
| 244 |
$checkRes["input"]->renderMML() ); |
| 245 |
} |
| 246 |
|
| 247 |
public function testSmash4() { |
| 248 |
$input = "\ce{\\smash[tb]{2}}"; |
| 249 |
$texVC = new TexVC(); |
| 250 |
$warnings = []; |
| 251 |
$checkRes = $texVC->check( $input, [ "usemhchem" => true, "usemhchemtexified" => true ], |
| 252 |
$warnings, true ); |
| 253 |
$this->assertStringContainsString( '<mpadded height="0" depth="0">', |
| 254 |
$checkRes["input"]->renderMML() ); |
| 255 |
} |
| 256 |
|
| 257 |
public function testSmash5() { |
| 258 |
$input = "\ce{\\smash{2}}"; |
| 259 |
$texVC = new TexVC(); |
| 260 |
$warnings = []; |
| 261 |
$checkRes = $texVC->check( $input, [ "usemhchem" => true, "usemhchemtexified" => true ], |
| 262 |
$warnings, true ); |
| 263 |
$ar = $checkRes["input"]->renderMML(); |
| 264 |
$this->assertStringContainsString( '<mpadded height="0" depth="0"', $ar ); |
| 265 |
} |
| 266 |
|
| 267 |
} |