diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-11-16 19:12:59 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-16 19:12:59 +0000 |
commit | ae73d813970522f5f3de5399ddde0f1f367c9479 (patch) | |
tree | 44e688977cc8bccd39d8aa6a56009889a5342548 /test/lua | |
parent | 0daf76ab882d2e2bda63a507e075ca05b59ee7f4 (diff) | |
parent | 68badebdac453aef0f8bc5af96e9a289aefc02e5 (diff) | |
download | rspamd-ae73d813970522f5f3de5399ddde0f1f367c9479.tar.gz rspamd-ae73d813970522f5f3de5399ddde0f1f367c9479.zip |
Merge pull request #3553 from fatalbanana/byte
[Minor] rspamd_text:byte() metamethod
Diffstat (limited to 'test/lua')
-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) |