Module:vi/testcases

From Wiktionary, the free dictionary
Jump to navigation Jump to search

All tests passed. (refresh)

TextExpectedActual
test_comp:
Passed(sorting){"Ả Rập", "Á Châu", "an ninh", "ánh sáng", "ăn", "bóng đá", "bóng rổ"}{"Ả Rập", "Á Châu", "an ninh", "ánh sáng", "ăn", "bóng đá", "bóng rổ"}
Passed(sorting){"bọ mắt", "chí lý", "ly lông", "tháng trời", "vi lượng đồng căn"}{"bọ mắt", "chí lý", "ly lông", "tháng trời", "vi lượng đồng căn"}
Passed(sorting){"bọ mắt", "chí lý", "đá", "ly lông", "tháng trời", "vi lượng đồng căn"}{"bọ mắt", "chí lý", "đá", "ly lông", "tháng trời", "vi lượng đồng căn"}
TextExpectedActual
test_removeDiacritics:
Passed{{#invoke:vi|removeDiacritics|thay đổi gần đây}}thay doi gan daythay doi gan day
Passed{{#invoke:vi|removeDiacritics|thay đổi gần đây|tones=0}}thay dỏi gàn daythay dỏi gàn day
Passed{{#invoke:vi|removeDiacritics|thay đổi gần đây|accents=0}}thay dôi gân dâythay dôi gân dây
Passed{{#invoke:vi|removeDiacritics|thay đổi gần đây|đ=0}}thay đoi gan đaythay đoi gan đay
Passed{{#invoke:vi|removeDiacritics|thay đổi gần đây|tones=1|accents=1|đ=1}}thay doi gan daythay doi gan day
Passed{{#invoke:vi|removeDiacritics|thay đổi gần đây|tones=0|accents=0|đ=0}}thay đổi gần đâythay đổi gần đây
TextExpectedActual
test_shiftTones:
Passedxóa to reformed tonesxoáxoá
Passedcúi to reformed tonescúicúi
Passedxoá to traditional tonesxóaxóa
Passedquỹ to traditional tonesquỹquỹ

-- Unit tests for [[Module:vi]]. Click talk page to run tests.
local p = require("Module:UnitTests")
local m_vi = require("Module:vi")

-- helper functions

function p:check_sort(input, expected)
    table.sort(input, m_vi.comp)
    self:equals_deep("(sorting)", input, expected)
end

function p:check_to_ref_tones(vi, expected)
	self:equals('<i class="Latn mention" lang="vi">[[' .. vi .. '#Vietnamese|' .. vi .. ']]</i> to reformed tones', m_vi.toReformedTones(vi), expected)
end

function p:check_to_trad_tones(vi, expected)
	self:equals('<i class="Latn mention" lang="vi">[[' .. vi .. '#Vietnamese|' .. vi .. ']]</i> to traditional tones', m_vi.toTraditionalTones(vi), expected)
end

-- tests

function p:test_shiftTones()
    self:check_to_ref_tones("xóa", "xoá")
    self:check_to_ref_tones("cúi", "cúi")
    self:check_to_trad_tones("xoá", "xóa")
    self:check_to_trad_tones("quỹ", "quỹ")
end

function p:test_removeDiacritics()
    self:preprocess_equals("{{#invoke:vi|removeDiacritics|thay đổi gần đây}}", "thay doi gan day")
    self:preprocess_equals("{{#invoke:vi|removeDiacritics|thay đổi gần đây|tones=0}}", "thay dỏi gàn day")
    self:preprocess_equals("{{#invoke:vi|removeDiacritics|thay đổi gần đây|accents=0}}", "thay dôi gân dây")
    self:preprocess_equals("{{#invoke:vi|removeDiacritics|thay đổi gần đây|đ=0}}", "thay đoi gan đay")
    self:preprocess_equals("{{#invoke:vi|removeDiacritics|thay đổi gần đây|tones=1|accents=1|đ=1}}", "thay doi gan day")
    self:preprocess_equals("{{#invoke:vi|removeDiacritics|thay đổi gần đây|tones=0|accents=0|đ=0}}", "thay đổi gần đây")
end

function p:test_comp()
    self:check_sort({"an ninh", "bóng rổ", "Ả Rập", "bóng đá", "ăn", "Á Châu", "ánh sáng"},
        {"Ả Rập", "Á Châu", "an ninh", "ánh sáng", "ăn", "bóng đá", "bóng rổ"})
    self:check_sort({"bọ mắt", "chí lý", "vi lượng đồng căn", "ly lông", "tháng trời"},
        {"bọ mắt", "chí lý", "ly lông", "tháng trời", "vi lượng đồng căn"})
    self:check_sort({"bọ mắt", "chí lý", "đá", "vi lượng đồng căn", "ly lông", "tháng trời"},
        {"bọ mắt", "chí lý", "đá", "ly lông", "tháng trời", "vi lượng đồng căn"})
end

function p.sampleComp(frame)
	local t = {"an ninh", "bóng rổ", "Ả Rập", "bóng đá", "ăn", "Á Châu"}
	table.sort(t, m_vi.comp)
	return table.concat(t, ", ")
end

return p