Module:Ppoem/testcases

-- Unit tests for Module:Ppoem. Click talk page to run tests. local p = require('Module:UnitTests')

local ppoem = require('Module:Ppoem')

function p:do_line_test( tests )

for k, v in pairs(tests) do	   self:equals_deep(	    	v[1] .. '' ,	    	ppoem.parse_line(v[2]),	    	v[3]    	) end end function p:test_line_syntax_parsing local tests = { { 'Plain stanza line', '', { type = 'stanza' } },   	{ 'Stanza class line', '{stanza_class}', { type = 'stanza', classes = { 'ws-poem-stanza_class' } } },   	{ 'Stanza class line, multiple', '{stanza class}', { type = 'stanza', classes = { 'ws-poem-stanza' ,'ws-poem-class' } } },     	{ 'Aligned right stanza line', '>>', { type = 'stanza', align = 'r' } },     	{ 'Aligned center stanza line', '<>', { type = 'stanza', align = 'c' } },     	{ 'Aligned right stanza line with class', '{stanza_class} >>', { type = 'stanza', align = 'r', classes = { 'ws-poem-stanza_class' } } },     	{ 'Aligned center stanza line with class', '{stanza_class} <>', { type = 'stanza', align = 'c', classes = { 'ws-poem-stanza_class' } } },     	{ 'Content line', 'Lorem ipsum', { type = 'line', content = 'Lorem ipsum' } },     	{ 'Classed line', '{line_class} Lorem ipsum', { type = 'line', content = 'Lorem ipsum', classes = { 'ws-poem-line_class' } } },     	{ 'Classed line, multiple', '{line class} Lorem ipsum', { type = 'line', content = 'Lorem ipsum', classes = { 'ws-poem-line', 'ws-poem-class' } } },     	{ 'Aligned right line', '>> Lorem ipsum', { type = 'line', align = 'r', content = 'Lorem ipsum' } },     	{ 'Aligned center line', '<> Lorem ipsum', { type = 'line', align = 'c', content = 'Lorem ipsum' } },     	{ 'Aligned right line with class', '{line_class} >> Lorem ipsum', { type = 'line', align = 'r', classes = { 'ws-poem-line_class' }, content = 'Lorem ipsum' } },     	{ 'Aligned center line with class', '{line_class} <> Lorem ipsum', { type = 'line', align = 'c', classes = { 'ws-poem-line_class' }, content = 'Lorem ipsum' } },     	{ 'Line with verse number', '42 <<< Lorem', { type = 'line', content = 'Lorem', verse_num = '42' } },     	{ 'Line with line number', 'Lorem >>> 13', { type = 'line', content = 'Lorem', line_num = '13' } },     	{ 'Empty line with line number', '>>> 13', { type = 'line', content = '', line_num = '13' } },     	{ 'Indented line with colons', ':::: Lorem', { type = 'line', content = 'Lorem', indent = { em = 4 } } },     	{ 'Indented line with spaces', '    Lorem', { type = 'line', content = 'Lorem', indent = { nbsp = 4 } } },     	{ 'Indented line with colons and class', ':::: {line_class} Lorem', { type = 'line', content = 'Lorem', indent = { em = 4 }, classes={"ws-poem-line_class"} } },     	{ 'Indented line with spaces', '    Lorem', { type = 'line', content = 'Lorem', indent = { nbsp = 4 } } },   }    self:do_line_test(tests) end

return p