diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-07-01 16:00:01 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-07-01 16:00:01 +0100 |
commit | 307cb52ff8d2d5a258515531ebdbf9afdad3ba73 (patch) | |
tree | a343da8d77ba28f5a6986c78b7f7e188bc87b8f3 /test/lua | |
parent | 66f1f01a9bb93a72a24302bbe70038441fb96d11 (diff) | |
download | rspamd-307cb52ff8d2d5a258515531ebdbf9afdad3ba73.tar.gz rspamd-307cb52ff8d2d5a258515531ebdbf9afdad3ba73.zip |
Add new url unit test.
Diffstat (limited to 'test/lua')
-rw-r--r-- | test/lua/unit/url.lua | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/lua/unit/url.lua b/test/lua/unit/url.lua index d56d06405..d162e2dc5 100644 --- a/test/lua/unit/url.lua +++ b/test/lua/unit/url.lua @@ -48,4 +48,37 @@ context("URL check functions", function() pool:destroy() end) + -- Some cases from https://code.google.com/p/google-url/source/browse/trunk/src/url_canon_unittest.cc + test("Parse urls", function() + local pool = mpool.create() + -- input, parseable, {host, port, user, password, path, query, part} + local cases = { + {"http://www.google.com/foo?bar=baz#", true, { + host = 'www.google.com', path = 'foo', query = 'bar=baz', tld = 'google.com'} + }, + } + + for _,c in ipairs(cases) do + local res = url.create(pool, c[1]) + + if c[2] then + assert_not_nil(res, "cannot parse " .. c[1]) + + local uf = res:to_table() + + for k,v in pairs(c[3]) do + assert_not_nil(uf[k], k .. ' is missing in url, must be ' .. v) + assert_equal(uf[k], v) + end + for k,v in pairs(uf) do + if k ~= 'url' and k ~= 'protocol' and k ~= 'tld' then + assert_not_nil(c[3][k], k .. ' should be absent but it is ' .. v) + end + end + else + assert_nil(res, "should not parse " .. c[1]) + end + end + end + ) end)
\ No newline at end of file |