Module:Check for deprecated parameters/testcases

-- Unit tests for [[Module:{{ROOTPAGENAME}}]]. Click talk page to run tests.
local p = require('Module:UnitTests')
local warning = require('Module:If preview')._warning
local main = require('Module:Check for deprecated parameters')._check
local sandbox = require('Module:Check for deprecated parameters/sandbox')._check

-- Remember to run the tests in preview mode! The test code, below, checks for preview correctness also

local function test(tester,fcn)
    tester:equals('Nothing deprecated',fcn({A1='B1',A2='B2',_category='C',preview='W'},
                               {A0='val'},'caller'),
                  '',{nowiki=1,stripmarkers=1})
    tester:equals('Simple',fcn({A1='B1',A2='B2',_category='C',preview='W'},
                               {A2='val'},'caller'),
                  'C'..warning({'W'}),{nowiki=1,stripmarkers=1})
    tester:equals('Simple with _VALUE_',fcn({A1='B1',A2='B2',_category='C _VALUE_',preview='W _VALUE_'},
                                            {A2='val'},'caller'),
                  'C A2'..warning({'W "A2". Replace with "B2".'}),{nowiki=1,stripmarkers=1})
    tester:equals('Remove',fcn({A1='B1',A2='B2',_category='C',preview='W',_remove='XX; A3; A4'},
                               {A3='val'},'caller'),
                  'C'..warning({'W'}),{nowiki=1,stripmarkers=1})
    tester:equals('Remove with _VALUE_',fcn({A1='B1',A2='B2',_category='C _VALUE_',preview='W _VALUE_',_remove='XX; A3; A4'},
                                            {A3='val'},'caller'),
                  'C A3'..warning({'W "A3". It should be removed.'}),{nowiki=1,stripmarkers=1})
    tester:equals('No preview',fcn({A1='B1',A2='B2',_category='C _VALUE_'},
                               {A2='val'},'caller'),
                  'C A2'..warning({'Page using [[caller]] with deprecated parameter "A2". Replace with "B2".'}),{nowiki=1,stripmarkers=1})
    tester:equals('Blank value',fcn({A1='B1',A2='B2',_category='C _VALUE_',preview='W'},
                               {A2='  '},'caller'),
                  'C A2'..warning({'W'}),{nowiki=1,stripmarkers=1})
    tester:equals('Blank value with ignoreblank',fcn({A1='B1',A2='B2',_category='C _VALUE_',preview='W',ignoreblank=1},
                               {A2='  '},'caller'),
                  '',{nowiki=1,stripmarkers=1})
end

function p:test_main()
    if main then
        test(p,main)
    end
end

function p:test_sandbox()
    if sandbox then
        test(p,sandbox)
    end
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.

  1. 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:
  2. 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.
  3. 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.
  4. 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.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.