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
|
|
|
*
|
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2013-06-11 19:16:04 +00:00
|
|
|
QUnit.module( 've.dm.MWTransclusionNode' );
|
2013-05-15 20:45:14 +00:00
|
|
|
|
|
|
|
/* 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.}}'
|
|
|
|
},
|
|
|
|
{
|
2013-06-11 19:16:04 +00:00
|
|
|
'msg': 'parameter with spanning-nowiki and nested transclusion',
|
2013-05-15 20:45:14 +00:00
|
|
|
'mw': {
|
|
|
|
'target': { 'wt': 'foo' },
|
|
|
|
'params': {
|
2013-06-11 19:16:04 +00:00
|
|
|
'bar': { 'wt': 'You should try using <nowiki>{{ping|foo=bar|2=1}}</nowiki> as a transclusion!' }
|
2013-05-15 20:45:14 +00:00
|
|
|
}
|
|
|
|
},
|
2013-06-11 19:16:04 +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
|
|
|
},
|
|
|
|
{
|
|
|
|
'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': {
|
2013-07-11 14:45:18 +00:00
|
|
|
'bar': { 'wt': '}} | {{a|{{b}}}} |' }
|
2013-06-27 19:12:44 +00:00
|
|
|
}
|
|
|
|
},
|
2013-07-11 14:45:18 +00:00
|
|
|
'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]]}}'
|
2013-06-05 10:47:47 +00:00
|
|
|
}
|
2013-05-15 20:45:14 +00:00
|
|
|
];
|
|
|
|
QUnit.expect( cases.length );
|
|
|
|
for ( i = 0; i < cases.length; i++ ) {
|
2013-06-11 19:16:04 +00:00
|
|
|
node = new ve.dm.MWTransclusionNode( 0,
|
|
|
|
{ 'type': 'mwTransclusion', 'attributes': { 'mw': cases[i].mw } }
|
2013-05-15 20:45:14 +00:00
|
|
|
);
|
|
|
|
assert.deepEqual( node.getWikitext(), cases[i].wikitext, cases[i].msg );
|
|
|
|
}
|
|
|
|
} );
|