From 29e0faf71b1b718c066d1a5e07c11fac08091fdd Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 1 Jul 2015 16:00:01 +0100 Subject: [PATCH] Add new url unit test. --- test/lua/unit/url.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) 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 -- 2.39.5