@@ -4321,11 +4321,15 @@ function test_wiki() {
43214321 wikitext = "'''b''bi'''"; parsed = CeL.wiki.parser(wikitext).parse();
43224322 assert([wikitext, parsed.toString()]);
43234323 assert(['bold', parsed[0].type], "''' bold '''");
4324- // '''''t ''''' → <i><b>t </b></i>
4324+ // '''''ib ''''' → <i><b>ib </b></i>
43254325 wikitext = "'''''Italic and bold formatting'''''"; parsed = CeL.wiki.parser(wikitext).parse();
43264326 assert([wikitext, parsed.toString()]);
4327- assert(['italic', parsed[0].type], "'''''t ''''' will render as <i><b>t </b></i>");
4327+ assert(['italic', parsed[0].type], "'''''ib ''''' will render as <i><b>ib </b></i>");
43284328 assert(['bold', parsed[0][1].type]);
4329+ // '''''bi''b''' → <b><i>bi</i>b</b>
4330+ wikitext = "'''''bi''b'''"; parsed = CeL.wiki.parser(wikitext).parse();
4331+ assert([wikitext, parsed.toString()]);
4332+ assert(['bold', parsed[0].type], "'''''bi''b''' will render as <b><i>bi</i>b</b>");
43294333 wikitext = "''Italic'''Italic and bold formatting'''Italic''"; parsed = CeL.wiki.parser(wikitext).parse();
43304334 assert([wikitext, parsed.toString()]);
43314335 assert(['italic', parsed[0].type], "'' '''t''' '' will render as <i><b>t</b></i>");
@@ -5807,10 +5811,39 @@ function test_wiki() {
58075811 var test_name = 'enwiki: expand_transclusion';
58085812 _setup_test(test_name);
58095813
5814+ var options = CeL.wiki.add_session_to_options(enwiki, { on_page_title: 'ABC', allow_promise: true });
58105815 var promise = Promise.resolve();
58115816
58125817 promise = promise.then(function () {
5813- var options = CeL.wiki.add_session_to_options(enwiki, { on_page_title: 'ABC', allow_promise: true });
5818+ return Promise.all([
5819+ '{{Ifsubst|yes|no}}',
5820+ '{{issubst}}'
5821+ ].map(function (wikitext) {
5822+ return CeL.wiki.expand_transclusion(wikitext, options);
5823+ }));
5824+ }).then(function (results) {
5825+ //console.trace(results);
5826+ var i = 0;
5827+ assert(['no', results[i++].toString()], test_name + ': CeL.wiki.expand_transclusion( {{Ifsubst}} )');
5828+ assert(['', results[i++].toString()], test_name + ': CeL.wiki.expand_transclusion( {{issubst}} )');
5829+
5830+
5831+ // https://zh.wikipedia.org/wiki/Special:ApiSandbox#action=expandtemplates&format=json&text=%7B%7BIfsubst%7Cyes%7Cno%7D%7D&formatversion=2
5832+ var parsed = CeL.wiki.expand_transclusion('{{safesubst:Ifsubst|yes1|no1}}', options);
5833+ assert(['no1', parsed.toString()], test_name + ': CeL.wiki.expand_transclusion( {{safesubst:Ifsubst}} )');
5834+
5835+ var PST_options = Object.assign({ mode: 'PST' }, options);
5836+ parsed = CeL.wiki.expand_transclusion('{{safesubst:Ifsubst|yes2|no2}}', PST_options);
5837+ assert(['yes2', parsed.toString()], test_name + ': CeL.wiki.expand_transclusion( {{safesubst:Ifsubst}}, mode: PST )');
5838+
5839+ parsed = CeL.wiki.expand_transclusion('{{safesubst:issubst}}', options);
5840+ assert(['', parsed.toString()], test_name + ': CeL.wiki.expand_transclusion( {{safesubst:issubst}} )');
5841+
5842+ parsed = CeL.wiki.expand_transclusion('{{safesubst:issubst}}', PST_options);
5843+ assert(['yes', parsed.toString()], test_name + ': CeL.wiki.expand_transclusion( {{safesubst:issubst}}, mode: PST )');
5844+ });
5845+
5846+ promise = promise.then(function () {
58145847 return Promise.all([
58155848 '{{w|ABC}}{{w|ABC|DEF}}',
58165849 '{{str right |Lorem ipsum dolor sit amet |10}}',
@@ -6132,45 +6165,48 @@ function test_wiki() {
61326165 var promise = Promise.resolve();
61336166
61346167 promise = promise.then(function () {
6135- return CeL.wiki.expand_transclusion('{{Ifsubst|yes|no}}', options);
6136- }).then(function (parsed) {
6137- //console.trace(parsed);
6138- assert(['no', parsed.toString()], 'CeL.wiki.expand_transclusion( {{Ifsubst}} )');
6139- });
6168+ return Promise.all([
6169+ '{{Ifsubst|yes|no}}',
6170+ '{{issubst}}'
6171+ ].map(function (wikitext) {
6172+ return CeL.wiki.expand_transclusion(wikitext, options);
6173+ }));
6174+ }).then(function (results) {
6175+ //console.trace(results);
6176+ var i = 0;
6177+ assert(['no', results[i++].toString()], test_name + ': CeL.wiki.expand_transclusion( {{Ifsubst}} )');
6178+ assert(['', results[i++].toString()], test_name + ': CeL.wiki.expand_transclusion( {{issubst}} )');
6179+
61406180
6141- promise = promise.then(function () {
61426181 // https://zh.wikipedia.org/wiki/Special:ApiSandbox#action=expandtemplates&format=json&text=%7B%7BIfsubst%7Cyes%7Cno%7D%7D&formatversion=2
6143- return CeL.wiki.expand_transclusion('{{safesubst:Ifsubst|yes|no}}', options);
6144- }).then(function (parsed) {
6145- //console.trace(parsed);
6146- assert(['no', parsed.toString()], 'CeL.wiki.expand_transclusion( {{safesubst:Ifsubst}} )');
6147- });
6182+ var parsed = CeL.wiki.expand_transclusion('{{safesubst:Ifsubst|yes1|no1}}', options);
6183+ assert(['no1', parsed.toString()], test_name + ': CeL.wiki.expand_transclusion( {{safesubst:Ifsubst}} )');
61486184
6149- promise = promise.then(function () {
6150- var _options = Object.assign({ mode: 'PST' }, options);
6151- return CeL.wiki.expand_transclusion('{{safesubst:Ifsubst|yes|no}}', _options);
6152- }).then(function (parsed) {
6153- //console.trace(parsed);
6154- assert(['yes', parsed.toString()], 'CeL.wiki.expand_transclusion( {{safesubst:Ifsubst}}, mode: PST )');
6155- });
6185+ var PST_options = Object.assign({ mode: 'PST' }, options);
6186+ parsed = CeL.wiki.expand_transclusion('{{safesubst:Ifsubst|yes2|no2}}', PST_options);
6187+ assert(['yes2', parsed.toString()], test_name + ': CeL.wiki.expand_transclusion( {{safesubst:Ifsubst}}, mode: PST )');
61566188
6157- promise = promise.then(function () {
6158- return CeL.wiki.expand_transclusion('{{a|條目|顯示文字|name=錨點名稱}}', options);
6159- }).then(function (parsed) {
6160- //console.trace(parsed);
6161- assert(['<span id="錨點名稱"></span>[[條目|顯示文字]]', parsed.toString()], 'CeL.wiki.expand_transclusion() using wiki.template_functions: {{a}}');
6162- });
6189+ parsed = CeL.wiki.expand_transclusion('{{safesubst:issubst}}', options);
6190+ assert(['', parsed.toString()], test_name + ': CeL.wiki.expand_transclusion( {{safesubst:issubst}} )');
61636191
6164- promise = promise.then(function () {
6165- return CeL.wiki.expand_transclusion('{{Kai|指引}}改为{{Kai|论述}}', options);
6166- }).then(function (parsed) {
6167- assert(['<templatestyles src="Template:楷體/styles.css" /><span class="template-kai">指引</span>改为<templatestyles src="Template:楷體/styles.css" /><span class="template-kai">论述</span>', parsed.toString()], 'CeL.wiki.expand_transclusion() fetch page #1');
6192+ parsed = CeL.wiki.expand_transclusion('{{safesubst:issubst}}', PST_options);
6193+ assert(['yes', parsed.toString()], test_name + ': CeL.wiki.expand_transclusion( {{safesubst:issubst}}, mode: PST )');
61686194 });
61696195
61706196 promise = promise.then(function () {
6171- return CeL.wiki.expand_transclusion('{{U|user}}\n', options);
6172- }).then(function (parsed) {
6173- assert(['[[User:user|user]]\n', parsed.toString()], 'CeL.wiki.expand_transclusion() fetch page #2');
6197+ return Promise.all([
6198+ '{{a|條目|顯示文字|name=錨點名稱}}',
6199+ '{{Kai|指引}}改为{{Kai|论述}}',
6200+ '{{U|user}}\n'
6201+ ].map(function (wikitext) {
6202+ return CeL.wiki.expand_transclusion(wikitext, options);
6203+ }));
6204+ }).then(function (results) {
6205+ //console.trace(results);
6206+ var i = 0;
6207+ assert(['<span id="錨點名稱"></span>[[條目|顯示文字]]', results[i++].toString()], 'CeL.wiki.expand_transclusion() using wiki.template_functions: {{a}}');
6208+ assert(['<templatestyles src="Template:楷體/styles.css" /><span class="template-kai">指引</span>改为<templatestyles src="Template:楷體/styles.css" /><span class="template-kai">论述</span>', results[i++].toString()], 'CeL.wiki.expand_transclusion() fetch page #1');
6209+ assert(['[[User:user|user]]\n', results[i++].toString()], 'CeL.wiki.expand_transclusion() fetch page #2');
61746210 });
61756211
61766212 promise = promise.then(function () {
@@ -6268,7 +6304,7 @@ function test_wiki() {
62686304 });
62696305
62706306 promise = promise.then(function () {
6271- var _options = Object.assign({}, options);
6307+ var _options = Object.assign({ mode: 'PST' }, options);
62726308 _options.max_template_depth = 1;
62736309 return CeL.wiki.expand_transclusion('{{subst:subst test 1}}', _options);
62746310 }).then(function (parsed) {
0 commit comments