local u=require("\046\046\047\046\046\047\116\101\115\116\107\105\116")local C=require("\105\110\105\116")local N,O,M,F=u.test()N("\117\114\108",function()do O("\101\110\099\111\100\101 \037\037\050\048")M(C.encode("\074\101 \115\117\105\115 \097\108\108\195\169 \097\117 \099\105\110\195\169\109\097\046")=="\074\101\037\050\048\115\117\105\115\037\050\048\097\108\108\037\067\051\037\065\057\037\050\048\097\117\037\050\048\099\105\110\037\067\051\037\065\057\109\097\046")end do O("\101\110\099\111\100\101 \043")M(C.encode("\074\101 \115\117\105\115 \097\108\108\195\169 \097\117 \099\105\110\195\169\109\097\046","\043")=="\074\101\043\115\117\105\115\043\097\108\108\037\067\051\037\065\057\043\097\117\043\099\105\110\037\067\051\037\065\057\109\097\046")end do O("\101\110\099\111\100\101 \043 \099\104\097\114")M(C.encode("\043")=="\037\050\066")end do O("\100\101\099\111\100\101 \037\037\050\048")M(C.decode("\074\101\037\050\048\115\117\105\115\037\050\048\097\108\108\037\067\051\037\065\057\037\050\048\097\117\037\050\048\099\105\110\037\067\051\037\065\057\109\097\046")=="\074\101 \115\117\105\115 \097\108\108\195\169 \097\117 \099\105\110\195\169\109\097\046")end do O("\100\101\099\111\100\101 \043 \099\104\097\114")M(C.decode("\037\050\066")=="\043")end do O("\100\101\099\111\100\101 \043")M(C.decode("\074\101\043\115\117\105\115\043\097\108\108\037\067\051\037\065\057\043\097\117\043\099\105\110\037\067\051\037\065\057\109\097\046")=="\074\101 \115\117\105\115 \097\108\108\195\169 \097\117 \099\105\110\195\169\109\097\046")end do O("\113\117\101\114\121\105\102\121")local u=C.queryify({meow="\109\114\114\112",mrrp="\109\101\111\119"})M(u=="\063\109\101\111\119\061\109\114\114\112\038\109\114\114\112\061\109\101\111\119")end do O("\114\101\097\100\095\113\117\101\114\121")local u="\063\109\101\111\119\061\109\114\114\112\038\109\114\114\112\061\109\101\111\119"local N=C.read_query(u)M(N.meow=="\109\114\114\112"and N.mrrp=="\109\101\111\119")end end)
local testkit = require("../../testkit")
local url = require("init")

local TEST, CASE, CHECK, FINISH = testkit.test()

TEST("url", function()
	do CASE("encode %%20")
		CHECK(url.encode("Je suis allé au cinéma.") == "Je%20suis%20all%C3%A9%20au%20cin%C3%A9ma.")
	end

	do CASE("encode +")
		CHECK(url.encode("Je suis allé au cinéma.", "+") == "Je+suis+all%C3%A9+au+cin%C3%A9ma.")
	end

	do CASE("encode + char")
		CHECK(url.encode("+") == "%2B")
	end

	do CASE("decode %%20")
		CHECK(url.decode("Je%20suis%20all%C3%A9%20au%20cin%C3%A9ma.") == "Je suis allé au cinéma.")
	end

	do CASE("decode + char")
		CHECK(url.decode("%2B") == "+")
	end

	do CASE("decode +")
		CHECK(url.decode("Je+suis+all%C3%A9+au+cin%C3%A9ma.") == "Je suis allé au cinéma.")
	end

	do CASE("queryify")
		local query = url.queryify({
			meow = "mrrp",
			mrrp = "meow"
		})
		
		CHECK(query == "?meow=mrrp&mrrp=meow")
	end

	do CASE("read_query")
		local query = "?meow=mrrp&mrrp=meow"
		local tbl = url.read_query(query)

		CHECK(tbl.meow == "mrrp" and tbl.mrrp == "meow")
	end

end)