diff options
author | Andrew Lewis <nerf@judo.za.org> | 2020-11-16 20:13:03 +0200 |
---|---|---|
committer | Andrew Lewis <nerf@judo.za.org> | 2020-11-16 20:13:03 +0200 |
commit | 68badebdac453aef0f8bc5af96e9a289aefc02e5 (patch) | |
tree | b746ea582bd0e32c8a85af93c264ad2d8158045b /test | |
parent | 36963c3fa3b053812dbb9abea386b27a78a5d062 (diff) | |
download | rspamd-68badebdac453aef0f8bc5af96e9a289aefc02e5.tar.gz rspamd-68badebdac453aef0f8bc5af96e9a289aefc02e5.zip |
[Minor] rspamd_text:byte() metamethod
Diffstat (limited to 'test')
-rw-r--r-- | test/lua/unit/rspamd_text.lua | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/lua/unit/rspamd_text.lua b/test/lua/unit/rspamd_text.lua new file mode 100644 index 000000000..269b49150 --- /dev/null +++ b/test/lua/unit/rspamd_text.lua @@ -0,0 +1,30 @@ +context("Rspamd_text:byte() test", function() + local lua_util = require "lua_util" + local rspamd_text = require "rspamd_text" + + local str = 'OMG' + local txt = rspamd_text.fromstring(str) + local fmt = 'case rspamd_text:byte(%s,%s)' + local cases = { + {'1', 'nil'}, + {'nil', '1'}, + } + + for start = -4, 4 do + for stop = -4, 4 do + table.insert(cases, {tostring(start), tostring(stop)}) + end + end + + for _, case in ipairs(cases) do + local name = string.format(fmt, case[1], case[2]) + test(name, function() + local txt_bytes = {txt:byte(tonumber(case[1]), tonumber(case[2]))} + local str_bytes = {str:byte(tonumber(case[1]), tonumber(case[2]))} + assert_rspamd_table_eq({ + expect = str_bytes, + actual = txt_bytes + }) + end) + end +end) |