Module:TwitterSnowflake/testcases
| This is the test cases page for the module Module:TwitterSnowflake. Results of the test cases. |
-- Unit tests for [[Module:TwitterSnowflake]]. Click talk page to run tests.
local p = require('Module:UnitTests')
-- test snowflakeToDate
function p:test_snowflakeToDate_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_snowflakeToDate_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_snowflakeToDate_custom_epoch() -- uses Discord's epoch
self:preprocess_equals('{{#invoke:TwitterSnowflake | snowflakeToDate | id_str = 797545051047460888 | epoch = 1420070400}}', 'January 9, 2021')
end
function p:test_snowflakeToDate_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
-- test getDate
function p:test_getDate_date_off_by_five() -- date off by five days, so this returns "5"
self:preprocess_equals('{{#invoke:TwitterSnowflake | getDate | id_str = 1345021162959503360 | date = January 6, 2021}}', '5')
end
function p:test_getDate_date_off_by_one() -- date off by one day, so this returns "1"
self:preprocess_equals('{{#invoke:TwitterSnowflake | getDate | id_str = 1345021162959503360 | date = January 2, 2021}}', '1')
end
function p:test_getDate_date_match() -- date matches, so this returns "0"
self:preprocess_equals('{{#invoke:TwitterSnowflake | getDate | id_str = 1345021162959503360 | date = January 1, 2021}}', '0')
end
function p:test_getDate_before_epoch() -- posted before epoch, so this returns "-1" (date isn't correct here, but that's irrelevant — it can't check it either way)
self:preprocess_equals('{{#invoke:TwitterSnowflake | getDate | id_str = 20 | date = January 1, 2015}}', '-1')
end
function p:test_getDate_invalid_id_str() -- id_str is invalid, so this returns "-2"
self:preprocess_equals('{{#invoke:TwitterSnowflake | getDate | id_str = 1345021162959503360?s=19 | date = January 1, 2021}}', '-2')
end
--sandbox tests for snowflakeToDate
function p:test_zzsandbox_snowflakeToDate_only_id() -- default date format is "Month Day, Year"
self:preprocess_equals('{{#invoke:TwitterSnowflake/sandbox | snowflakeToDate | id_str = 1345021162959503360}}', 'January 1, 2021')
end
function p:test_zzsandbox_snowflakeToDate_custom_output_format() -- tests date format "Day Month Year"
self:preprocess_equals('{{#invoke:TwitterSnowflake/sandbox | snowflakeToDate | id_str = 1345021162959503360 | format = %e %B %Y}}', ' 1 January 2021')
end
function p:test_zzsandbox_snowflakeToDate_custom_epoch() -- uses Discord's epoch
self:preprocess_equals('{{#invoke:TwitterSnowflake/sandbox | snowflakeToDate | id_str = 797545051047460888 | epoch = 1420070400}}', 'January 9, 2021')
end
function p:test_zzsandbox_snowflakeToDate_weird_breaking_date() -- this one used to break old versions of the script, outputting "April 11, 2011"
self:preprocess_equals('{{#invoke:TwitterSnowflake/sandbox | snowflakeToDate | id_str = 574608900537761792}}', 'March 8, 2015')
end
--sandbox tests for getDate
function p:test_zzsandbox_getDate_date_off_by_five() -- date off by five days, so this returns "5"
self:preprocess_equals('{{#invoke:TwitterSnowflake/sandbox | getDate | id_str = 1345021162959503360 | date = January 6, 2021}}', '5')
end
function p:test_zzsandbox_getDate_date_off_by_one() -- date off by one day, so this returns "1"
self:preprocess_equals('{{#invoke:TwitterSnowflake/sandbox | getDate | id_str = 1345021162959503360 | date = January 2, 2021}}', '1')
end
function p:test_zzsandbox_getDate_date_match() -- date matches, so this returns "0"
self:preprocess_equals('{{#invoke:TwitterSnowflake/sandbox | getDate | id_str = 1345021162959503360 | date = January 1, 2021}}', '0')
end
function p:test_zzsandbox_getDate_before_epoch() -- posted before epoch, so this returns "-1" (date isn't correct here, but that's irrelevant — it can't check it either way)
self:preprocess_equals('{{#invoke:TwitterSnowflake/sandbox | getDate | id_str = 20 | date = January 1, 2015}}', '-1')
end
function p:test_zzsandbox_getDate_invalid_id_str() -- id_str is invalid, so this returns "-2"
self:preprocess_equals('{{#invoke:TwitterSnowflake/sandbox | getDate | id_str = 1345021162959503360?s=19 | date = January 1, 2021}}', '-2')
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.