Merge "Add mw.text.unstripNoWiki, mw.text.killMarkers, fix mw.text.unstrip"

This commit is contained in:
jenkins-bot 2014-12-01 21:42:17 +00:00 committed by Gerrit Code Review
commit 6f7349dcc8
4 changed files with 69 additions and 5 deletions

View file

@ -6,6 +6,8 @@ class Scribunto_LuaTextLibrary extends Scribunto_LuaLibraryBase {
$lib = array(
'unstrip' => array( $this, 'textUnstrip' ),
'unstripNoWiki' => array( $this, 'textUnstripNoWiki' ),
'killMarkers' => array( $this, 'killMarkers' ),
'getEntityTable' => array( $this, 'getEntityTable' ),
);
$opts = array(
@ -37,7 +39,18 @@ class Scribunto_LuaTextLibrary extends Scribunto_LuaLibraryBase {
function textUnstrip( $s ) {
$this->checkType( 'unstrip', 1, $s, 'string' );
return array( $this->getParser()->mStripState->unstripBoth( $s ) );
$stripState = $this->getParser()->mStripState;
return array( $stripState->killMarkers( $stripState->unstripNoWiki( $s ) ) );
}
function textUnstripNoWiki( $s ) {
$this->checkType( 'unstripNoWiki', 1, $s, 'string' );
return array( $this->getParser()->mStripState->unstripNoWiki( $s ) );
}
function killMarkers( $s ) {
$this->checkType( 'killMarkers', 1, $s, 'string' );
return array( $this->getParser()->mStripState->killMarkers( $s ) );
}
function getEntityTable() {

View file

@ -199,6 +199,14 @@ function mwtext.unstrip( s )
return php.unstrip( s )
end
function mwtext.unstripNoWiki( s )
return php.unstripNoWiki( s )
end
function mwtext.killMarkers( s )
return php.killMarkers( s )
end
function mwtext.split( text, pattern, plain )
local ret = {}
for m in mwtext.gsplit( text, pattern, plain ) do

View file

@ -7,10 +7,17 @@ class Scribunto_LuaTextLibraryTests extends Scribunto_LuaEngineTestBase {
parent::setUp();
// For unstrip test
$parser = $this->getEngine()->getParser();
$markers = array(
'nowiki' => $parser->uniqPrefix() . '-test-nowiki-' . Parser::MARKER_SUFFIX,
'general' => $parser->uniqPrefix() . '-test-general-' . Parser::MARKER_SUFFIX,
);
$parser->mStripState->addNoWiki( $markers['nowiki'], 'NoWiki' );
$parser->mStripState->addGeneral( $markers['general'], 'General' );
$interpreter = $this->getEngine()->getInterpreter();
$interpreter->callFunction(
$interpreter->loadString( 'mw.text.stripTest = ...', 'fortest' ),
$this->getEngine()->getParser()->insertStripItem( 'ok' )
$markers
);
}

View file

@ -13,6 +13,19 @@ setmetatable( tagattrs, { __pairs = function ( t )
end
end } )
-- For data provider, make sure this is defined
mw.text.stripTest = mw.text.stripTest or { nowiki = '!!!', general = '!!!' }
-- Can't directly expect the value from mw.text.stripTest, because when
-- 'expect' is processed by the data provider it's the dummy entry above.
local function stripTest( func, marker )
local result = func( marker )
if result == marker then
result = 'strip-marker'
end
return result
end
-- Tests
local tests = {
{ name = 'trim',
@ -107,9 +120,32 @@ local tests = {
expect = { '<b present key="value" n="42">foo</b>' }
},
{ name = 'unstrip',
func = mw.text.unstrip, args = { mw.text.stripTest },
expect = { 'ok' }
{ name = 'unstrip (nowiki)',
func = stripTest,
args = { mw.text.unstrip, mw.text.stripTest.nowiki },
expect = { 'NoWiki' }
},
{ name = 'unstrip (general)',
func = stripTest,
args = { mw.text.unstrip, mw.text.stripTest.general },
expect = { '' }
},
{ name = 'unstripNoWiki (nowiki)',
func = stripTest,
args = { mw.text.unstripNoWiki, mw.text.stripTest.nowiki },
expect = { 'NoWiki' }
},
{ name = 'unstripNoWiki (general)',
func = stripTest,
args = { mw.text.unstripNoWiki, mw.text.stripTest.general },
expect = { 'strip-marker' }
},
{ name = 'killMarkers',
func = mw.text.killMarkers,
args = { 'a' .. mw.text.stripTest.nowiki .. 'b' .. mw.text.stripTest.general .. 'c' },
expect = { 'abc' }
},
{ name = 'split, simple',