Jump to content

Module:IPA/testcases

From Wikipedia, the free encyclopedia
-- Unit tests for [[Module:IPA]]. Click talk page to run tests.
local p = require('Module:UnitTests')

local function getStripMarker(tag)
	return string.format(
		'%s\'"`UNIQ--%s-00000000-QINU`"\'%s',
		string.char(0x7f),
		tag,
		string.char(0x7f)
	)
end

function p:test_all()
	self:preprocess_equals_many('{{IPA/sandbox|', '|debug=yes}}', {
		{
			'foo',
			'<span class="IPA nowrap" lang="und-Latn-fonipa" title="Representation in the International Phonetic Alphabet (IPA)">foo</span>[[:Category:Pages with plain IPA]]'
		},
		{
			'foo|lang=en|class=foo bar|tooltip=Random tooltip',
			'<span class="IPA foo bar nowrap" lang="en-Latn-fonipa" title="Random tooltip">foo</span>[[:Category:Pages with plain IPA]]'
		},
		{
			'foo|bar|tooltip=',
			'<span style="color:#d33">Error: {{[[Template:IPA|IPA]]}}: unrecognized language code: foo</span>[[:Category:IPA template errors]]'
		},
		{
			'foo bar|tooltip=',
			'<span class="IPA nowrap" lang="und-Latn-fonipa">foo<span class="wrap"> </span>bar</span>[[:Category:Pages with plain IPA]]'
		},
		{
			'foo bar|wrap=none|tooltip=',
			'<span class="IPA nowrap" lang="und-Latn-fonipa">foo bar</span>[[:Category:Pages with plain IPA]]'
		},
		{
			'foo bar|wrap=all|tooltip=',
			'<span class="IPA" lang="und-Latn-fonipa">foo bar</span>[[:Category:Pages with plain IPA]]'
		},
		{
			'1=<i style="text-decoration: underline;">foo bar</i>|tooltip=',
			'<span class="IPA nowrap" lang="und-Latn-fonipa"><i style="text-decoration: underline;">foo<span class="wrap"> </span>bar</i></span>[[:Category:Pages with plain IPA]]'
		},
		{
			'[[foo bar]] [[foo bar|baz qux]]|tooltip=',
			'<span class="IPA nowrap" lang="und-Latn-fonipa">[[foo bar|foo<span class="wrap"> </span>bar]]<span class="wrap"> </span>[[foo bar|baz<span class="wrap"> </span>qux]]</span>[[:Category:Pages with plain IPA]]'
		},
		{
			'foo|audio=Example.ogg|tooltip=',
			'<span class="IPA nowrap" lang="und-Latn-fonipa">foo</span> ' .. getStripMarker('phonos') .. '[[:Category:Pages with plain IPA]][[:Category:Pages including recorded pronunciations]]'
		},
		{
			'fr|foo|-|Example.ogg',
			getStripMarker('templatestyles') .. '<span class="IPA-label IPA-label-small">French pronunciation:</span> <span class="IPA nowrap" lang="fr-Latn-fonipa">[[Help:IPA/French|&#91;foo&#93;]]</span> ' .. getStripMarker('phonos') .. '[[:Category:Pages with French IPA]][[:Category:Pages including recorded pronunciations]]'
		},
		{
			'fra|foo|lang',
			getStripMarker('templatestyles') .. '<span class="IPA-label IPA-label-small">French:</span> <span class="IPA nowrap" lang="fr-Latn-fonipa">[[Help:IPA/French|&#91;foo&#93;]]</span>[[:Category:Pages with French IPA]]'
		},
		{
			'fr|foo|',
			'<span class="IPA nowrap" lang="fr-Latn-fonipa">[[Help:IPA/French|&#91;foo&#93;]]</span>[[:Category:Pages with French IPA]]'
		},
		{
			'fr|foo|label=',
			'<span class="IPA nowrap" lang="fr-Latn-fonipa">[[Help:IPA/French|&#91;foo&#93;]]</span>[[:Category:Pages with French IPA]]'
		},
		{
			'fr|foo|label=Random label:|small=no',
			 '<span class="IPA-label">Random label:</span> <span class="IPA nowrap" lang="fr-Latn-fonipa">[[Help:IPA/French|&#91;foo&#93;]]</span>[[:Category:Pages with French IPA]]'
		},
		{
			'fr|foo|link=yes',
			getStripMarker('templatestyles') .. '<span class="IPA-label IPA-label-small">[[French language|French]] pronunciation:</span> <span class="IPA nowrap" lang="fr-Latn-fonipa">[[Help:IPA/French|&#91;foo&#93;]]</span>[[:Category:Pages with French IPA]]'
		},
		{
			'fr|foo|generic=yes',
			getStripMarker('templatestyles') .. '<span class="IPA-label IPA-label-small">French pronunciation:</span> <span class="IPA nowrap" lang="fr-Latn-fonipa">[[Help:IPA|&#91;foo&#93;]]</span>[[:Category:Pages with French IPA]]'
		},
		{
			'en-AU|foo|lang',
			getStripMarker('templatestyles') .. '<span class="IPA-label IPA-label-small">Australian English:</span> <span class="IPA nowrap" lang="en-AU-Latn-fonipa">[[Help:IPA|&#91;foo&#93;]]</span>[[:Category:Pages with Australian English IPA]]'
		},
		{
			'ace|foo',
			getStripMarker('templatestyles') .. '<span class="IPA-label IPA-label-small">Acehnese pronunciation:</span> <span class="IPA nowrap" lang="ace-Latn-fonipa">[[Help:IPA|&#91;foo&#93;]]</span>[[:Category:Pages with Acehnese IPA]]'
		},
		{
			'en|foo',
			'<span class="IPA nowrap" lang="en-Latn-fonipa">[[Help:IPA/English|/foo/]]</span>[[:Category:Pages with English IPA]]'
		},
		{
			'en-uk|foo',
			getStripMarker('templatestyles') .. '<span class="IPA-label IPA-label-small">UK:</span> <span class="IPA nowrap" lang="en-GB-Latn-fonipa">[[Help:IPA/English|/foo/]]</span>[[:Category:Pages with British English IPA]]'
		},
		{
			'en-uk|foo|link=yes',
			getStripMarker('templatestyles') .. '<span class="IPA-label IPA-label-small">[[British English language|UK]]:</span> <span class="IPA nowrap" lang="en-GB-Latn-fonipa">[[Help:IPA/English|/foo/]]</span>[[:Category:Pages with British English IPA]]'
		},
		{
			'sv-FI|foo|lang',
			getStripMarker('templatestyles') .. '<span class="IPA-label IPA-label-small">Finland Swedish:</span> <span class="IPA nowrap" lang="sv-FI-Latn-fonipa">[[Help:IPA/Swedish|&#91;foo&#93;]]</span>[[:Category:Pages with Finland Swedish IPA]]'
		},
		{
			'ca-valencia|foo|lang|link=yes',
			getStripMarker('templatestyles') .. '<span class="IPA-label IPA-label-small">[[Valencian language|Valencian]]:</span> <span class="IPA nowrap" lang="ca-valencia-Latn-fonipa">[[Help:IPA/Catalan|&#91;foo&#93;]]</span>[[:Category:Pages with Valencian IPA]]'
		},
		{
			'grc-x-attic|foo|lang|link=yes',
			getStripMarker('templatestyles') .. '<span class="IPA-label IPA-label-small">[[Attic Greek language|Attic Greek]]:</span> <span class="IPA nowrap" lang="grc-Latn-fonipa">[[Help:IPA/Greek|&#91;foo&#93;]]</span>[[:Category:Pages with Attic Greek IPA]]'
		},
		{
			'grc-x-aeolic|foo|lang|link=yes',
			getStripMarker('templatestyles') .. '<span class="IPA-label IPA-label-small">[[Aeolic Greek language|Aeolic Greek]]:</span> <span class="IPA nowrap" lang="grc-Latn-fonipa">[[Help:IPA|&#91;foo&#93;]]</span>[[:Category:Pages with Aeolic Greek IPA]]'
		},
		{
			'nan-TW|foo|lang|link=yes',
			getStripMarker('templatestyles') .. '<span class="IPA-label IPA-label-small">[[Taiwanese Hokkien language|Taiwanese Hokkien]]:</span> <span class="IPA nowrap" lang="nan-TW-Latn-fonipa">[[Help:IPA/Taiwanese Hokkien|&#91;foo&#93;]]</span>[[:Category:Pages with Taiwanese Hokkien IPA]]'
		},
		{
			'nl-BE|foo|lang|link=yes',
			getStripMarker('templatestyles') .. '<span class="IPA-label IPA-label-small">[[Flemish language|Flemish]]:</span> <span class="IPA nowrap" lang="nl-BE-Latn-fonipa">[[Help:IPA/Dutch|&#91;foo&#93;]]</span>[[:Category:Pages with Flemish IPA]]'
		},
		{
			'myn|foo|lang',
			getStripMarker('templatestyles') .. '<span class="IPA-label IPA-label-small">Mayan:</span> <span class="IPA nowrap" lang="myn-Latn-fonipa">[[Help:IPA/Mayan|&#91;foo&#93;]]</span>[[:Category:Pages with Mayan languages IPA]]'
		},
		{
			'myn|foo|lang|link=yes',
			getStripMarker('templatestyles') .. '<span class="IPA-label IPA-label-small">[[Mayan languages|Mayan]]:</span> <span class="IPA nowrap" lang="myn-Latn-fonipa">[[Help:IPA/Mayan|&#91;foo&#93;]]</span>[[:Category:Pages with Mayan languages IPA]]'
		},
		{
			'aus|foo|lang|link=yes',
			getStripMarker('templatestyles') .. '<span class="IPA-label IPA-label-small">[[Australian languages|Aboriginal]]:</span> <span class="IPA nowrap" lang="aus-Latn-fonipa">[[Help:IPA/Australian languages|&#91;foo&#93;]]</span>[[:Category:Pages with Australian languages IPA]]'
		},
		{
			'und|foo',
			getStripMarker('templatestyles') .. '<span class="IPA-label IPA-label-small">IPA:</span> <span class="IPA nowrap" lang="und-Latn-fonipa">[[Help:IPA|&#91;foo&#93;]]</span>[[:Category:Pages with undetermined IPA]]'
		},
		{
			'en|',
			'<span class="IPA nowrap" lang="und-Latn-fonipa" title="Representation in the International Phonetic Alphabet (IPA)">en</span>[[:Category:Pages with plain IPA]]'
		},
	}, { combined = true, stripmarker = true })
	self:preprocess_equals_preprocess_many('{{IPA-cs|', '}}', '{{IPA|cs|', '}}', {
		{ 'foo' },
		{ 'foo|lang' },
		{ 'foo|-|Example.ogg' },
		{ 'foo|' },
	}, { combined = true, stripmarker = true })
end

return p