پودمان:FarsiDate/testcases

از ویکی‌پدیا، دانشنامهٔ آزاد
local p = require('Module:UnitTests')

local frame = mw.getCurrentFrame()
 
function p:testMain()
	self:preprocess_equals('{{#invoke:FarsiDate|main|۱۳۹۷|۱|۱|solar}}', '۱ فروردین ۱۳۹۷')
    self:preprocess_equals('{{#invoke:FarsiDate|main| ۱۳۹۷ | ۱ | ۱ | solar }}', '۱ فروردین ۱۳۹۷')
    self:preprocess_equals('{{#invoke:FarsiDate|main| 1397 | 1 | 1 | solar }}', '۱ فروردین ۱۳۹۷')
    self:preprocess_equals('{{#invoke:FarsiDate|main| 1397 | 1 | 1 | خورشیدی }}', '۱ فروردین ۱۳۹۷')
    self:preprocess_equals('{{#invoke:FarsiDate|main| 1370| 10 | 10 | خورشیدی }}', '۱۰ دی ۱۳۷۰')
    self:preprocess_equals('{{#invoke:FarsiDate|main| ۲۰۰۰ | ۱ | ۱ }}', '۱ ژانویهٔ ۲۰۰۰')
    self:preprocess_equals('{{#invoke:FarsiDate|main| 2000 | 1 | 1 }}', '۱ ژانویهٔ ۲۰۰۰')
    self:preprocess_equals('{{#invoke:FarsiDate|main| 2000 | 01 | 01 }}', '۱ ژانویهٔ ۲۰۰۰')
    self:preprocess_equals('{{#invoke:FarsiDate|main| 2000 | 1 }}', 'ژانویهٔ ۲۰۰۰')
    self:preprocess_equals('{{#invoke:FarsiDate|main| 2000 |}}', '۲۰۰۰')
    self:preprocess_equals('{{#invoke:FarsiDate|main| 2000 }}', '۲۰۰۰')
end

local function causesInvalidDateError(...)
  local success, result = pcall(frame.callParserFunction, frame, '#invoke', 'FarsiDate', 'main', unpack(arg))
  return result:match('تاریخ ورودی نامعتبر است.') and true or false
end

function p:testInvalidDates()
    self:equals('all valid', causesInvalidDateError(' 2000 ', ' 01 ', ' 01 '), false)
    self:equals('year only', causesInvalidDateError(' 2000 '), false)
    self:equals('valid month, no day', causesInvalidDateError(' 2000 ' , '1'), false)
    self:equals('invalid month, no day', causesInvalidDateError(' 2000 ', ' 00 '), true)
    self:equals('valid month, invalid day', causesInvalidDateError(' 2000 ', ' 0 ', ' 00 '), true)
end
 
return p