/** * MediaWiki CodeMirror tests. */ ( function () { /** * Keys are the titles of the test cases. Each has an 'input' and the expected 'output'. * * @type {Object} */ const config = mw.config.get( 'extCodeMirrorConfig' ), extCiteLoaded = config.tagModes.ref, testCases = [ { title: 'p tags, extra closing tag', input: 'this is

content

', output: '
this is <p><div>content</p></p>
' }, { title: 'HTML tag attributes', input: '', output: '
<span title="a<b"><b title="a>b"></b></span>
' }, { title: 'ref tag attributes', input: '', output: extCiteLoaded ? '
<ref name="a<b"/>
' : '
<ref name="a<b"/>
' }, { title: 'indented table with caption and inline headings', input: ' ::{| class="wikitable"\n |+ Caption\n |-\n ! Uno !! Dos\n |-\n | Foo || Bar\n |}', output: '
 ::{| class="wikitable"
 |+ Caption
 |-
 ! Uno !! Dos
 |-
 | Foo || Bar
 |}
' }, { title: 'apostrophe before italic', input: 'plain l\'\'\'italic\'\'plain', output: '
plain l\'\'\'italic\'\'plain
' }, { title: 'free external links', input: 'https://wikimedia.org [ftp://foo.bar FOO] //archive.org', output: '
https://wikimedia.org [ftp://foo.bar FOO] //archive.org
' }, { title: 'void tags', input: 'a
b
c a
b
c
d', output: '
a<br>b</br>c a<div>b<br>c</div>d
' }, { title: 'magic words', input: '__NOTOC__', output: '
__NOTOC__
' }, { title: 'nowiki', input: '{{foo}}

{{{', output: '
<nowiki>{{foo}}<p> </div> {{{</nowiki>
' }, { title: 'ref tag with cite web, extraneous curly braces', input: '{{cite web|2=foo}}}}', output: extCiteLoaded ? '
<ref>{{cite web|2=foo}}}}</ref>
' : '
<ref>{{cite web|2=foo}}}}</ref>
' }, { title: 'template with params and parser function', input: '{{foo|1=bar|2={{{param|blah}}}|{{#if:{{{3|}}}|yes|no}}}}', output: '
{{foo|1=bar|2={{{param|blah}}}|{{#if:{{{3|}}}|yes|no}}}}
' }, { title: 'T277767: newlines and comments in template names', input: '{{#if: | {{some template\n }} }}', output: '
{{#if: | {{some template
<!-- comment --> }} }}
' }, { title: 'T108450: template transclusion where the template name is a parameter', input: '{{{{{1}}}|…}}', output: '
{{{{{1}}}|}}
' }, { title: 'T292967: table syntax where all | are escaped with the {{!}} parser function', input: '{{{!}} class="wikitable"\n! header\n{{!}}-\n{{!}} cell\n{{!}}}', output: '
{{{!}} class="wikitable"
! header
{{!}}-
{{!}} cell
{{!}}}
' }, { title: 'section headings', input: '== My section ==\nFoo bar\n=== Blah ===\nBaz\n= { =\nText', output: '
== My section ==
Foo bar
=== Blah ===
Baz
= { =
Text
' }, { title: 'section headings with trailing comments', input: '== My section == \nFoo bar\n=== Blah ===\nBaz\n== a == ', output: '
== My section == <!-- comment --> 
Foo bar
=== Blah ===<!--comment-->
Baz
== <i>a</i> <!-- comment --> == <!--comment-->
' }, { title: 'bullets and numbering, with invalid leading spacing', input: '* bullet A\n* bullet B\n# one\n # two', output: '
* bullet A
* bullet B
# one
 # two
' }, { title: 'link with bold text', input: '[[Link title|\'\'\'bold link\'\'\']]', output: '
[[Link title|\'\'\'bold link\'\'\']]
' }, { title: 'horizontal rule', input: 'One\n----\nTwo', output: '
One
----
Two
' }, { title: 'comments', input: '', output: '
<!-- foo [[bar]] {{{param}}} -->
' }, { title: 'signatures', input: 'my sig ~~~ ~~~~ ~~~~~~~', output: '
my sig ~~~ ~~~~ ~~~~~~~
' }, { title: 'new', input: '', output: extCiteLoaded ? '
<ref></Ref>
' : '
<ref></Ref>
' }, { title: 'multi-line tag', input: 'bar', output: '
<div
id="foo"
>bar</div>
' } ]; QUnit.module( 'ext.CodeMirror.mediawiki.test', QUnit.newMwEnvironment() ); /** * For some reason in QUnit we have to make the textarea, and supply it with the * wikitext prior to initializing CodeMirror. So this function will do this and * destroy CodeMirror after the test has completed, so that we have a clean slate * for the next iteration. * * @param {string} wikitext * @param {Function} callback Ran after CodeMirror has been initialized. */ function setup( wikitext, callback ) { const $textarea = $( '