Module:Format ISBN/testcases

-- Unit tests for Module:Format ISBN. Click talk page to run tests. -- Example usage: --  -- Console example: --  mw.log(p.run_tests(mw.getCurrentFrame))

local p = require('Module:UnitTests')

function p:test_check_ISBN self:preprocess_equals("", "true") self:preprocess_equals("", "true") self:preprocess_equals("", "") self:preprocess_equals("", "") end

function p:test_check_return_values self:preprocess_equals("", "okay") self:preprocess_equals("", "error") self:preprocess_equals("", "okay") self:preprocess_equals("", "error") end

function p:test_check_punctuation_removal self:preprocess_equals("", "true") self:preprocess_equals("", "true") end

function p:test_check_positional_arguments self:preprocess_equals("", "valid") self:preprocess_equals("", "invalid") end

function p:test_format_English_ISBN_10 self:preprocess_equals("", "ISBN 1-84356-028-3") self:preprocess_equals("", "ISBN 0-684-84328-5") self:preprocess_equals("", "ISBN 0-8044-2957-X") self:preprocess_equals("", "ISBN 0-85131-041-9") self:preprocess_equals("", "ISBN 0-943396-04-2") self:preprocess_equals("", "ISBN 0-9752298-0-X") end

function p:test_format_English_ISBN_13 self:preprocess_equals("", "ISBN 978-1-84356-028-9") self:preprocess_equals("", "ISBN 978-0-684-84328-5") self:preprocess_equals("", "ISBN 978-0-8044-2957-3") self:preprocess_equals("", "ISBN 978-0-85131-041-1") self:preprocess_equals("", "ISBN 978-0-943396-04-0") self:preprocess_equals("", "ISBN 978-0-9752298-0-4")

self:preprocess_equals("", "ISBN 979-8-5311-3217-8") end

function p:test_format_non_English_ISBN_10 self:preprocess_equals("", "ISBN 99921-58-10-7") self:preprocess_equals("", "ISBN 9971-5-0210-0") self:preprocess_equals("", "ISBN 960-425-059-0") self:preprocess_equals("", "ISBN 80-902734-1-6") self:preprocess_equals("", "ISBN 85-359-0277-5") end

function p:test_format_non_English_ISBN_13 self:preprocess_equals("", "ISBN 978-99921-58-10-4") self:preprocess_equals("", "ISBN 978-9971-5-0210-2") self:preprocess_equals("", "ISBN 978-960-425-059-2") self:preprocess_equals("", "ISBN 978-80-902734-1-2") self:preprocess_equals("", "ISBN 978-85-359-0277-8") end

function p:test_format_punctuation_removal self:preprocess_equals("", "ISBN 1-84356-028-3") self:preprocess_equals("", "ISBN 978-1-84356-028-9") end

function p:test_format_invariance local isbn_10, isbn_13 = "1-84356-028-3", "978-1-84356-028-9" self:preprocess_equals("", "ISBN " .. isbn_10) self:preprocess_equals("", "ISBN " .. isbn_13) end

function p:test_format_prefixes self:preprocess_equals("", "ISBN-10 1-84356-028-3") self:preprocess_equals("", "ISBN-13 978-1-84356-028-9") self:preprocess_equals("", "ISBN-10 1-84356-028-3") self:preprocess_equals("", "ISBN-13 978-1-84356-028-9") self:preprocess_equals("", "1-84356-028-3") self:preprocess_equals("", "978-1-84356-028-9") self:preprocess_equals("", "1-84356-028-3") self:preprocess_equals("", "978-1-84356-028-9") end

function p:test_format_space_separators self:preprocess_equals("", "ISBN 1 84356 028 3") self:preprocess_equals("", "ISBN 978 1 84356 028 9") self:preprocess_equals("", "ISBN 1 84356 028 3") self:preprocess_equals("", "ISBN 978 1 84356 028 9") end

function p:test_format_ISBN_10_to_13_conversion self:preprocess_equals("", "ISBN 978-1-84356-028-9") self:preprocess_equals("", "ISBN 978-1-84356-028-9") self:preprocess_equals("", "ISBN 978-1-84356-028-9") self:preprocess_equals("", "ISBN 978-1-84356-028-9") end

function p:test_format_ISBN_13_to_10_conversion self:preprocess_equals("", "ISBN 1-84356-028-3") self:preprocess_equals("", "ISBN 1-84356-028-3") self:preprocess_equals("", "ISBN 1-84356-028-3") self:preprocess_equals("", "ISBN 1-84356-028-3")

self:preprocess_equals("", "ISBN error") end

function p:test_format_special_links self:preprocess_equals("", "ISBN 1-84356-028-3") self:preprocess_equals("", "ISBN 978-1-84356-028-9") self:preprocess_equals("", "ISBN 1-84356-028-3") self:preprocess_equals("", "ISBN 978-1-84356-028-9") end

function p:test_format_invalid_check_digits self:preprocess_equals("", "ISBN error") self:preprocess_equals("", "ISBN error") end

function p:test_format_error_inputs self:preprocess_equals("", "ISBN error") self:preprocess_equals("", "ISBN error") self:preprocess_equals("", "ISBN error") self:preprocess_equals("", "ISBN error") self:preprocess_equals("", "ISBN error") self:preprocess_equals("", "ISBN error") self:preprocess_equals("", "ISBN error") self:preprocess_equals("", "invalid") self:preprocess_equals("", "") end

function p:test_format_positional_arguments self:preprocess_equals("", "ISBN-13 978 1 84356 028 9") self:preprocess_equals("", "ISBN-10 1 84356 028 3") self:preprocess_equals("", "ISBN-10 1-84356-028-3") self:preprocess_equals("", "ISBN-10 1-84356-028-3") self:preprocess_equals("", "ISBN-10 1-84356-028-3") self:preprocess_equals("", "invalid") self:preprocess_equals("", "ISBN-13 978 1 84356 028 9") self:preprocess_equals("", "ISBN-10 1 84356 028 3") self:preprocess_equals("", "ISBN-10 1-84356-028-3") self:preprocess_equals("", "invalid") end

return p