diff options
| author | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2025-01-24 20:35:27 +0900 |
|---|---|---|
| committer | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2025-01-24 20:35:27 +0900 |
| commit | c80a54e42b52ce297f0f2f71af23c562832025c7 (patch) | |
| tree | dcce8bb977a770f473325d48f6f70b21d9818a40 /ar/.config/mpv/script-modules/utf8/test/util.lua | |
init
Diffstat (limited to 'ar/.config/mpv/script-modules/utf8/test/util.lua')
| -rw-r--r-- | ar/.config/mpv/script-modules/utf8/test/util.lua | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/ar/.config/mpv/script-modules/utf8/test/util.lua b/ar/.config/mpv/script-modules/utf8/test/util.lua new file mode 100644 index 0000000..bdc25e5 --- /dev/null +++ b/ar/.config/mpv/script-modules/utf8/test/util.lua @@ -0,0 +1,75 @@ +require "test.strict" + +local function equals(t1, t2) + for k,v in pairs(t1) do + if t2[k] == nil then return false end + if type(t2[k]) == 'cdata' and type(v) == 'cdata' then + return true -- don't know how to compare + elseif type(t2[k]) == 'table' and type(v) == 'table' then + if not equals(t2[k], v) then return false end + else + if t2[k] ~= v then return false end + end + end + for k,v in pairs(t2) do + if t1[k] == nil then return false end + if type(t1[k]) == 'cdata' and type(v) == 'cdata' then + return true -- don't know how to compare + elseif type(t1[k]) == 'table' and type(v) == 'table' then + if not equals(t1[k], v) then return false end + else + if t1[k] ~= v then return false end + end + end + return true +end + +local old_tostring = tostring +local function tostring(v) + local type = type(v) + if type == 'table' then + local tbl = "{" + for k,v in pairs(v) do + tbl = tbl .. tostring(k) .. ' = ' .. tostring(v) .. ', ' + end + return tbl .. '}' + else + return old_tostring(v) + end +end + +local old_assert = assert +local assert = function(cond, ...) + if not cond then + local data = {...} + local msg = "" + for _, v in pairs(data) do + local type = type(v) + if type == 'table' then + local tbl = "{" + for k,v in pairs(v) do + tbl = tbl .. tostring(k) .. ' = ' .. tostring(v) .. ', ' + end + msg = msg .. tbl .. '}' + else + msg = msg .. tostring(v) + end + end + error(#data > 0 and msg or "assertion failed!") + end + return cond +end + +local function assert_equals(a,b) + assert( + type(a) == 'table' and type(b) == 'table' and equals(a,b) or a == b, + "expected: ", a and a or tostring(a), "\n", + "got: ", b and b or tostring(b) + ) +end + +return { + equals = equals, + assert = assert, + assert_equals = assert_equals, +} |
