2013-05-15 20:45:14 +00:00
|
|
|
/*!
|
2013-06-11 19:16:04 +00:00
|
|
|
* VisualEditor DataModel MWTransclusionNode tests.
|
2013-05-15 20:45:14 +00:00
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2013-05-15 20:45:14 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2021-08-25 08:31:34 +00:00
|
|
|
QUnit.module( 've.dm.MWTransclusionNode' );
|
2013-05-15 20:45:14 +00:00
|
|
|
|
|
|
|
/* Tests */
|
|
|
|
|
2021-04-30 09:33:22 +00:00
|
|
|
QUnit.test( 'getWikitext', ( assert ) => {
|
2021-04-29 14:42:18 +00:00
|
|
|
const cases = [
|
2013-05-15 20:45:14 +00:00
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
msg: 'mix of numbered and named parameters',
|
|
|
|
mw: {
|
|
|
|
target: { wt: 'foo' },
|
|
|
|
params: {
|
|
|
|
1: { wt: 'bar' },
|
|
|
|
baz: { wt: 'quux' }
|
2013-05-15 20:45:14 +00:00
|
|
|
}
|
|
|
|
},
|
2014-08-22 20:50:48 +00:00
|
|
|
wikitext: '{{foo|1=bar|baz=quux}}'
|
2013-05-15 20:45:14 +00:00
|
|
|
},
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
msg: 'parameter with self-closing nowiki',
|
|
|
|
mw: {
|
|
|
|
target: { wt: 'foo' },
|
|
|
|
params: {
|
|
|
|
bar: { wt: 'l\'<nowiki />\'\'\'Étranger\'\'\'' }
|
2013-05-15 20:45:14 +00:00
|
|
|
}
|
|
|
|
},
|
2014-08-22 20:50:48 +00:00
|
|
|
wikitext: '{{foo|bar=l\'<nowiki />\'\'\'Étranger\'\'\'}}'
|
2013-05-15 20:45:14 +00:00
|
|
|
},
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
msg: 'parameter with self-closing nowiki without space',
|
|
|
|
mw: {
|
|
|
|
target: { wt: 'foo' },
|
|
|
|
params: {
|
|
|
|
bar: { wt: 'l\'<nowiki/>\'\'\'Étranger\'\'\'' }
|
2013-05-15 20:45:14 +00:00
|
|
|
}
|
|
|
|
},
|
2014-08-22 20:50:48 +00:00
|
|
|
wikitext: '{{foo|bar=l\'<nowiki/>\'\'\'Étranger\'\'\'}}'
|
2013-05-15 20:45:14 +00:00
|
|
|
},
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
msg: 'parameter with spanning-nowiki',
|
|
|
|
mw: {
|
|
|
|
target: { wt: 'foo' },
|
|
|
|
params: {
|
|
|
|
bar: { wt: 'You should use <nowiki>\'\'\'</nowiki> to make things bold.' }
|
2013-05-15 20:45:14 +00:00
|
|
|
}
|
|
|
|
},
|
2014-08-22 20:50:48 +00:00
|
|
|
wikitext: '{{foo|bar=You should use <nowiki>\'\'\'</nowiki> to make things bold.}}'
|
2013-05-15 20:45:14 +00:00
|
|
|
},
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
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!' }
|
2013-05-15 20:45:14 +00:00
|
|
|
}
|
|
|
|
},
|
2014-08-22 20:50:48 +00:00
|
|
|
wikitext: '{{foo|bar=You should try using <nowiki>{{ping|foo=bar|2=1}}</nowiki> as a transclusion!}}'
|
2013-06-27 19:12:44 +00:00
|
|
|
},
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
msg: 'parameter containing another template invocation',
|
|
|
|
mw: {
|
|
|
|
target: { wt: 'foo' },
|
|
|
|
params: {
|
|
|
|
bar: { wt: '{{ping|foo=bar|2=1}}' }
|
2013-06-27 19:12:44 +00:00
|
|
|
}
|
|
|
|
},
|
2014-08-22 20:50:48 +00:00
|
|
|
wikitext: '{{foo|bar={{ping|foo=bar|2=1}}}}'
|
2013-06-27 19:12:44 +00:00
|
|
|
},
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
msg: 'parameter containing another parameter',
|
|
|
|
mw: {
|
|
|
|
target: { wt: 'foo' },
|
|
|
|
params: {
|
|
|
|
bar: { wt: '{{{1}}}' }
|
2013-06-27 19:12:44 +00:00
|
|
|
}
|
|
|
|
},
|
2014-08-22 20:50:48 +00:00
|
|
|
wikitext: '{{foo|bar={{{1}}}}}'
|
2013-06-27 19:12:44 +00:00
|
|
|
},
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
msg: 'parameter containing unmatched close brackets and floating pipes',
|
|
|
|
mw: {
|
|
|
|
target: { wt: 'foo' },
|
|
|
|
params: {
|
|
|
|
bar: { wt: '}} | {{a|{{b}}}} |' }
|
2013-06-27 19:12:44 +00:00
|
|
|
}
|
|
|
|
},
|
2014-08-22 20:50:48 +00:00
|
|
|
wikitext: '{{foo|bar=<nowiki>}}</nowiki> <nowiki>|</nowiki> {{a|{{b}}}} <nowiki>|</nowiki>}}'
|
2013-07-11 14:45:18 +00:00
|
|
|
},
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
msg: 'parameter containing piped link',
|
|
|
|
mw: {
|
|
|
|
target: { wt: 'foo' },
|
|
|
|
params: {
|
|
|
|
bar: { wt: '[[baz|quux]]' }
|
2013-07-11 14:45:18 +00:00
|
|
|
}
|
|
|
|
},
|
2014-08-22 20:50:48 +00:00
|
|
|
wikitext: '{{foo|bar=[[baz|quux]]}}'
|
2016-10-28 00:22:30 +00:00
|
|
|
} ];
|
2017-04-28 15:48:52 +00:00
|
|
|
|
2024-05-01 13:02:29 +00:00
|
|
|
cases.forEach( ( caseItem ) => {
|
2021-04-29 14:42:18 +00:00
|
|
|
const node = new ve.dm.MWTransclusionNode(
|
2024-05-01 13:02:29 +00:00
|
|
|
{ type: 'mwTransclusion', attributes: { mw: caseItem.mw } }
|
2013-05-15 20:45:14 +00:00
|
|
|
);
|
2024-05-01 13:02:29 +00:00
|
|
|
assert.strictEqual( node.getWikitext(), caseItem.wikitext, caseItem.msg );
|
|
|
|
} );
|
2013-05-15 20:45:14 +00:00
|
|
|
} );
|