// When the expected result is the same in both modes
function assertBothModes( assert, parserArguments, expectedResult, assertMessage ) {
- assert.equal( formatText.apply( null, parserArguments ), expectedResult, assertMessage + ' when format is \'text\'' );
- assert.equal( formatParse.apply( null, parserArguments ), expectedResult, assertMessage + ' when format is \'parse\'' );
+ assert.strictEqual( formatText.apply( null, parserArguments ), expectedResult, assertMessage + ' when format is \'text\'' );
+ assert.strictEqual( formatParse.apply( null, parserArguments ), expectedResult, assertMessage + ' when format is \'parse\'' );
}
QUnit.module( 'mediawiki.jqueryMsg', QUnit.newMwEnvironment( {
QUnit.test( 'Replace', function ( assert ) {
mw.messages.set( 'simple', 'Foo $1 baz $2' );
- assert.equal( formatParse( 'simple' ), 'Foo $1 baz $2', 'Replacements with no substitutes' );
- assert.equal( formatParse( 'simple', 'bar' ), 'Foo bar baz $2', 'Replacements with less substitutes' );
- assert.equal( formatParse( 'simple', 'bar', 'quux' ), 'Foo bar baz quux', 'Replacements with all substitutes' );
+ assert.strictEqual( formatParse( 'simple' ), 'Foo $1 baz $2', 'Replacements with no substitutes' );
+ assert.strictEqual( formatParse( 'simple', 'bar' ), 'Foo bar baz $2', 'Replacements with less substitutes' );
+ assert.strictEqual( formatParse( 'simple', 'bar', 'quux' ), 'Foo bar baz quux', 'Replacements with all substitutes' );
mw.messages.set( 'plain-input', '<foo foo="foo">x$1y<</foo>z' );
- assert.equal(
+ assert.strictEqual(
formatParse( 'plain-input', 'bar' ),
'<foo foo="foo">xbary&lt;</foo>z',
'Input is not considered html'
mw.messages.set( 'plain-replace', 'Foo $1' );
- assert.equal(
+ assert.strictEqual(
formatParse( 'plain-replace', '<bar bar="bar">></bar>' ),
'Foo <bar bar="bar">&gt;</bar>',
'Replacement is not considered html'
mw.messages.set( 'object-replace', 'Foo $1' );
- assert.equal(
+ assert.strictEqual(
formatParse( 'object-replace', $( '<div class="bar">></div>' ) ),
'Foo <div class="bar">></div>',
'jQuery objects are preserved as raw html'
);
- assert.equal(
+ assert.strictEqual(
formatParse( 'object-replace', $( '<div class="bar">></div>' ).get( 0 ) ),
'Foo <div class="bar">></div>',
'HTMLElement objects are preserved as raw html'
);
- assert.equal(
+ assert.strictEqual(
formatParse( 'object-replace', $( '<div class="bar">></div>' ).toArray() ),
'Foo <div class="bar">></div>',
'HTMLElement[] arrays are preserved as raw html'
);
- assert.equal(
+ assert.strictEqual(
formatParse( 'external-link-replace', 'http://example.org/?x=y&z' ),
'Foo <a href="http://example.org/?x=y&z">bar</a>',
'Href is not double-escaped in wikilink function'
);
- assert.equal(
+ assert.strictEqual(
formatParse( 'external-link-plural', 1, 'http://example.org' ),
'Foo is <a href="http://example.org">one</a> things.',
'Link is expanded inside plural and is not escaped html'
);
- assert.equal(
+ assert.strictEqual(
formatParse( 'external-link-plural', 2, 'http://example.org' ),
'Foo <a href="http://example.org">two</a> things.',
'Link is expanded inside an explicit plural form and is not escaped html'
);
- assert.equal(
+ assert.strictEqual(
formatParse( 'external-link-plural', 3 ),
'Foo three things.',
'A simple explicit plural form co-existing with complex explicit plural forms'
);
- assert.equal(
+ assert.strictEqual(
formatParse( 'external-link-plural', 4, 'http://example.org' ),
'Foo a=b things.',
'Only first equal sign is used as delimiter for explicit plural form. Repeated equal signs does not create issue'
);
- assert.equal(
+ assert.strictEqual(
formatParse( 'external-link-plural', 6, 'http://example.org' ),
'Foo are <a href="http://example.org">some</a> things.',
'Plural fallback to the "other" plural form'
);
- assert.equal(
+ assert.strictEqual(
formatParse( 'plural-only-explicit-forms', 2 ),
'It is a double room.',
'Plural with explicit forms alone.'
} );
QUnit.test( 'Plural', function ( assert ) {
- assert.equal( formatParse( 'plural-msg', 0 ), 'Found 0 items', 'Plural test for english with zero as count' );
- assert.equal( formatParse( 'plural-msg', 1 ), 'Found 1 item', 'Singular test for english' );
- assert.equal( formatParse( 'plural-msg', 2 ), 'Found 2 items', 'Plural test for english' );
- assert.equal( formatParse( 'plural-msg-explicit-forms-nested', 6 ), 'Found 6 results', 'Plural message with explicit plural forms' );
- assert.equal( formatParse( 'plural-msg-explicit-forms-nested', 0 ), 'Found no results in Wiki', 'Plural message with explicit plural forms, with nested {{SITENAME}}' );
- assert.equal( formatParse( 'plural-msg-explicit-forms-nested', 1 ), 'Found 1 result', 'Plural message with explicit plural forms with placeholder nested' );
- assert.equal( formatParse( 'plural-empty-explicit-form', 0 ), 'There is me.' );
- assert.equal( formatParse( 'plural-empty-explicit-form', 1 ), 'There is me and other people.' );
- assert.equal( formatParse( 'plural-empty-explicit-form', 2 ), 'There is me and other people.' );
+ assert.strictEqual( formatParse( 'plural-msg', 0 ), 'Found 0 items', 'Plural test for english with zero as count' );
+ assert.strictEqual( formatParse( 'plural-msg', 1 ), 'Found 1 item', 'Singular test for english' );
+ assert.strictEqual( formatParse( 'plural-msg', 2 ), 'Found 2 items', 'Plural test for english' );
+ assert.strictEqual( formatParse( 'plural-msg-explicit-forms-nested', 6 ), 'Found 6 results', 'Plural message with explicit plural forms' );
+ assert.strictEqual( formatParse( 'plural-msg-explicit-forms-nested', 0 ), 'Found no results in Wiki', 'Plural message with explicit plural forms, with nested {{SITENAME}}' );
+ assert.strictEqual( formatParse( 'plural-msg-explicit-forms-nested', 1 ), 'Found 1 result', 'Plural message with explicit plural forms with placeholder nested' );
+ assert.strictEqual( formatParse( 'plural-empty-explicit-form', 0 ), 'There is me.' );
+ assert.strictEqual( formatParse( 'plural-empty-explicit-form', 1 ), 'There is me and other people.' );
+ assert.strictEqual( formatParse( 'plural-empty-explicit-form', 2 ), 'There is me and other people.' );
} );
QUnit.test( 'Gender', function ( assert ) {
// TODO: These tests should be for mw.msg once mw.msg integrated with mw.jqueryMsg
// TODO: English may not be the best language for these tests. Use a language like Arabic or Russian
mw.user.options.set( 'gender', 'male' );
- assert.equal(
+ assert.strictEqual(
formatParse( 'gender-msg', 'Bob', 'male' ),
'Bob: blue',
'Masculine from string "male"'
);
- assert.equal(
+ assert.strictEqual(
formatParse( 'gender-msg', 'Bob', mw.user ),
'Bob: blue',
'Masculine from mw.user object'
);
- assert.equal(
+ assert.strictEqual(
formatParse( 'gender-msg-currentuser' ),
'blue',
'Masculine for current user'
);
mw.user.options.set( 'gender', 'female' );
- assert.equal(
+ assert.strictEqual(
formatParse( 'gender-msg', 'Alice', 'female' ),
'Alice: pink',
'Feminine from string "female"' );
- assert.equal(
+ assert.strictEqual(
formatParse( 'gender-msg', 'Alice', mw.user ),
'Alice: pink',
'Feminine from mw.user object'
);
- assert.equal(
+ assert.strictEqual(
formatParse( 'gender-msg-currentuser' ),
'pink',
'Feminine for current user'
);
mw.user.options.set( 'gender', 'unknown' );
- assert.equal(
+ assert.strictEqual(
formatParse( 'gender-msg', 'Foo', mw.user ),
'Foo: green',
'Neutral from mw.user object' );
- assert.equal(
+ assert.strictEqual(
formatParse( 'gender-msg', 'User' ),
'User: green',
'Neutral when no parameter given' );
- assert.equal(
+ assert.strictEqual(
formatParse( 'gender-msg', 'User', 'unknown' ),
'User: green',
'Neutral from string "unknown"'
);
- assert.equal(
+ assert.strictEqual(
formatParse( 'gender-msg-currentuser' ),
'green',
'Neutral for current user'
mw.messages.set( 'gender-msg-one-form', '{{GENDER:$1|User}}: $2 {{PLURAL:$2|edit|edits}}' );
- assert.equal(
+ assert.strictEqual(
formatParse( 'gender-msg-one-form', 'male', 10 ),
'User: 10 edits',
'Gender neutral and plural form'
);
- assert.equal(
+ assert.strictEqual(
formatParse( 'gender-msg-one-form', 'female', 1 ),
'User: 1 edit',
'Gender neutral and singular form'
);
mw.messages.set( 'gender-msg-lowercase', '{{gender:$1|he|she}} is awesome' );
- assert.equal(
+ assert.strictEqual(
formatParse( 'gender-msg-lowercase', 'male' ),
'he is awesome',
'Gender masculine'
);
- assert.equal(
+ assert.strictEqual(
formatParse( 'gender-msg-lowercase', 'female' ),
'she is awesome',
'Gender feminine'
);
mw.messages.set( 'gender-msg-wrong', '{{gender}} test' );
- assert.equal(
+ assert.strictEqual(
formatParse( 'gender-msg-wrong', 'female' ),
' test',
'Invalid syntax should result in {{gender}} simply being stripped away'
QUnit.test( 'Case changing', function ( assert ) {
mw.messages.set( 'to-lowercase', '{{lc:thIS hAS MEsSed uP CapItaliZatiON}}' );
- assert.equal( formatParse( 'to-lowercase' ), 'this has messed up capitalization', 'To lowercase' );
+ assert.strictEqual( formatParse( 'to-lowercase' ), 'this has messed up capitalization', 'To lowercase' );
mw.messages.set( 'to-caps', '{{uc:thIS hAS MEsSed uP CapItaliZatiON}}' );
- assert.equal( formatParse( 'to-caps' ), 'THIS HAS MESSED UP CAPITALIZATION', 'To caps' );
+ assert.strictEqual( formatParse( 'to-caps' ), 'THIS HAS MESSED UP CAPITALIZATION', 'To caps' );
mw.messages.set( 'uc-to-lcfirst', '{{lcfirst:THis hAS MEsSed uP CapItaliZatiON}}' );
mw.messages.set( 'lc-to-lcfirst', '{{lcfirst:thIS hAS MEsSed uP CapItaliZatiON}}' );
- assert.equal( formatParse( 'uc-to-lcfirst' ), 'tHis hAS MEsSed uP CapItaliZatiON', 'Lcfirst caps' );
- assert.equal( formatParse( 'lc-to-lcfirst' ), 'thIS hAS MEsSed uP CapItaliZatiON', 'Lcfirst lowercase' );
+ assert.strictEqual( formatParse( 'uc-to-lcfirst' ), 'tHis hAS MEsSed uP CapItaliZatiON', 'Lcfirst caps' );
+ assert.strictEqual( formatParse( 'lc-to-lcfirst' ), 'thIS hAS MEsSed uP CapItaliZatiON', 'Lcfirst lowercase' );
mw.messages.set( 'uc-to-ucfirst', '{{ucfirst:THis hAS MEsSed uP CapItaliZatiON}}' );
mw.messages.set( 'lc-to-ucfirst', '{{ucfirst:thIS hAS MEsSed uP CapItaliZatiON}}' );
- assert.equal( formatParse( 'uc-to-ucfirst' ), 'THis hAS MEsSed uP CapItaliZatiON', 'Ucfirst caps' );
- assert.equal( formatParse( 'lc-to-ucfirst' ), 'ThIS hAS MEsSed uP CapItaliZatiON', 'Ucfirst lowercase' );
+ assert.strictEqual( formatParse( 'uc-to-ucfirst' ), 'THis hAS MEsSed uP CapItaliZatiON', 'Ucfirst caps' );
+ assert.strictEqual( formatParse( 'lc-to-ucfirst' ), 'ThIS hAS MEsSed uP CapItaliZatiON', 'Ucfirst lowercase' );
mw.messages.set( 'mixed-to-sentence', '{{ucfirst:{{lc:thIS hAS MEsSed uP CapItaliZatiON}}}}' );
- assert.equal( formatParse( 'mixed-to-sentence' ), 'This has messed up capitalization', 'To sentence case' );
+ assert.strictEqual( formatParse( 'mixed-to-sentence' ), 'This has messed up capitalization', 'To sentence case' );
mw.messages.set( 'all-caps-except-first', '{{lcfirst:{{uc:thIS hAS MEsSed uP CapItaliZatiON}}}}' );
- assert.equal( formatParse( 'all-caps-except-first' ), 'tHIS HAS MESSED UP CAPITALIZATION', 'To opposite sentence case' );
+ assert.strictEqual( formatParse( 'all-caps-except-first' ), 'tHIS HAS MESSED UP CAPITALIZATION', 'To opposite sentence case' );
} );
QUnit.test( 'Grammar', function ( assert ) {
- assert.equal( formatParse( 'grammar-msg' ), 'Przeszukaj Wiki', 'Grammar Test with sitename' );
+ assert.strictEqual( formatParse( 'grammar-msg' ), 'Przeszukaj Wiki', 'Grammar Test with sitename' );
mw.messages.set( 'grammar-msg-wrong-syntax', 'Przeszukaj {{GRAMMAR:grammar_case_xyz}}' );
- assert.equal( formatParse( 'grammar-msg-wrong-syntax' ), 'Przeszukaj ', 'Grammar Test with wrong grammar template syntax' );
+ assert.strictEqual( formatParse( 'grammar-msg-wrong-syntax' ), 'Przeszukaj ', 'Grammar Test with wrong grammar template syntax' );
} );
QUnit.test( 'Match PHP parser', function ( assert ) {
var parser;
mw.config.set( 'wgUserLanguage', test.lang );
parser = new mw.jqueryMsg.Parser( { language: langClass } );
- assert.equal(
+ assert.strictEqual(
parser.parse( test.key, test.args ).html(),
test.result,
test.name
mw.messages.set( 'reverse-pipe-trick', '[[|Tampa, Florida]]' );
mw.messages.set( 'empty-link', '[[]]' );
this.suppressWarnings();
- assert.equal(
+ assert.strictEqual(
formatParse( 'pipe-trick' ),
'[[Tampa, Florida|]]',
'Pipe trick should not be parsed.'
);
- assert.equal(
+ assert.strictEqual(
formatParse( 'reverse-pipe-trick' ),
'[[|Tampa, Florida]]',
'Reverse pipe trick should not be parsed.'
);
- assert.equal(
+ assert.strictEqual(
formatParse( 'empty-link' ),
'[[]]',
'Empty link should not be parsed.'
// Test non-{{ wikitext, where behavior differs
// Wikilink
- assert.equal(
+ assert.strictEqual(
formatText( 'jquerymsg-test-statistics-users' ),
mw.messages.get( 'jquerymsg-test-statistics-users' ),
'Internal link message unchanged when format is \'text\''
);
// External link
- assert.equal(
+ assert.strictEqual(
formatText( 'jquerymsg-test-version-entrypoints-index-php' ),
mw.messages.get( 'jquerymsg-test-version-entrypoints-index-php' ),
'External link message unchanged when format is \'text\''
);
// External link with parameter
- assert.equal(
+ assert.strictEqual(
formatText( 'external-link-replace', 'http://example.com' ),
'Foo [http://example.com bar]',
'External link message only substitutes parameter when format is \'text\''
'Link with nested message'
);
- assert.equal(
+ assert.strictEqual(
formatParse( 'see-portal-url' ),
'Project:Community portal is an important community page.',
'Nested message'
mw.messages.set( 'uses-missing-int', '{{int:doesnt-exist}}' );
- assert.equal(
+ assert.strictEqual(
formatParse( 'uses-missing-int' ),
'⧼doesnt-exist⧽',
'int: where nested message does not exist'
QUnit.test( 'Ns', function ( assert ) {
mw.messages.set( 'ns-template-talk', '{{ns:Template talk}}' );
- assert.equal(
+ assert.strictEqual(
formatParse( 'ns-template-talk' ),
'Dyskusja szablonu',
'ns: returns localised namespace when used with a canonical namespace name'
);
mw.messages.set( 'ns-10', '{{ns:10}}' );
- assert.equal(
+ assert.strictEqual(
formatParse( 'ns-10' ),
'Szablon',
'ns: returns localised namespace when used with a namespace number'
);
mw.messages.set( 'ns-unknown', '{{ns:doesnt-exist}}' );
- assert.equal(
+ assert.strictEqual(
formatParse( 'ns-unknown' ),
'',
'ns: returns empty string for unknown namespace name'
);
mw.messages.set( 'ns-in-a-link', '[[{{ns:template}}:Foo]]' );
- assert.equal(
+ assert.strictEqual(
formatParse( 'ns-in-a-link' ),
'<a title="Szablon:Foo" href="/wiki/Szablon:Foo">Szablon:Foo</a>',
'ns: works when used inside a wikilink'
{
lang: 'ar',
number: '٩٨٧٦٥٤٣٢١٫٦٥٤٣٢١',
- result: 987654321,
+ result: '987654321',
integer: true,
description: 'formatnum test for Arabic, with decimal separator, reverse'
},
{
lang: 'ar',
number: '-١٢٫٨٩',
- result: -12,
+ result: '-12',
integer: true,
description: 'formatnum test for Arabic, negative number, reverse'
},
var parser;
mw.config.set( 'wgUserLanguage', test.lang );
parser = new mw.jqueryMsg.Parser( { language: langClass } );
- assert.equal(
+ assert.strictEqual(
parser.parse( test.integer ? 'formatnum-msg-int' : 'formatnum-msg',
[ test.number ] ).html(),
test.result,
'Italics with link inside in parse mode'
);
- assert.equal(
+ assert.strictEqual(
formatText( 'jquerymsg-italics-with-link' ),
mw.messages.get( 'jquerymsg-italics-with-link' ),
'Italics with link unchanged in text mode'
'Tag outside whitelist escaped in parse mode'
);
- assert.equal(
+ assert.strictEqual(
formatText( 'jquerymsg-script-msg' ),
mw.messages.get( 'jquerymsg-script-msg' ),
'Tag outside whitelist unchanged in text mode'
// Intentionally not using htmlEqual for the quote tests
mw.messages.set( 'jquerymsg-double-quotes-preserved', '<i id="double">Double</i>' );
- assert.equal(
+ assert.strictEqual(
formatParse( 'jquerymsg-double-quotes-preserved' ),
mw.messages.get( 'jquerymsg-double-quotes-preserved' ),
'Attributes with double quotes are preserved as such'
);
mw.messages.set( 'jquerymsg-single-quotes-normalized-to-double', '<i id=\'single\'>Single</i>' );
- assert.equal(
+ assert.strictEqual(
formatParse( 'jquerymsg-single-quotes-normalized-to-double' ),
'<i id="single">Single</i>',
'Attributes with single quotes are normalized to double'
QUnit.test( 'Nowiki', function ( assert ) {
mw.messages.set( 'jquerymsg-nowiki-link', 'Foo <nowiki>[[bar]]</nowiki> baz.' );
- assert.equal(
+ assert.strictEqual(
formatParse( 'jquerymsg-nowiki-link' ),
'Foo [[bar]] baz.',
'Link inside nowiki is not parsed'
);
mw.messages.set( 'jquerymsg-nowiki-htmltag', 'Foo <nowiki><b>bar</b></nowiki> baz.' );
- assert.equal(
+ assert.strictEqual(
formatParse( 'jquerymsg-nowiki-htmltag' ),
'Foo <b>bar</b> baz.',
'HTML inside nowiki is not parsed and escaped'
);
mw.messages.set( 'jquerymsg-nowiki-template', 'Foo <nowiki>{{bar}}</nowiki> baz.' );
- assert.equal(
+ assert.strictEqual(
formatParse( 'jquerymsg-nowiki-template' ),
'Foo {{bar}} baz.',
'Template inside nowiki is not parsed and does not cause a parse error'
this.suppressWarnings();
logSpy = this.sandbox.spy( mw.log, 'warn' );
- assert.equal(
+ assert.strictEqual(
formatParse( 'invalid-wikitext' ),
'<b>{{FAIL}}</b>',
'Invalid wikitext: \'parse\' format'
);
- assert.equal(
+ assert.strictEqual(
formatText( 'invalid-wikitext' ),
'<b>{{FAIL}}</b>',
'Invalid wikitext: \'text\' format'
);
- assert.equal( logSpy.callCount, 2, 'mw.log.warn calls' );
+ assert.strictEqual( logSpy.callCount, 2, 'mw.log.warn calls' );
} );
QUnit.test( 'Integration', function ( assert ) {
expected = '<b><a title="Bold" href="/wiki/Bold">Bold</a>!</b>';
mw.messages.set( 'integration-test', '<b>[[Bold]]!</b>' );
- assert.equal(
+ assert.strictEqual(
mw.message( 'integration-test' ).parse(),
expected,
'mw.message().parse() works correctly'
);
- assert.equal(
+ assert.strictEqual(
$( '<span>' ).msg( 'integration-test' ).html(),
expected,
'jQuery plugin $.fn.msg() works correctly'
$( '<a>' ).attr( 'href', 'http://example.com/' )
);
msg.parse(); // Not a no-op
- assert.equal(
+ assert.strictEqual(
msg.parse(),
'<a href="http://example.com/">Link</a>',
'Calling .parse() multiple times does not duplicate link contents'