/*! * Tests for ext.translate.parsers.js. * * @license GPL-2.0-or-later */ ( function () { 'use strict'; QUnit.module( 'ext.translate.parsers', QUnit.newMwEnvironment() ); QUnit.test( '-- Page titles and headings', function ( assert ) { mw.config.set( 'wgArticlePath', '/wiki/$1' ); assert.strictEqual( mw.translate.formatMessageGently( '== Heading with = sign ==' ), '

Heading with = sign

', 'Heading equal signs should always detect the line-end equal signs and strip the surronding whitespaces' ); assert.strictEqual( mw.translate.formatMessageGently( '==Heading with = sign without suggested surronding whitespaces==' ), '

Heading with = sign without suggested surronding whitespaces

', 'Heading equal signs should always detect the line-end equal signs without suggested surronding whitespaces' ); assert.strictEqual( mw.translate.formatMessageGently( '== Heading with = sign ==\nText' ), '

Heading with = sign

\nText', 'Headings with text in new line should able to be rendered correctly' ); } ); QUnit.test( '-- External links', function ( assert ) { mw.config.set( 'wgArticlePath', '/wiki/$1' ); assert.strictEqual( mw.translate.formatMessageGently( 'This page is [in English]' ), 'This page is [in English]', 'Brackets without protocol doesn\'t make a link' ); assert.strictEqual( mw.translate.formatMessageGently( 'This page has [https://www.mediawiki.org a link]' ), 'This page has a link', 'Brackets with https:// protocol creates a link' ); assert.strictEqual( mw.translate.formatMessageGently( 'No kun [[m:MassMessage]] ja plum [[m:|Meta-Wiki]].' ), 'No kun m:MassMessage ja plum Meta-Wiki.', 'Link parsing is non-greedy' ); } ); QUnit.test( '-- Bold and italics', function ( assert ) { mw.config.set( 'wgArticlePath', '/wiki/$1' ); assert.strictEqual( mw.translate.formatMessageGently( "'''Bold text.''' Normal text." ), 'Bold text. Normal text.', 'Bold parsing is correct' ); assert.strictEqual( mw.translate.formatMessageGently( "''Italic text.'' Normal text." ), 'Italic text. Normal text.', 'Italic parsing is correct' ); assert.strictEqual( mw.translate.formatMessageGently( "'''''Bold and italic text.''''' Normal text." ), 'Bold and italic text. Normal text.', 'Bold and italic parsing is correct' ); assert.strictEqual( mw.translate.formatMessageGently( "'''''Bold and italic.'' Just bold.''' Normal." ), 'Bold and italic. Just bold. Normal.', 'Parsing of bold text with italic at the start is correct' ); assert.strictEqual( mw.translate.formatMessageGently( "'''''Bold and italic.''' Just italic.'' Normal." ), 'Bold and italic. Just italic. Normal.', 'Parsing of italic text with bold at the start is correct' ); assert.strictEqual( mw.translate.formatMessageGently( "'''Bold first, ''then italic.''''' Normal." ), 'Bold first, then italic. Normal.', 'Parsing of bold text ending with italic text is correct' ); assert.strictEqual( mw.translate.formatMessageGently( "''Italic first, '''then bold.''''' Normal." ), 'Italic first, then bold. Normal.', 'Parsing of italic text ending with bold text is correct' ); } ); }() );