Module:TemplateDataDoc/testcases

-- Unit tests for Module:TemplateDataDoc. Click talk page to run tests. require( 'Module:No globals' )

local ScribuntoUnit = require( 'Module:ScribuntoUnit' ) local suite = ScribuntoUnit:new local libName = 'TemplateDataDoc'

-- Helper to run all tests using sandbox version of the library from the debug console. To run against main lib, use =p.run function suite.runSandbox local frame = mw.getCurrentFrame:newChild{ title='testcases', args={ module=libName .. '/sandbox', displayMode='log' } } return suite.run( frame ) end

-- Allow test runner to use the sandbox and the primary versions of the library with the same testcases function suite:module return require( 'Module:' .. ( self.frame and self.frame.args.module or libName ) ) end

-- Test convertFormatString

function suite:testConvertFormatString local tt = self:module

local formatInline, flagInline = tt.convertFormatString( 'inline' ) self:assertEquals( '', formatInline ) self:assertEquals( false, flagInline )

local formatBlock, flagBlock = tt.convertFormatString( 'block' ) self:assertEquals( '', formatBlock ) self:assertEquals( true, flagBlock )

local formatCustom, flagCustom = tt.convertFormatString( '' ) self:assertEquals( '', formatCustom ) self:assertEquals( false, flagCustom ) end

-- Test getFormatParts

function suite:testGetFormatParts local tt = self:module

local flag1, start1, end1, paramKey1, paramValue1 = tt.getFormatParts( 'inline', 'Test' ) self:assertEquals( false, flag1 ) self:assertEquals( '', end1 ) self:assertEquals( '|_=', paramKey1 ) self:assertEquals( '_', paramValue1 )

local flag2, start2, end2, paramKey2, paramValue2 = tt.getFormatParts( 'block', 'Test_2' ) self:assertEquals( true, flag2 ) self:assertEquals( '', end2 ) self:assertEquals( '| _ =', paramKey2 ) self:assertEquals( ' _\n', paramValue2 )

local flag3, start3, end3, paramKey3, paramValue3 = tt.getFormatParts( '\n', 'Test 3' ) self:assertEquals( false, flag3 ) self:assertEquals( '\n', end3 ) self:assertEquals( '|\n_\n=', paramKey3 ) self:assertEquals( '\n_\n', paramValue3 ) end

-- Test processJson

function suite:testProcessJson local tt = self:module

local json = '{ "params": { "1": { "label": "1", }, "2": { "label": "2", } } }' local data = tt.processJson( json ) self:assertEquals( 2, #data.params ) end

return suite