From: Vsevolod Stakhov Date: Wed, 1 Jul 2015 15:00:01 +0000 (+0100) Subject: Add new url unit test. X-Git-Tag: 1.0.0~467 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=307cb52ff8d2d5a258515531ebdbf9afdad3ba73;p=thirdparty%2Frspamd.git Add new url unit test. --- diff --git a/test/lua/unit/url.lua b/test/lua/unit/url.lua index d56d064050..d162e2dc5e 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