2013-02-08 14:56:44 +00:00
|
|
|
|
local testframework = require 'Module:TestFramework'
|
|
|
|
|
|
|
|
|
|
local message1 = mw.message.new( 'mainpage' )
|
|
|
|
|
local message1_copy = mw.message.new( 'mainpage' )
|
|
|
|
|
local message2 = mw.message.new( 'i-dont-exist-evar' )
|
|
|
|
|
|
|
|
|
|
function test_exists( key )
|
|
|
|
|
return mw.message.new( key ):exists()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function test_language( key )
|
|
|
|
|
-- If mw.language is available, test that too
|
|
|
|
|
local lang = 'ru'
|
|
|
|
|
if mw.language then
|
|
|
|
|
lang = mw.language.new( 'ru' )
|
|
|
|
|
end
|
|
|
|
|
|
2014-02-03 20:08:54 +00:00
|
|
|
|
return mw.message.new( 'mainpage' ):useDatabase( false ):inLanguage( 'en' ):plain(),
|
|
|
|
|
mw.message.new( 'mainpage' ):useDatabase( false ):inLanguage( 'ru' ):plain(),
|
|
|
|
|
mw.message.new( 'mainpage' ):useDatabase( false ):inLanguage( lang ):plain()
|
2013-02-08 14:56:44 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function test_params( rawMessage, func, ... )
|
|
|
|
|
local msg = mw.message.newRawMessage( rawMessage ):inLanguage( 'en' )
|
2014-02-03 20:08:54 +00:00
|
|
|
|
return msg[func]( msg, ... ):plain()
|
2013-02-08 14:56:44 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return testframework.getTestProvider( {
|
|
|
|
|
{ name = 'exists (1)', func = test_exists,
|
2020-10-23 15:39:12 +00:00
|
|
|
|
args = { 'mainpage' },
|
|
|
|
|
expect = { true }
|
2013-02-08 14:56:44 +00:00
|
|
|
|
},
|
|
|
|
|
{ name = 'exists (2)', func = test_exists,
|
2020-10-23 15:39:12 +00:00
|
|
|
|
args = { 'i-dont-exist-evar' },
|
|
|
|
|
expect = { false }
|
2013-02-08 14:56:44 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ name = 'inLanguage', func = test_language,
|
2020-10-23 15:39:12 +00:00
|
|
|
|
expect = { 'Main Page', 'Заглавная страница', 'Заглавная страница' }
|
2013-02-08 14:56:44 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ name = 'plain param', func = test_params,
|
2020-10-23 15:39:12 +00:00
|
|
|
|
args = { '($1 $2)', 'params', "'''foo'''", 123456 },
|
|
|
|
|
expect = { "('''foo''' 123456)" }
|
2013-02-08 14:56:44 +00:00
|
|
|
|
},
|
|
|
|
|
{ name = 'raw param', func = test_params,
|
2020-10-23 15:39:12 +00:00
|
|
|
|
args = { '($1 $2)', 'rawParams', "'''foo'''", 123456 },
|
|
|
|
|
expect = { "('''foo''' 123456)" }
|
2013-02-08 14:56:44 +00:00
|
|
|
|
},
|
|
|
|
|
{ name = 'num param', func = test_params,
|
2020-10-23 15:39:12 +00:00
|
|
|
|
args = { '($1 $2)', 'numParams', "-1.23", 123456 },
|
2020-11-20 15:20:10 +00:00
|
|
|
|
expect = { "(−1.23 123,456)" }
|
2013-02-08 14:56:44 +00:00
|
|
|
|
},
|
|
|
|
|
{ name = 'mixed params', func = test_params,
|
2020-10-23 15:39:12 +00:00
|
|
|
|
args = { '($1 $2 $3)', 'params',
|
2013-02-08 14:56:44 +00:00
|
|
|
|
"'''foo'''", mw.message.rawParam( "'''foo'''" ), mw.message.numParam( 123456 )
|
2020-10-23 15:39:12 +00:00
|
|
|
|
},
|
|
|
|
|
expect = { "('''foo''' '''foo''' 123,456)" }
|
2013-02-08 14:56:44 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ name = 'message as param', func = test_params,
|
2020-10-23 15:39:12 +00:00
|
|
|
|
args = { '($1)', 'params', mw.message.newRawMessage( 'bar' ) },
|
|
|
|
|
expect = { "(bar)" }
|
2013-02-08 14:56:44 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{ name = 'different title', func = test_params,
|
2020-10-23 15:39:12 +00:00
|
|
|
|
args = { '($1)', 'params', mw.message.newRawMessage( 'bar' ) },
|
|
|
|
|
expect = { "(bar)" }
|
2013-02-08 14:56:44 +00:00
|
|
|
|
},
|
|
|
|
|
} )
|