Template:Chem2/testcases

Proposal: add parameter checks

 * -12:26, 6 March 2023 (UTC)


 * Waiting for -DePiep (talk) 09:24, 28 February 2023 (UTC)
 * See talk
 * Prepared in Chem2/sandbox2. -DePiep (talk) 09:24, 28 February 2023 (UTC)
 * Prepared in Chem2/sandbox2. -DePiep (talk) 09:24, 28 February 2023 (UTC)


 * Tests (also by ):
 * Example, by /sandbox2:
 * &rarr;
 * &rarr;


 * to check (negative check expected): "A{B{Q}" -- error all right, but for other reason (unbalanced, & end-bracket). Effect is OK.
 * &rarr; {{chem2/sandbox2|1=A{B{Q}|2=}}
 * &rarr; {{chem2/sandbox2|1=A{B|2=}}
 * pattern: >{{#invoke:String|match|s=A{B{Q}|pattern=(%{[^%}]*)$|plain=false|ignore_errors=true|nomatch=}}<
 * -DePiep (talk) 05:49, 1 March 2023 (UTC)

subscript hyphen (Feb 2023)

 * -DePiep (talk) 19:47, 27 February 2023 (UTC)


 * Issue:
 * Chem2/sandbox initially: now has Module:Chem2/sandbox (from live source code).
 * Template styles: Module:Chem2/styles.css (Chem2/sandbox/styles.css diff)


 * Bug reproduction:
 * (A) code:  &rarr; A_{x}H_{1-x} (current live result)
 * Hardcoded result from expanded live template (19:36, 27 February 2023):  Ax H1-x
 * (B, {chem2/sandbox} live):
 * Characters involved:
 * (H) &rarr; A_{x}H_{1-x}
 * (M) &rarr; A_{x}M_{1−x}


 * Done /sandbox: L239, % not \ (tot test; errors from live code?)
 * L250, L251


 * what's with \s, \-
 * whatwhen entering &amp;minus; ?

tests

 * Module:Chem2, Module:Chem2/sandbox
 * tst setup:  (H, M)
 * test minus M>−< vs, hyphen H>-<:
 * live, in:H>-<: A^{1-y}B_{1-x}H(2-)
 * /sbx, in:H>-<:
 * live, in:M>−<: A^{1−y}B_{1−x}M(2−)
 * /sbx, in:M>−<:
 * All sup/sub returns (8) are U+002d hyphen ❌
 * All (4) 2- charge returnsa are U+2212 ✅
 * -DePiep (talk) 20:36, 27 February 2023 (UTC)


 * Entering &minus;
 * live, in:>&amp;minus;<: A^{1&minus;y}B_{1&minus;x}M(2&minus;) -- incidentally, returns as expected ..
 * /sbx, in:>&amp;minus;<:


 * Entering &beta;
 * live, in:>&amp;beta;<: A^{1&beta;y}B_{1&beta;x}M(2&beta;)
 * /sbx, in:>&amp;beta;<:


 * lol from doc: use \s, \-
 * live, in:H>\-<: A^{1\-y}B_{1\-x}H(2\-)
 * /sbx, in:H>\-<:
 * live, in:M>\s<: A^{1\sy}B_{1\sx}M(2\s)
 * /sbx, in:M>\s<:

talk: debugging & tests

 * see /testcases at


 * More research:
 * Test string to be (rule: when final-{{hl|1=} }} in formula input, end pipe {{hl|1= }|}} }} is required):
 * (A)  &rarr; A_{x}H_{1-x}
 * Characters involved:
 * (H) &rarr; A_{x}H_{1-x}
 * (M) &rarr; A_{x}M_{1−x}
 * re MSGJ: by reading the code, none of the lines 277 (good replacement), 288 (good replacement), 294 (hyphen only) seem to make the wrong replacement.
 * -DePiep (talk) 19:02, 27 February 2023 (UTC)
 * code review:
 * L239 (current live):
 * {{code|1=^\^{[^}]*}|2=}} ? expected {{code|1=^^{[^}]*}|2=}} (Lua pattern not regex; module preview reports Error: [239:42] invalid escape sequence near '\^'. (Errors from this, missed? hidden?) edited in sandboxDePiep (talk) 19:57, 27 February 2023 (UTC)


 * test code to be:
 * Three minus/hyphen signs input, expected result: all three Minus (M). Current live test:
 * Live M>−<: A^{1−y}B_{1−x}M(2−)
 * returns H, H, M. sup/sub issue. -DePiep (talk) 20:43, 27 February 2023 (UTC)
 * returns H, H, M. sup/sub issue. -DePiep (talk) 20:43, 27 February 2023 (UTC)

talk: Bug report

 * See /testcases at . module:Chem2, current live code.
 * (H)
 * (M)

From original report (OP); B2-B (demo/test inline) and (4-) (charge) added as extra testcases (situations 1–4 now).
 * In the tests here, B2-B is added and is not targeted (no changes claimed nor expected; ignored in conclsions)
 * in H>-<: HA^{1-x}B2-B_{3-x}(4-) -- ❌ MINUS expected
 * in M>−<: MA^{1−x}B2−B_{3−x}(4−) -- ❌ MINUS expected
 * in H>-<: HA^{1-x}B2-B_{3-x}(4-) -- ❌ MINUS expected
 * in M>−<: MA^{1−x}B2−B_{3−x}(4−) -- ❌ MINUS expected


 * (A) Original complaint:
 * MINUS (−) not kept when in (topically correct) sub/supscripted formula is entered; shows hyphen (-) instead.
 * Cause: early replaces NDASH and MINUS with HYPHEN, to be treatred similar (see code L250, 251).
 * When as charge, the hyphen is changed into MINUS all right, but no such replacement in the supsubscripts.
 * Proposed solution: in T_CARET and T_UNDERSCORE change any hyphen (from early replacement) into MINUS.
 * live, in:H>-<: HA^{1-x}B2-B_{3-x}(4-)
 * /sbx, in:H>-<:
 * live, in:M>−<: MA^{1−x}B2−B_{3−x}(4−)
 * /sbx, in:M>−<:
 * Showing: current live version returns HYPHEN in subsuptexts; correct MINUS inline and in the "(2-)" charge). All irrespective of input character.


 * (B) Handling of HTML entities (&amp;minus;)
 * When entering like &minus; (for character MINUS), it is not handled as the character.
 * Incidentally, this preserves the MINUS character as asked for in the OP (undocumented 'solution', hack).
 * However, not documented and would give different results between input &minus; vs. −. Also, other codes entries could be affected.
 * Proposed solution: add early decoding mw.text.decode.


 * Entering HTML Entity &minus;
 * live, in:>&amp;minus;<: EA^{1&minus;x}B2&minus;B_{3&minus;x}(4&minus;) -- incidentally, returns as expected
 * /sbx, in:>&amp;minus;<:
 * Entering &beta;
 * live, in:>&amp;beta;<: EA^{1&beta;x}B2&beta;B_{3&beta;x}(4&beta;) -- as expected :/sbx, in:>&amp;beta;<: -- same result (returns decoded &amp;beta; to UA: decoded later)


 * (C) Bad code
 * Parser gives error: {{code|1='^\^{[^}]*}'}} has incorrect "\" (note: expected is Lua pattern not Regex). Saves with error (-warning).
 * No error effects (in pages) known, nor seen in testpage.
 * From Lua documentation mw:Lua manual: "At other positions, '^' and '$' have no special meaning and represent themselves". That is: the second caret should represent the input character (to indicate superscript).
 * Proposed solution: Remove the slash: . No effects in tests seen.
 * Testcases: see superscripts (CARET input) throughout.
 * Late note 29 March 2023, from mw:Lua_reference_manual § string: the code \^ is not required to escape the literal character in Lua code (as opposed to e.g., \"). -DePiep (talk) 05:04, 29 March 2023 (UTC)


 * (D) Escape codes limitations
 * The /documentation mentions \s, \- for input "single bond" (topical term) and "hyphen" when used in line. However, they don't work as expected when in sup/subscripted text (as in OP).
 * Proposed solution: the escape codes are not developed to function more widely. Instead, documentation to be improved (mention limitations).


 * From doc: use \s, \- slashed escape code (note: "B2-B" as expected)
 * live, in:>\s<: SsA^{1\sx}B2\sB_{3\sx}(4\s)
 * /sbx, in:>\s<:
 * live, in:>\-<: ShA^{1\-}B2\-B_{3\-x}(4\-)
 * /sbx, in:>\-<:
 * -DePiep (talk) 00:06, 28 February 2023 (UTC)

(T) more tests: bare hyphen: input without no preceding number etc in text element (eg, charge "(-)"):
 * HA^{-x}-B_{-x}(-)
 * MA^{−x}−B_{−x}(−)
 * EA^{&minus;x}&minus;B_{&minus;x}(&minus;) -- &amp;minus;
 * Adjustmensts, refining testcases, spell uc MINUS etc, create 4 numberred testsituations DePiep 05:41, 28 February 2023
 * For more bare "-" input tests (not "2-" &tc;), see /testcases (UTC), -DePiep (talk) 06:36, 28 February 2023 (UTC)
 * Adjustmensts, refining testcases, spell uc MINUS etc, create 4 numberred testsituations DePiep 05:41, 28 February 2023
 * For more bare "-" input tests (not "2-" &tc;), see /testcases (UTC), -DePiep (talk) 06:36, 28 February 2023 (UTC)
 * For more bare "-" input tests (not "2-" &tc;), see /testcases (UTC), -DePiep (talk) 06:36, 28 February 2023 (UTC)

(T2) added in /testcases
(T2) more bare tests FWIW: rm italice,, use \s \-
 * live
 * HA^{-x}-B_{-x}(-)
 * MA^{-x}-B_{-x}-
 * SsA^{\sx}\sB_{\sx}\s
 * ShA^{\-x}\-B_{\-x}\-
 * SsA^{\sx}\sB_{\sx}(\s)
 * ShA^{\-x}\-B_{\-x}(\-)
 * /sbox

Proposal (code edit)

 * From the Report above, I propose to oconsider: edit all code from module:Chem2/sandbox into module:Chem2.
 * Note: the (B) may change behaviour (instances relying on undocumented effects). Conservation action needed? OTOH, when entering &amp;minus;, what else should be expected than MINUS?
 * Also, I'd like to have chemicist eyes taking a look.
 * More tests at the Template:Chem2/testcases.
 * -DePiep (talk) 00:06, 28 February 2023 (UTC)
 * ping|Christian75|Mikhail Ryazanov|MSGJ demos and tests stable & ok now, please take a look. -DePiep (talk) 06:41, 28 February 2023 (UTC)

Formula punctuation (Chem2 live)
 ^ If the last character of the template input is, MediaWiki will confuse it with the end-of-template tag. Adding a space between the two resolves this ambiguity. Other options include instead inserting  or.

Formula punctuation (Chem2/sandbox)
 ^ If the last character of the template input is, MediaWiki will confuse it with the end-of-template tag. Adding a space between the two resolves this ambiguity. Other options include instead inserting  or.

from Doc


 ^ If the last character of the template input is, MediaWiki will confuse it with the end-of-template tag. Adding  between the two resolves this ambiguity. Other options include instead inserting  (space),   or.

Formulas (without charge) are just written. Eg.:
 * gives CH3(CH2)5CH3
 * gives Fe3S2(CO)9
 * gives C_{n}H_{2n+2}

Charges are written inside parenthesis, otherwise its treated as +1 or −1, e.g.:
 * gives Na+
 * gives O2- but can be written as  too.
 * gives SO4(2-)
 * gives S19(2+)

Chemical equations can be written too. E.g.: The arrows can be written as  or just. All characters (and unicode markup) are valid input except, = (Mediawiki use it),   and   (endash etc.)
 * gives 2 S + 3 O2 + 2 H2O -> 2 H2SO4
 * gives 2S + 3O2 + 2H2O -> 2H2SO4
 * gives 2 H2_{(g)} + O2_{(g)} -> 2H2O_{(g)}
 * gives NH2RCHCO2H <-> NH3+RCHCO2-

Hapticity and mu:
 * gives W(CO)3(PiPr3)2(\h{2}\-H2)
 * gives W(CO)3(PiPr3)2(\h{2}\-H2)

Links: Use or ordinary wiki link (  and  ), e.g.:
 * gives FeCl3
 * gives 3H2 + 2N2 <-> 2NH3

Auto links: Automatic link elements: Use (e.g.  ):
 * gives CH3CH2CH3CBrFCIClCH3

All /sandbox


 ^ If the last character of the template input is, MediaWiki will confuse it with the end-of-template tag. Adding  between the two resolves this ambiguity. Other options include instead inserting  (space),   or.

/doc

 * using /sandbox

/doc Formula punctuation
 ^ If the last character of the template input is, MediaWiki will confuse it with the end-of-template tag. Adding a space between the two resolves this ambiguity. Other options include instead inserting  or.

/doc Formulas, charges, equations
Formulas (without charge) are just written:
 * &rarr; CH3(CH2)5CH3
 * &rarr; Fe3S2(CO)9
 * &rarr; C_{n}H_{2n+2}

Charges are written inside parentheses:
 * &rarr; SO4(2-)
 * &rarr; S19(2+)

Charges +1 and &minus;1 can be written plain:
 * &rarr; Na+
 * &rarr; O2-
 * equals

Chemical equations: The arrows can be written as  or just. All characters (and unicode markup) are valid input except, = (Mediawiki use it),   and   (endash etc.)
 * &rarr; 2 S + 3 O2 + 2 H2O -> 2 H2SO4
 * &rarr; 2S + 3O2 + 2H2O -> 2H2SO4
 * &rarr; 2 H2_{(g)} + O2_{(g)} -> 2H2O_{(g)}
 * &rarr; NH2RCHCO2H <-> NH3+RCHCO2-

Hapticity and mu:
 * &rarr; W(CO)3(PiPr3)2(\h{2}H2)
 * &rarr; W(CO)3(PiPr3)2(\h{2}H2)

/doc Whole formula link
Link the whole formula with &lt;wiki pagename&gt;:

Or use wikilink brackets in input like :

/doc Link each element (C, Hg) and generic element code (R, X)

 * Use yes to link each element symbol once, as well as some others such as Ph



/doc Link functional groups
Some common groups are recognized and linked if you wikilink them using
 * In particular H2O links to water of crystallization in, because a link to water is generally unnecessary.
 * In particular H2O links to water of crystallization in, because a link to water is generally unnecessary.
 * In particular H2O links to water of crystallization in, because a link to water is generally unnecessary.

You can link to any article even if chem2 is unaware of it:!-- same as |link=... then -->

To change the default link:

/doc Examples

 * gives [Cl4Re\qReCl4](2−)
 * gives [Cl4Re\qReCl4](2-)
 * gives NH2RCHCO2H <-> NH3+RCHCO2−


 * gives \\hallo
 * gives H3CC\tCH <-> H2C\dC\dCH2
 * gives 4 NH3 + 5 O2 -> 4 NO + 6 H2O


 * "H2O &amp;#8594; H2O" is H2O &#8594; H2O
 * "H2O_{(l)} -> H2O_{(g)}" is H2O_{(l)} -> H2O_{(g)}


 * "4 NH3 + 5 O2 → 4 NO + 6 H2O" is 4 NH3 + 5 O2 → 4 NO + 6 H2O
 * " 4 NH3 + 5 O2 → 4 NO + 6 H2O" is 4 NH3 + 5 O2 → 4 NO + 6 H2O
 * " 4NH3 + 5O2 → 4NO + 6H2O" is 4NH3 + 5O2 → 4NO + 6H2O
 * " 2Mn2(+)" is 2Mn2(+)
 * " 2Mn2(+) + 3H2O" is 2Mn2(+) + 3H2O
 * Mn– is Mn–


 * Mn2(2-) is Mn2(2-)
 * Mn2☃+ is Mn2☃+, Mn2(2–) is Mn2(2–), Mn2(2☃–) is Mn2(2☃–)
 * Mn2(+) is Mn2(+)
 * Mn2+ is Mn2+
 * Mn2(-) is Mn2(-)
 * Mn2- is Mn2-


 * C_{n}H_{2n + 2} gives C_{n}H_{2n + 2}
 * C_{abc} gives C_{abc}
 * (chem gives )
 * CoCl2*1.5H2O gives CoCl2*1.5H2O
 * Mn22– is Mn22–
 * Cu2C2*H2O is Cu2C2*H2O


 * Special


 * [Me2Al(\m{2}Me)]2 gives [Me2Al(\m{2}Me)]2
 * ^{13}CO2 gives ^{13}CO2
 * ^{13}CO2 gives ^{13}CO2
 * \h{5}(C5H5)2TiCl2 gives \h{5}(C5H5)2TiCl2
 * \h{5}\s(C5H5) gives \h{5}\s(C5H5)
 * CH2\dCH2\sCH2\sC\tCH\qMn is CH2\dCH2\sCH2\sC\tCH\qMn


 * RC(OR’)3 gives RC(OR’)3
 * C\\C gives C\\C
 * C2*NH3 gives C2*NH3
 * C2*2NH3 gives C2*2NH3
 * C1.2H3.5 gives C1.2H3.5


 * 12 is 12
 * 12 is 12
 * CH3\i{13}CH2CH3 is CH3\i{13}CH2CH3
 * \{\{abc\}\} is \b\bAbC\e\e
 * C2(μ\-C) is C2(μ\-C)


 * SO4(2-) is SO4(2-)
 * 2Mn2(2+) is 2Mn2(2+)
 * CH3-CH2-OH is CH3-CH2-OH
 * [ZnCl4]- is [ZnCl4]-
 * [ZnCl4](2-) is [ZnCl4](2-)
 * AUTO: ((H2O)5{CoCl2})2 is ((H2O)5{CoCl2})2
 * Si(OH)4 is Si(OH)4


 * AUTO: Cu2C2*H2O is Cu2C2*H2O
 * Cu2C2*2H2O is Cu2C2*2H2O
 * CuSO*2H2O is CuSO*2H2O
 * CuSO4*15H2O is CuSO4*15H2O
 * CuSO4(H2O)5 is CuSO4(H2O)5
 * H+ + OH- → H2O is H+ + OH- → H2O
 * H → O is H → O


 * ZxPo4 is ZxPo4           Unknown element.
 * ((Na)Cl is ((Na)Cl         Too many "(".
 * Si(OH))4 is Si(OH))4        Too many ")".
 * Si&☃Si is Si&☃Si
 * CH2=CH2

/doc More

 * Cl2O6 is Cl2O6
 * [Fe(Phen)(Phen)3](2+) is [Fe(Phen)(Phen)3](2+)
 * AUTO: [Fe(Phen)(Phen)3](2+) is [Fe(Phen)(Phen)3](2+)
 * [C2O2](2+) is [C2O2](2+)
 * SI4 is SI4
 * H2SO4+ is H2SO4+
 * Mn- is Mn-
 * Mn22+ is Mn22+, Mn22- is Mn22-,
 * Mn(2+) is Mn(2+)
 * Mn2(+) is Mn2(+)
 * Mn(22-) is Mn(22-)
 * Mn3(22-) is Mn3(22-)
 * Mn(22+) is Mn(22+)
 * Mn2(22+) is Mn2(22+)
 * Mn2(2+) is Mn2(2+)
 * Mn22(2+) is Mn22(2+)

autodoc

 * &rarr;
 * Adds sections:

=== Elements and element-style symbols === === Groups ===

(start of autodoc)

(end of autodoc)