summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2016-07-30 15:23:29 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2016-07-30 15:23:29 +0100
commit6c19bae72fefb677990f3375ff5b9fec5e3c2a2a (patch)
tree15e0d9fcb8de6344664fd81ba391e3ab6f4ff9d4
parentbc16ec6bfbe14700c5f109ca33a744183a567e80 (diff)
downloadtongue-6c19bae72fefb677990f3375ff5b9fec5e3c2a2a.tar.bz2
Add the test files for translit and util
-rw-r--r--test/test-tongue.transliteration.lua66
-rw-r--r--test/test-tongue.util.lua62
2 files changed, 128 insertions, 0 deletions
diff --git a/test/test-tongue.transliteration.lua b/test/test-tongue.transliteration.lua
new file mode 100644
index 0000000..86725b4
--- /dev/null
+++ b/test/test-tongue.transliteration.lua
@@ -0,0 +1,66 @@
+-- test/test-tongue.transliteration.lua
+--
+-- Lua I18N library 'Tongue' -- Tests for the transliteration module
+--
+-- Copyright 2016 Daniel Silverstone <dsilvers@digital-scurf.org>
+--
+-- For Licence terms, see COPYING
+--
+
+-- Step one, start coverage
+
+pcall(require, 'luacov')
+
+local tongue = require 'tongue'
+
+local testnames = {}
+
+local real_assert = assert
+local total_asserts = 0
+local function assert(...)
+ local retval = real_assert(...)
+ total_asserts = total_asserts + 1
+ return retval
+end
+
+local function add_test(suite, name, value)
+ rawset(suite, name, value)
+ testnames[#testnames+1] = name
+end
+
+local suite = setmetatable({}, {__newindex = add_test})
+
+function suite.get_passthru()
+ local pt = tongue.transliteration.get("UTF-8")
+ assert(pt, "Unable to get a passthrough transliterator")
+ assert(pt:touser("다니앨") == "다니앨", "Passthrough mangles Korean")
+ assert(pt:fromuser("다니앨") == "다니앨", "Passthrough mangles Korean")
+end
+
+function suite.get_simple_trans()
+ local st = tongue.transliteration.get("ISO-8859-1")
+ assert(st, "Unable to get a simple transliterator for testing")
+ assert(st:touser("café") == "caf\233", "Unable to transliterate from UTF-8 to Latin 1")
+end
+
+function suite.real_transliterate()
+ local st = tongue.transliteration.get("ASCII")
+ assert(st, "Unable to get a simple transliterator for testing")
+ assert(st:touser("œdipus") == "oedipus", "Unable to transliterate from UTF-8 to ASCII")
+end
+
+local count_ok = 0
+for _, testname in ipairs(testnames) do
+-- print("Run: " .. testname)
+ local ok, err = xpcall(suite[testname], debug.traceback)
+ if not ok then
+ print(err)
+ print()
+ else
+ count_ok = count_ok + 1
+ end
+end
+
+print(tostring(count_ok) .. "/" .. tostring(#testnames) .. " [" .. tostring(total_asserts) .. "] OK")
+
+os.exit(count_ok == #testnames and 0 or 1)
diff --git a/test/test-tongue.util.lua b/test/test-tongue.util.lua
new file mode 100644
index 0000000..0a81eab
--- /dev/null
+++ b/test/test-tongue.util.lua
@@ -0,0 +1,62 @@
+-- test/test-tongue.util.lua
+--
+-- Lua I18N library 'Tongue' -- Tests for the util module
+--
+-- Copyright 2016 Daniel Silverstone <dsilvers@digital-scurf.org>
+--
+-- For Licence terms, see COPYING
+--
+
+-- Step one, start coverage
+
+pcall(require, 'luacov')
+
+local tongue = require 'tongue'
+
+local testnames = {}
+
+local real_assert = assert
+local total_asserts = 0
+local function assert(...)
+ local retval = real_assert(...)
+ total_asserts = total_asserts + 1
+ return retval
+end
+
+local function add_test(suite, name, value)
+ rawset(suite, name, value)
+ testnames[#testnames+1] = name
+end
+
+local suite = setmetatable({}, {__newindex = add_test})
+
+function suite.parse_categories()
+ local categories = {
+ { "en", "en", nil, nil },
+ { "en_GB", "en", "GB", nil },
+ { "en.UTF-8", "en", nil, "UTF-8" },
+ { "en_GB.UTF-8", "en", "GB", "UTF-8" },
+ }
+ for _, cat in ipairs(categories) do
+ local lang, country, charset = tongue.util.split_category(cat[1])
+ assert(lang == cat[2], "Language wrong")
+ assert(country == cat[3], "Country wrong")
+ assert(charset == cat[4], "Charset wrong")
+ end
+end
+
+local count_ok = 0
+for _, testname in ipairs(testnames) do
+-- print("Run: " .. testname)
+ local ok, err = xpcall(suite[testname], debug.traceback)
+ if not ok then
+ print(err)
+ print()
+ else
+ count_ok = count_ok + 1
+ end
+end
+
+print(tostring(count_ok) .. "/" .. tostring(#testnames) .. " [" .. tostring(total_asserts) .. "] OK")
+
+os.exit(count_ok == #testnames and 0 or 1)