Jump to content

Module:TwitterSnowflake/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Elli (talk | contribs) at 15:36, 18 January 2021 (ah, extra space). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- Unit tests for [[Module:TwitterSnowflake]]. Click talk page to run tests. 
local p = require('Module:UnitTests')

function p:test_only_id() -- default date format is "Month Day, Year"
    self:preprocess_equals('{{#invoke:TwitterSnowflake | snowflakeToDate | id_str = 1345021162959503360}}', 'January  1, 2021')
end

function p:test_custom_output_format() -- tests date format "Day Month Year"
    self:preprocess_equals('{{#invoke:TwitterSnowflake | snowflakeToDate | id_str = 1345021162959503360 | format = %e %B %Y}}', ' 1 January 2021')
end

function p:test_custom_epoch() -- uses Discord's epoch
    self:preprocess_equals('{{#invoke:TwitterSnowflake | snowflakeToDate | id_str = 797545051047460888 | epoch = 1420070400}}', 'January  9, 2021')
end

function p:test_weird_breaking_date() -- this one used to break old versions of the script, outputting "April 11, 2011"
    self:preprocess_equals('{{#invoke:TwitterSnowflake | snowflakeToDate | id_str = 574608900537761792}}', 'March  8, 2015')
end

return p