mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-26 04:53:04 +00:00
b7f92605b2
Change-Id: I7b56bc7a9a69f64073ab97bdb1911d17b328b8b8
114 lines
2.7 KiB
JavaScript
114 lines
2.7 KiB
JavaScript
/*!
|
|
* VisualEditor DataModel MWTransclusionNode tests.
|
|
*
|
|
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
QUnit.module( 've.dm.MWTransclusionNode', ve.test.utils.mwEnvironment );
|
|
|
|
/* Tests */
|
|
|
|
QUnit.test( 'getWikitext', function ( assert ) {
|
|
var i, node, cases = [
|
|
{
|
|
msg: 'mix of numbered and named parameters',
|
|
mw: {
|
|
target: { wt: 'foo' },
|
|
params: {
|
|
1: { wt: 'bar' },
|
|
baz: { wt: 'quux' }
|
|
}
|
|
},
|
|
wikitext: '{{foo|1=bar|baz=quux}}'
|
|
},
|
|
{
|
|
msg: 'parameter with self-closing nowiki',
|
|
mw: {
|
|
target: { wt: 'foo' },
|
|
params: {
|
|
bar: { wt: 'l\'<nowiki />\'\'\'Étranger\'\'\'' }
|
|
}
|
|
},
|
|
wikitext: '{{foo|bar=l\'<nowiki />\'\'\'Étranger\'\'\'}}'
|
|
},
|
|
{
|
|
msg: 'parameter with self-closing nowiki without space',
|
|
mw: {
|
|
target: { wt: 'foo' },
|
|
params: {
|
|
bar: { wt: 'l\'<nowiki/>\'\'\'Étranger\'\'\'' }
|
|
}
|
|
},
|
|
wikitext: '{{foo|bar=l\'<nowiki/>\'\'\'Étranger\'\'\'}}'
|
|
},
|
|
{
|
|
msg: 'parameter with spanning-nowiki',
|
|
mw: {
|
|
target: { wt: 'foo' },
|
|
params: {
|
|
bar: { wt: 'You should use <nowiki>\'\'\'</nowiki> to make things bold.' }
|
|
}
|
|
},
|
|
wikitext: '{{foo|bar=You should use <nowiki>\'\'\'</nowiki> to make things bold.}}'
|
|
},
|
|
{
|
|
msg: 'parameter with spanning-nowiki and nested transclusion',
|
|
mw: {
|
|
target: { wt: 'foo' },
|
|
params: {
|
|
bar: { wt: 'You should try using <nowiki>{{ping|foo=bar|2=1}}</nowiki> as a transclusion!' }
|
|
}
|
|
},
|
|
wikitext: '{{foo|bar=You should try using <nowiki>{{ping|foo=bar|2=1}}</nowiki> as a transclusion!}}'
|
|
},
|
|
{
|
|
msg: 'parameter containing another template invocation',
|
|
mw: {
|
|
target: { wt: 'foo' },
|
|
params: {
|
|
bar: { wt: '{{ping|foo=bar|2=1}}' }
|
|
}
|
|
},
|
|
wikitext: '{{foo|bar={{ping|foo=bar|2=1}}}}'
|
|
},
|
|
{
|
|
msg: 'parameter containing another parameter',
|
|
mw: {
|
|
target: { wt: 'foo' },
|
|
params: {
|
|
bar: { wt: '{{{1}}}' }
|
|
}
|
|
},
|
|
wikitext: '{{foo|bar={{{1}}}}}'
|
|
},
|
|
{
|
|
msg: 'parameter containing unmatched close brackets and floating pipes',
|
|
mw: {
|
|
target: { wt: 'foo' },
|
|
params: {
|
|
bar: { wt: '}} | {{a|{{b}}}} |' }
|
|
}
|
|
},
|
|
wikitext: '{{foo|bar=<nowiki>}}</nowiki> <nowiki>|</nowiki> {{a|{{b}}}} <nowiki>|</nowiki>}}'
|
|
},
|
|
{
|
|
msg: 'parameter containing piped link',
|
|
mw: {
|
|
target: { wt: 'foo' },
|
|
params: {
|
|
bar: { wt: '[[baz|quux]]' }
|
|
}
|
|
},
|
|
wikitext: '{{foo|bar=[[baz|quux]]}}'
|
|
}
|
|
];
|
|
QUnit.expect( cases.length );
|
|
for ( i = 0; i < cases.length; i++ ) {
|
|
node = new ve.dm.MWTransclusionNode(
|
|
{ type: 'mwTransclusion', attributes: { mw: cases[i].mw } }
|
|
);
|
|
assert.deepEqual( node.getWikitext(), cases[i].wikitext, cases[i].msg );
|
|
}
|
|
} );
|