Модул:Wikidata/P512/tests
< Модул:Wikidata | P512
Ин модул ҳуҷҷатгузории кофӣ надорад.
Вы можете помочь проекту, создав описание модуля: что он делает, как его использовать, какие параметры он принимает, в какие категории добавляет. Это поможет другим использовать его. P.S. Также не забываем про категорию и интервики. P.P.S. Некоторые советы по оформлению есть на странице проекта «Документирование шаблонов». |
local p = require('Module:UnitTests')
local t = require('Module:Wikidata/P512')
function p:test_getPreviousDegrees()
self:getPreviousDegreesAndAssert({}, {})
self:getPreviousDegreesAndAssert({1}, {})
self:getPreviousDegreesAndAssert({1, 16698078, 19610224}, {[19610224]=true})
self:getPreviousDegreesAndAssert({17281125, 17281125}, {[18071588]=true})
end
function p:test_formatAcademicDegree()
local mockContext = {
['selectClaims'] =
function( a, b )
return {{
['id'] = 'Q4115189$2fb0ce43-4ffe-9e6e-6dab-0d101b0ceac0',
['mainsnak'] = {['datavalue'] = {
['value'] = { ['numeric-id'] = 17281087 }}},
['references'] = {
['hash'] = 'd103e3541cc531fa54adcaffebde6bef28d87d32'}}}
end,
['formatStatement'] =
function( a, b )
return 'доктори илмҳои филология'
end
}
local mockOptions = {['entity']={}, ['property']='P512'}
local expectedValue = '<span class="wikidata-claim" ' ..
'data-wikidata-property-id="P512" ' ..
'data-wikidata-claim-id="Q4115189$2fb0ce43-4ffe-9e6e-6dab-0d101b0ceac0"' ..
'>доктори илмҳои филология</span>' ..
'[[Гурӯҳ:Докторони улуми филология]]'
self:equals('demo', t.formatAcademicDegree(mockContext, mockOptions),
expectedValue, {['nowiki']=true})
end
function p:test_formatCorrespondingCategory()
self:formatCorrespondingCategoryAndAssert( 752297, true, '[[Гурӯҳ:Докторони фалсафа]]' )
self:formatCorrespondingCategoryAndAssert( 849697, true, '' )
self:formatCorrespondingCategoryAndAssert( 913404, true, '[[Гурӯҳ:Докторони тиб]]' )
self:formatCorrespondingCategoryAndAssert( 959320, true, '[[Гурӯҳ:Докторони ҳуқуқ]]' )
self:formatCorrespondingCategoryAndAssert( 5978719, true, '' )
self:formatCorrespondingCategoryAndAssert( 17281180, true, '[[Гурӯҳ:Докторони ҳунаршиносӣ]]' )
self:formatCorrespondingCategoryAndAssert( 19603972, true, '[[Гурӯҳ:Номзадҳои улуми фалсафа]]' )
end
function p:test_formatQualifier()
self:formatQualifierAndAssert({}, '')
self:formatQualifierAndAssert({1987}, ' (1987)')
self:formatQualifierAndAssert({2017, 2024}, ' (2017)')
end
function p:getPreviousDegreesAndAssert( degrees, previous )
local claims = {}
for _, id in ipairs(degrees) do
table.insert(claims, {['mainsnak'] = {['datavalue'] = {['value'] = { ['numeric-id'] = id }}}})
end
self:equals_deep('{' .. table.concat(degrees, ', ') .. '}',
t.getPreviousDegrees(claims),
previous)
end
function p:formatCorrespondingCategoryAndAssert( numericId, needRef, expectedValue )
local ref=''
local claim = {['mainsnak'] = {['datavalue'] = {['value'] = { ['numeric-id'] = numericId }}}}
if (needRef) then
claim['references'] =''
ref='<sup>[1]</sup>'
end;
local actualValue = t.formatCorrespondingCategory (claim);
self:equals('[[d:Q' .. numericId .. ']]'..ref,
string.gsub(actualValue, "Гурӯҳ", ":Гурӯҳ"),
string.gsub(expectedValue, "Гурӯҳ", ":Гурӯҳ"),
nil)
end
function p:formatQualifierAndAssert(snaks, expectedValue )
self:equals_deep('{' .. table.concat(snaks, ', ') .. '}',
t.formatQualifier({['formatSnak'] =
function( a, b )
return b
end; }, {}, snaks),
expectedValue)
end
return p