Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/tests/dm/nodes/ve.dm.MWTransclusionNode.test.js

raw symbols SCIP
1 /*!
2 * VisualEditor DataModel MWTransclusionNode tests.
3 *
4 * @copyright See AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7
8 QUnit.module( 've.dm.MWTransclusionNode' );
9
10 QUnit.test.each( 'getWikitext', {
11 'mix of numbered and named parameters': {
12 mw: {
13 target: { wt: 'foo' },
14 params: {
15 1: { wt: 'bar' },
16 baz: { wt: 'quux' }
17 }
18 },
19 wikitext: '{{foo|1=bar|baz=quux}}'
20 },
21 'parameter with self-closing nowiki': {
22 mw: {
23 target: { wt: 'foo' },
24 params: {
25 bar: { wt: 'l\'<nowiki />\'\'\'Étranger\'\'\'' }
26 }
27 },
28 wikitext: '{{foo|bar=l\'<nowiki />\'\'\'Étranger\'\'\'}}'
29 },
30 'parameter with self-closing nowiki without space': {
31 mw: {
32 target: { wt: 'foo' },
33 params: {
34 bar: { wt: 'l\'<nowiki/>\'\'\'Étranger\'\'\'' }
35 }
36 },
37 wikitext: '{{foo|bar=l\'<nowiki/>\'\'\'Étranger\'\'\'}}'
38 },
39 'parameter with spanning-nowiki': {
40 mw: {
41 target: { wt: 'foo' },
42 params: {
43 bar: { wt: 'You should use <nowiki>\'\'\'</nowiki> to make things bold.' }
44 }
45 },
46 wikitext: '{{foo|bar=You should use <nowiki>\'\'\'</nowiki> to make things bold.}}'
47 },
48 'parameter with spanning-nowiki and nested transclusion': {
49 mw: {
50 target: { wt: 'foo' },
51 params: {
52 bar: { wt: 'You should try using <nowiki>{{ping|foo=bar|2=1}}</nowiki> as a transclusion!' }
53 }
54 },
55 wikitext: '{{foo|bar=You should try using <nowiki>{{ping|foo=bar|2=1}}</nowiki> as a transclusion!}}'
56 },
57 'parameter containing another template invocation': {
58 mw: {
59 target: { wt: 'foo' },
60 params: {
61 bar: { wt: '{{ping|foo=bar|2=1}}' }
62 }
63 },
64 wikitext: '{{foo|bar={{ping|foo=bar|2=1}}}}'
65 },
66 'parameter containing another parameter': {
67 mw: {
68 target: { wt: 'foo' },
69 params: {
70 bar: { wt: '{{{1}}}' }
71 }
72 },
73 wikitext: '{{foo|bar={{{1}}}}}'
74 },
75 'parameter containing unmatched close brackets and floating pipes': {
76 mw: {
77 target: { wt: 'foo' },
78 params: {
79 bar: { wt: '}} | {{a|{{b}}}} |' }
80 }
81 },
82 wikitext: '{{foo|bar=<nowiki>}}</nowiki> <nowiki>|</nowiki> {{a|{{b}}}} <nowiki>|</nowiki>}}'
83 },
84 'parameter containing piped link': {
85 mw: {
86 target: { wt: 'foo' },
87 params: {
88 bar: { wt: '[[baz|quux]]' }
89 }
90 },
91 wikitext: '{{foo|bar=[[baz|quux]]}}'
92 }
93 }, ( assert, caseItem ) => {
94 const node = new ve.dm.MWTransclusionNode(
95 { type: 'mwTransclusion', attributes: { mw: caseItem.mw } }
96 );
97 assert.strictEqual( node.getWikitext(), caseItem.wikitext );
98 }
99 );