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_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_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-7193-8927-1") end

function p:test_partially_handled_non_English_ISBN_10 self:preprocess_equals("", "ISBN 999215810-7") self:preprocess_equals("", "ISBN 997150210-0") self:preprocess_equals("", "ISBN 960425059-0") self:preprocess_equals("", "ISBN 809027341-6") self:preprocess_equals("", "ISBN 853590277-5")

-- Note: calling format with fully formatted non-English ISBNs currently downgrades their format. self:preprocess_equals("", "ISBN 999215810-7") self:preprocess_equals("", "ISBN 997150210-0") self:preprocess_equals("", "ISBN 960425059-0") self:preprocess_equals("", "ISBN 809027341-6") self:preprocess_equals("", "ISBN 853590277-5") end

function p:test_partially_handled_non_English_ISBN_13 self:preprocess_equals("", "ISBN 978-999215810-4") self:preprocess_equals("", "ISBN 978-997150210-2") self:preprocess_equals("", "ISBN 978-960425059-2") self:preprocess_equals("", "ISBN 978-809027341-2") self:preprocess_equals("", "ISBN 978-853590277-8")

-- Note: calling format with fully formatted non-English ISBNs currently downgrades their format. self:preprocess_equals("", "ISBN 978-999215810-4") self:preprocess_equals("", "ISBN 978-997150210-2") self:preprocess_equals("", "ISBN 978-960425059-2") self:preprocess_equals("", "ISBN 978-809027341-2") self:preprocess_equals("", "ISBN 978-853590277-8") end

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

function p:test_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_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_space_separators self:preprocess_equals("", "ISBN 1 84356 028 3") self:preprocess_equals("", "ISBN 978 1 84356 028 9") end

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

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

function p:test_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_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("", "invalid") end

return p