User:Evad37/extra/test.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:Evad37/extra/test. |
/***************************************************************************************************
ExtraJS testcases --- by Evad37
> These tests are run automatically on extraJs script pages when this script is installed.
***************************************************************************************************/
/* jshint esversion: 6, laxbreak: true, undef: true, maxerr:999 */
/* globals window, mw, $, QUnit, extraJs */
// <nowiki>
/* ========== Set up ============================================================================ */
if (
mw.config.get('wgPageName').includes('User:Evad37/extra') &&
mw.config.get('wgPageContentModel') === 'javascript' &&
mw.config.get('wgAction') === 'view' &&
mw.config.get('wgDiffOldId') === null
) {
var init = function() {
var rawUrl = function(page) {
var ctype = /\.css$/.test(page) ? 'text/css' : 'text/javascript';
return 'https://wiki.riteme.site/w/index.php?title=' + page.replace(/ /g, '_') +
'&action=raw&ctype=' + ctype;
};
// Create output div
var $output = $('<div>').attr('id', 'qunit').insertBefore('#firstHeading');
// Script version: use sandbox version, except on the main script page itself
var scriptPage = mw.config.get('wgPageName') === 'User:Evad37/extra.js'
? 'User:Evad37/extra.js'
: 'User:Evad37/extra/sandbox.js';
// Get that version of the script
mw.loader.getScript( rawUrl(scriptPage) ).then(function() {
// Load QUnit
mw.loader.load( rawUrl('User:Evad37/qunit-2.8.0.css'), 'text/css' );
$.getScript( rawUrl('User:Evad37/qunit-2.8.0.js'), function(){
// Note version of script being tested
$('<strong>').append([
'Testing version ' + extraJs.version + ' (',
$(scriptPage === mw.config.get('wgPageName') ? '<span>' : '<a>')
.attr('href', 'https://wiki.riteme.site/wiki/'+scriptPage)
.text(scriptPage),
'):'
]).insertBefore( $output );
/* ========== Data to use in tests ============================================================== */
var original = "[[Lorem]] ipsum [[dolor]] sit amet, consectetur adipiscing elit, sed do eiusmod "+
"tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud "+
"exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure "+
"[[dolor]]s in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. "+
"Excepteur sint occaecat cupidatat non proident, sunt in culpa qui [[lorem|officia]] deserunt "+
"mollit anim id est laborum.";
var listItems = "*[[Lorem]]\n*ipsum [[dolor]]\n*[[sit]] [[amet]]\n*[[consectetur]]";
var file1 = "{{Infobox ipsum\n|image1=File:Foobar.png\n|image2=Foobar.png\n|param=value}}";
var file2 = "[[File:Foobar.png|thumb|right|200px|caption]]";
var file3 = "<gallery>\nFile:Foobar.png|caption\nFile:Otherimage.jpg|Othercaption\n</gallery>";
var portal1 = "{{Portal|Foo|Bar}}";
var portal2 = "{{portal|Foo}}";
var portal3 = "Lorem ipsum.\n\n==See also==\n*{{Portal-inline|Foo}}\n*{{Portal-inline|Bar}}\n\n==External links==";
var portal4 = "Lorem ipsum.\n\n==See also==\n*{{Portal-inline|Foo}}\n\n==External links==";
var portal5 = "{{Portal bar|Foo|Bar}}";
var portal6 = "{{Portal bar|Foo}}";
var portal7 = "{{Subject bar |portal= Foo |portal2= Primates "+
"|s= y |s-search= Author:William Charles Osman Hill |v= y }}";
// Per [[Special:Diff/894178603]]
var portal8 = '=== Section ===\nLorem ipsum.{{Portal|Hip hop}}\n\n==References==';
var portal9 = '=== Section ===\n{{Portal|Hip hop}}\nLorem ipsum.\n\n==References==';
// Per [[Special:Diff/903501933]]
var portal10 = `{{Strategic Air Command}}
{{Subject bar
|portal1=United States Army
|portal2=United States Air Force
|portal3=World War I
|portal4=World War II
|commons=y
}}
{{good article}}`;
// ========== Test Module: extraJs.unlink ======================================================= */
QUnit.module('extraJs.unlink');
QUnit.test('Nothing to replace', function(assert) {
var unlinked = extraJs.unlink(original, ['Foo'], 0);
assert.equal(original, unlinked, 'No change');
});
QUnit.test('Simple and piped links', function(assert) {
var unlinked1 = extraJs.unlink(original, ['Lorem'], 0);
var expected1 = "Lorem ipsum [[dolor]] sit amet, consectetur adipiscing elit, sed do eiusmod "+
"tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud "+
"exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure "+
"[[dolor]]s in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. "+
"Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt "+
"mollit anim id est laborum.";
assert.equal(unlinked1, expected1, 'One page');
var unlinked2 = extraJs.unlink(original, ['Lorem', 'Dolor'], 0);
var expected2 = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod "+
"tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud "+
"exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure "+
"dolors in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. "+
"Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt "+
"mollit anim id est laborum.";
assert.equal(unlinked2, expected2, 'Two pages');
});
QUnit.test('List items', function(assert) {
var unlinked1 = extraJs.unlink(listItems, ['Lorem'], 0);
var expected1 = "{{subst:void}}*Lorem\n*ipsum [[dolor]]\n*[[sit]] [[amet]]\n*[[consectetur]]";
assert.equal(unlinked1, expected1, 'Single-link list item unlinked and marked for review');
var unlinked2 = extraJs.unlink(listItems, ['dolor'], 0);
var expected2 = "*[[Lorem]]\n{{subst:void}}*ipsum dolor\n*[[sit]] [[amet]]\n*[[consectetur]]";
assert.equal(unlinked2, expected2, 'Not single-link list item unlinked and marked for review');
var unlinked3 = extraJs.unlink("{{Navbox|list1=\n"+listItems+"}}", ['Lorem'], 10);
var expected3 = "{{Navbox|list1=\n*ipsum [[dolor]]\n*[[sit]] [[amet]]\n*[[consectetur]]}}";
assert.equal(unlinked3, expected3, 'Navbox list item removed');
var unlinked4 = extraJs.unlink(listItems, ['dolor'], 0, true);
var expected4 = "*[[Lorem]]\n*[[sit]] [[amet]]\n*[[consectetur]]";
assert.equal(unlinked4, expected4, 'Disambiguation item removed');
var unlinked5 = extraJs.unlink(listItems+"\n\n{{Given name}}", ['dolor'], 0);
var expected5 = "*[[Lorem]]\n*[[sit]] [[amet]]\n*[[consectetur]]\n\n{{Given name}}";
assert.equal(unlinked5, expected5, 'Set index article for names treated like disambiguation');
});
QUnit.test('Files', function(assert) {
var unlinked1 = extraJs.unlink(file1, ['File:Foobar.png'], 0);
var expected1 = "{{Infobox ipsum\n\n\n|param=value}}";
assert.equal(unlinked1, expected1, 'Infobox images');
var unlinked2 = extraJs.unlink(file2+"Lorem ipsum", ['File:Foobar.png'], 0);
var expected2 = "Lorem ipsum";
assert.equal(unlinked2, expected2, 'Normal image');
var unlinked3 = extraJs.unlink(file3, ['File:Foobar.png'], 0);
var expected3 = "<gallery>\n\nFile:Otherimage.jpg|Othercaption\n</gallery>";
assert.equal(unlinked3, expected3, 'Gallery image');
});
QUnit.test('Portals', function(assert) {
var unlinked1 = extraJs.unlink(portal1, ['Portal:Foo'], 0);
var expected1 = "{{Portal|Bar}}";
assert.equal(unlinked1, expected1, 'Multiple portals in {{Portal}}');
var unlinked2 = extraJs.unlink(portal2, ['Portal:Foo'], 0);
var expected2 = "";
assert.equal(unlinked2, expected2, 'Single portal in {{Portal}}');
var unlinked3 = extraJs.unlink(portal3, ['Portal:Foo'], 0);
var expected3 = "Lorem ipsum.\n\n==See also==\n*{{Portal-inline|Bar}}\n\n==External links==";
assert.equal(unlinked3, expected3, 'List with multiple {{Portal-inline}} templates');
var unlinked4 = extraJs.unlink(portal4, ['Portal:Foo'], 0);
var expected4 = "Lorem ipsum.\n\n==External links==";
assert.equal(unlinked4, expected4, 'List with single {{Portal-inline}} template');
var unlinked5 = extraJs.unlink(portal5, ['Portal:Foo'], 0);
var expected5 = "{{Portal bar|Bar}}";
assert.equal(unlinked5, expected5, 'Multiple portals in {{Portal bar}}');
var unlinked6 = extraJs.unlink(portal6, ['Portal:Foo'], 0);
var expected6 = "";
assert.equal(unlinked6, expected6, 'Single portal in {{Portal bar}}');
var unlinked7 = extraJs.unlink(portal7, ['Portal:Foo'], 0);
var expected7 = "{{Subject bar |portal2= Primates "+
"|s= y |s-search= Author:William Charles Osman Hill |v= y }}";
assert.equal(unlinked7, expected7, '{{Subject bar}}');
var unlinked8 = extraJs.unlink(portal8, ['Portal:Hip hop'], 0);
var expected8 = '=== Section ===\nLorem ipsum.\n\n==References==';
assert.equal(unlinked8, expected8, '{{Portal}} at end of a line');
var unlinked9 = extraJs.unlink(portal9, ['Portal:Hip hop'], 0);
var expected9 = '=== Section ===\nLorem ipsum.\n\n==References==';
assert.equal(unlinked9, expected9, '{{Portal}} on it\'s own line');
var unlinked10 = extraJs.unlink(portal10, ['Portal:United States Army'], 0);
var expected10 = `{{Strategic Air Command}}
{{Subject bar
|portal2=United States Air Force
|portal3=World War I
|portal4=World War II
|commons=y
}}
{{good article}}`;
assert.equal(unlinked10, expected10, '{{Subject bar}} per [[Special:Diff/903501933]]');
});
// ========== Test Module: extraJs.parseTemplates ======================================================= */
QUnit.module('extraJs.parseTemplates');
QUnit.test("Single template, no params", function(assert) {
var wikitext = "Lorem {{ipsum}} dorem";
var parsed = extraJs.parseTemplates(wikitext);
assert.equal(parsed.length, 1, "One template found");
assert.equal(parsed[0].name, "ipsum", "Correct name");
assert.equal(parsed[0].parameters.length, 0, "No parameters");
assert.equal(parsed[0].wikitext, "{{ipsum}}", "Correct wikitext");
});
QUnit.test("Two templates, no params", function(assert) {
var wikitext = "Lorem {{ipsum}} dorem {{sum}}";
var parsed = extraJs.parseTemplates(wikitext);
assert.equal(parsed.length, 2, "Two template found");
assert.equal(parsed[0].name, "ipsum", "First: Correct name");
assert.equal(parsed[0].parameters.length, 0, "First: No parameters");
assert.equal(parsed[0].wikitext, "{{ipsum}}", "First: Correct wikitext");
assert.equal(parsed[1].name, "sum", "First: Correct name");
assert.equal(parsed[1].parameters.length, 0, "First: No parameters");
assert.equal(parsed[1].wikitext, "{{sum}}", "First: Correct wikitext");
});
QUnit.test("Two nested templates, not recursive", function(assert) {
var wikitext = "Lorem {{ipsum|{{dorem}}}} sum";
var parsed = extraJs.parseTemplates(wikitext);
assert.equal(parsed.length, 1, "One template found");
assert.equal(parsed[0].name, "ipsum", "Correct name");
assert.equal(parsed[0].parameters.length, 1, "One parameter");
assert.equal(parsed[0].parameters[0].name, 1, "Correct parameter name");
assert.equal(parsed[0].parameters[0].value, "{{dorem}}", "Correct parameter value");
assert.equal(parsed[0].parameters[0].wikitext, "|{{dorem}}", "Correct parameter wikitext");
assert.equal(parsed[0].wikitext, "{{ipsum|{{dorem}}}}", "Correct wikitext");
});
QUnit.test("Two nested templates, recursive", function(assert) {
var wikitext = "Lorem {{ipsum|{{dorem}}}} sum";
var parsed = extraJs.parseTemplates(wikitext, true);
assert.equal(parsed.length, 2, "Two template found");
assert.equal(parsed[0].name, "ipsum", "Correct name");
assert.equal(parsed[0].parameters.length, 1, "One parameter");
assert.equal(parsed[0].parameters[0].name, 1, "Correct parameter name");
assert.equal(parsed[0].parameters[0].value, "{{dorem}}", "Correct parameter value");
assert.equal(parsed[0].parameters[0].wikitext, "|{{dorem}}", "Correct parameter wikitext");
assert.equal(parsed[0].wikitext, "{{ipsum|{{dorem}}}}", "Correct wikitext");
assert.equal(parsed[1].name, "dorem", "Correct name");
assert.equal(parsed[1].parameters.length, 0, "No parameters");
assert.equal(parsed[1].wikitext, "{{dorem}}", "Correct wikitext");
});
QUnit.test("More nested templates, recursive (Talk:Eleanor Robinson)", function(assert) {
var wikitext = `{{WikiProjectBannerShell|1=
{{WikiProject Biography
| living=yes
| class =C
| listas=Robinson, Eleanor
| sports-work-group = yes
| sports-priority =
| needs-photo = yes}}
{{WikiProject Athletics
|class=C
|importance=}}
{{WikiProject Running
|class=C
|importance=}}
{{WikiProject Women's sport
|class=C
|importance=}}
}}
{{DYK talk|31 January|2015|entry= ... that in 1998 '''[[Eleanor Robinson]]''' set a world record of 13 days, 1 hour, 54 minutes for a woman to run {{convert|1000|mi}}?}}
{{Did you know nominations/Eleanor Robinson}}`;
var parsed = extraJs.parseTemplates(wikitext, true);
assert.equal(parsed.length, 8, "Eight templates found");
assert.equal(parsed[0].name, "WikiProjectBannerShell", "First: Correct name");
assert.equal(parsed[0].parameters.length, 1, "First: One parameter");
assert.equal(parsed[0].parameters[0].name, "1", "First: Correct parameter name");
assert.equal(parsed[0].parameters[0].value, `{{WikiProject Biography
| living=yes
| class =C
| listas=Robinson, Eleanor
| sports-work-group = yes
| sports-priority =
| needs-photo = yes}}
{{WikiProject Athletics
|class=C
|importance=}}
{{WikiProject Running
|class=C
|importance=}}
{{WikiProject Women's sport
|class=C
|importance=}}`, "First: Correct parameter value");
assert.equal(parsed[0].parameters[0].wikitext, `|1=
{{WikiProject Biography
| living=yes
| class =C
| listas=Robinson, Eleanor
| sports-work-group = yes
| sports-priority =
| needs-photo = yes}}
{{WikiProject Athletics
|class=C
|importance=}}
{{WikiProject Running
|class=C
|importance=}}
{{WikiProject Women's sport
|class=C
|importance=}}
`, "First: Correct parameter wikitext");
assert.equal(parsed[0].wikitext, `{{WikiProjectBannerShell|1=
{{WikiProject Biography
| living=yes
| class =C
| listas=Robinson, Eleanor
| sports-work-group = yes
| sports-priority =
| needs-photo = yes}}
{{WikiProject Athletics
|class=C
|importance=}}
{{WikiProject Running
|class=C
|importance=}}
{{WikiProject Women's sport
|class=C
|importance=}}
}}`, "First: Correct wikitext");
});
QUnit.test("Unnamed parameter", function(assert) {
var wikitext = "Lorem {{ipsum|foo}} dorem";
var parsed = extraJs.parseTemplates(wikitext);
assert.equal(parsed.length, 1, "One template found");
assert.equal(parsed[0].name, "ipsum", "Correct name");
assert.equal(parsed[0].parameters.length, 1, "One parameter");
assert.equal(parsed[0].parameters[0].name, 1, "Correct parameter name");
assert.equal(parsed[0].parameters[0].value, "foo", "Correct parameter value");
assert.equal(parsed[0].parameters[0].wikitext, "|foo", "Correct parameter wikitext");
assert.equal(parsed[0].wikitext, "{{ipsum|foo}}", "Correct wikitext");
});
QUnit.test("Unnamed parameters", function(assert) {
var wikitext = "Lorem {{ipsum|foo|bar}} dorem";
var parsed = extraJs.parseTemplates(wikitext);
assert.equal(parsed.length, 1, "One template found");
assert.equal(parsed[0].name, "ipsum", "Correct name");
assert.equal(parsed[0].parameters.length, 2, "Two parameters");
assert.equal(parsed[0].parameters[0].name, 1, "Correct first parameter name");
assert.equal(parsed[0].parameters[0].value, "foo", "Correct first parameter value");
assert.equal(parsed[0].parameters[0].wikitext, "|foo", "Correct first parameter wikitext");
assert.equal(parsed[0].parameters[1].name, 2, "Correct second parameter name");
assert.equal(parsed[0].parameters[1].value, "bar", "Correct second parameter value");
assert.equal(parsed[0].parameters[1].wikitext, "|bar", "Correct second parameter wikitext");
assert.equal(parsed[0].wikitext, "{{ipsum|foo|bar}}", "Correct wikitext");
});
QUnit.test("Numbered parameters", function(assert) {
var wikitext = "Lorem {{ipsum|2=foo|3=bar}} dorem";
var parsed = extraJs.parseTemplates(wikitext);
assert.equal(parsed.length, 1, "One template found");
assert.equal(parsed[0].name, "ipsum", "Correct name");
assert.equal(parsed[0].parameters.length, 2, "Two parameters");
assert.equal(parsed[0].parameters[0].name, "2", "Correct first parameter name");
assert.equal(parsed[0].parameters[0].value, "foo", "Correct first parameter value");
assert.equal(parsed[0].parameters[0].wikitext, "|2=foo", "Correct first parameter wikitext");
assert.equal(parsed[0].parameters[1].name, "3", "Correct second parameter name");
assert.equal(parsed[0].parameters[1].value, "bar", "Correct second parameter value");
assert.equal(parsed[0].parameters[1].wikitext, "|3=bar", "Correct second parameter wikitext");
assert.equal(parsed[0].wikitext, "{{ipsum|2=foo|3=bar}}", "Correct wikitext");
});
QUnit.test("Contains triple-brace parameter", function(assert) {
var wikitext = "Lorem {{ipsum|{{{1|}}}}} dorem";
var parsed = extraJs.parseTemplates(wikitext);
assert.equal(parsed.length, 1, "One template found");
assert.equal(parsed[0].name, "ipsum", "Correct name");
assert.equal(parsed[0].parameters.length, 1, "One parameter");
assert.equal(parsed[0].parameters[0].name, 1, "Correct parameter name");
assert.equal(parsed[0].parameters[0].value, "{{{1|}}}", "Correct parameter value");
assert.equal(parsed[0].parameters[0].wikitext, "|{{{1|}}}", "Correct parameter wikitext");
assert.equal(parsed[0].wikitext, "{{ipsum|{{{1|}}}}}", "Correct wikitext");
});
QUnit.test("Four braces (template name is a template), non-recursive", function(assert) {
var wikitext = "Lorem {{{{ipsum|one}}|bar}} dorem";
var parsed = extraJs.parseTemplates(wikitext);
assert.equal(parsed.length, 1, "One template found");
assert.equal(parsed[0].name, "{{ipsum|one}}", "Correct name");
assert.equal(parsed[0].parameters.length, 1, "One parameter");
assert.equal(parsed[0].parameters[0].name, 1, "Correct parameter name");
assert.equal(parsed[0].parameters[0].value, "bar", "Correct parameter value");
assert.equal(parsed[0].parameters[0].wikitext, "|bar", "Correct parameter wikitext");
assert.equal(parsed[0].wikitext, "{{{{ipsum|one}}|bar}}", "Correct wikitext");
});
QUnit.test("Four braces (template name is a template), recursive", function(assert) {
var wikitext = "Lorem {{{{ipsum|one}}|bar}} dorem";
var parsed = extraJs.parseTemplates(wikitext, true);
assert.equal(parsed.length, 2, "Two templates found");
assert.equal(parsed[0].name, "{{ipsum|one}}", "First: Correct name");
assert.equal(parsed[0].parameters.length, 1, "First: One parameter");
assert.equal(parsed[0].parameters[0].name, 1, "First: Correct parameter name");
assert.equal(parsed[0].parameters[0].value, "bar", "First: Correct parameter value");
assert.equal(parsed[0].parameters[0].wikitext, "|bar", "First: Correct parameter wikitext");
assert.equal(parsed[0].wikitext, "{{{{ipsum|one}}|bar}}", "First: Correct wikitext");
assert.equal(parsed[1].name, "ipsum", "Second: Correct name");
assert.equal(parsed[1].parameters.length, 1, "Second: One parameter");
assert.equal(parsed[1].parameters[0].name, 1, "Second: Correct parameter name");
assert.equal(parsed[1].parameters[0].value, "one", "Second: Correct parameter value");
assert.equal(parsed[1].parameters[0].wikitext, "|one", "Second: Correct parameter wikitext");
assert.equal(parsed[1].wikitext, "{{ipsum|one}}", "Second: Correct wikitext");
});
QUnit.test("Five braces (template name is a triple-brace parameter), non-recursive", function(assert) {
var wikitext = "Lorem {{{{{ipsum|foo}}}|bar}} dorem";
var parsed = extraJs.parseTemplates(wikitext);
assert.equal(parsed.length, 1, "One template found");
assert.equal(parsed[0].name, "{{{ipsum|foo}}}", "Correct name");
assert.equal(parsed[0].parameters.length, 1, "One parameter");
assert.equal(parsed[0].parameters[0].name, 1, "Correct parameter name");
assert.equal(parsed[0].parameters[0].value, "bar", "Correct parameter value");
assert.equal(parsed[0].parameters[0].wikitext, "|bar", "Correct parameter wikitext");
assert.equal(parsed[0].wikitext, "{{{{{ipsum|foo}}}|bar}}", "Correct wikitext");
});
QUnit.test("Five braces (template name is a triple-brace parameter), recursive", function(assert) {
var wikitext = "Lorem {{{{{ipsum|foo}}}|bar}} dorem";
var parsed = extraJs.parseTemplates(wikitext, true);
assert.equal(parsed.length, 1, "One template found");
assert.equal(parsed[0].name, "{{{ipsum|foo}}}", "Correct name");
assert.equal(parsed[0].parameters.length, 1, "One parameter");
assert.equal(parsed[0].parameters[0].name, 1, "Correct parameter name");
assert.equal(parsed[0].parameters[0].value, "bar", "Correct parameter value");
assert.equal(parsed[0].parameters[0].wikitext, "|bar", "Correct parameter wikitext");
assert.equal(parsed[0].wikitext, "{{{{{ipsum|foo}}}|bar}}", "Correct wikitext");
});
QUnit.test("Six braces (template name is a template, which itself has a template name that is a template), recursive", function(assert) {
var wikitext = "Lorem {{{{{{ipsum|foo}}|bar}}|baz}} dorem";
var parsed = extraJs.parseTemplates(wikitext, true);
assert.equal(parsed.length, 3, "Three templates found");
assert.equal(parsed[0].name, "{{{{ipsum|foo}}|bar}}", "First: Correct name");
assert.equal(parsed[0].parameters.length, 1, "First: One parameter");
assert.equal(parsed[0].parameters[0].name, 1, "First: Correct parameter name");
assert.equal(parsed[0].parameters[0].value, "baz", "First: Correct parameter value");
assert.equal(parsed[0].parameters[0].wikitext, "|baz", "First: Correct parameter wikitext");
assert.equal(parsed[0].wikitext, "{{{{{{ipsum|foo}}|bar}}|baz}}", "First: Correct wikitext");
assert.equal(parsed[1].name, "{{ipsum|foo}}", "Second: Correct name");
assert.equal(parsed[1].parameters.length, 1, "Second: One parameter");
assert.equal(parsed[1].parameters[0].name, 1, "Second: Correct parameter name");
assert.equal(parsed[1].parameters[0].value, "bar", "Second: Correct parameter value");
assert.equal(parsed[1].parameters[0].wikitext, "|bar", "Second: Correct parameter wikitext");
assert.equal(parsed[1].wikitext, "{{{{ipsum|foo}}|bar}}", "Second: Correct wikitext");
assert.equal(parsed[2].name, "ipsum", "Third: Correct name");
assert.equal(parsed[2].parameters.length, 1, "Third: One parameter");
assert.equal(parsed[2].parameters[0].name, 1, "Third: Correct parameter name");
assert.equal(parsed[2].parameters[0].value, "foo", "Third: Correct parameter value");
assert.equal(parsed[2].parameters[0].wikitext, "|foo", "Third: Correct parameter wikitext");
assert.equal(parsed[2].wikitext, "{{ipsum|foo}}", "Third: Correct wikitext");
});
QUnit.test("Six braces (triple-brace parameter within triple-brace parameter), recursive", function(assert) {
var wikitext = "Lorem {{foo|{{{{{{ipsum|}}}|bar}}}|baz}} dorem";
var parsed = extraJs.parseTemplates(wikitext, true);
assert.equal(parsed.length, 1, "One template found");
assert.equal(parsed[0].name, "foo", "Correct name");
assert.equal(parsed[0].parameters.length, 2, "Two parameter");
assert.equal(parsed[0].parameters[0].name, 1, "Correct first parameter name");
assert.equal(parsed[0].parameters[0].value, "{{{{{{ipsum|}}}|bar}}}", "Correct first parameter value");
assert.equal(parsed[0].parameters[0].wikitext, "|{{{{{{ipsum|}}}|bar}}}", "Correct first parameter wikitext");
assert.equal(parsed[0].parameters[1].name, 2, "Correct second parameter name");
assert.equal(parsed[0].parameters[1].value, "baz", "Correct second parameter value");
assert.equal(parsed[0].parameters[1].wikitext, "|baz", "Correct second parameter wikitext");
assert.equal(parsed[0].wikitext, "{{foo|{{{{{{ipsum|}}}|bar}}}|baz}}", "Correct wikitext");
});
/* ========== End closures ====================================================================== */
}); // end of load QUnit callback
}); // end of getScript callback
}; // end of init function
// Wait for page load
$(function($) {
// Wait a few more seconds, so hopefull other scripts have finished loading, then run init
window.setTimeout(init, 3000);
});
} // end if statement
// </nowiki>