diff options
author | Matthew Wild <mwild1@gmail.com> | 2011-08-10 17:49:37 -0400 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2011-08-10 17:49:37 -0400 |
commit | bc2d1fe944f50bf73730aaff0e682a50c8223236 (patch) | |
tree | 76e44e84a6e832ced42ddecd589409d21b34a2e9 | |
parent | fad05ab1c7d6e083c379ce010e931279c64d023c (diff) | |
download | prosody-bc2d1fe944f50bf73730aaff0e682a50c8223236.tar.gz prosody-bc2d1fe944f50bf73730aaff0e682a50c8223236.zip |
tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
-rw-r--r-- | tests/test.lua | 2 | ||||
-rw-r--r-- | tests/test_net_http.lua | 37 |
2 files changed, 39 insertions, 0 deletions
diff --git a/tests/test.lua b/tests/test.lua index ae5b24f0..000c3ee9 100644 --- a/tests/test.lua +++ b/tests/test.lua @@ -9,8 +9,10 @@ function run_all_tests() + package.loaded["net.connlisteners"] = { get = function () return {} end }; dotest "util.jid" dotest "util.multitable" + dotest "net.http" dotest "core.modulemanager" dotest "core.stanza_router" dotest "core.s2smanager" diff --git a/tests/test_net_http.lua b/tests/test_net_http.lua new file mode 100644 index 00000000..e68f96e9 --- /dev/null +++ b/tests/test_net_http.lua @@ -0,0 +1,37 @@ +-- Prosody IM +-- Copyright (C) 2008-2010 Matthew Wild +-- Copyright (C) 2008-2010 Waqas Hussain +-- +-- This project is MIT/X11 licensed. Please see the +-- COPYING file in the source package for more information. +-- + +function urlencode(urlencode) + assert_equal(urlencode("helloworld123"), "helloworld123", "Normal characters not escaped"); + assert_equal(urlencode("hello world"), "hello%20world", "Spaces escaped"); + assert_equal(urlencode("This & that = something"), "This%20%26%20that%20%3d%20something", "Important URL chars escaped"); +end + +function urldecode(urldecode) + assert_equal("helloworld123", urldecode("helloworld123"), "Normal characters not escaped"); + assert_equal("hello world", urldecode("hello%20world"), "Spaces escaped"); + assert_equal("This & that = something", urldecode("This%20%26%20that%20%3d%20something"), "Important URL chars escaped"); + assert_equal("This & that = something", urldecode("This%20%26%20that%20%3D%20something"), "Important URL chars escaped"); +end + +function formencode(formencode) + assert_equal(formencode({ { name = "one", value = "1"}, { name = "two", value = "2" } }), "one=1&two=2", "Form encoded"); + assert_equal(formencode({ { name = "one two", value = "1"}, { name = "two one&", value = "2" } }), "one+two=1&two+one%26=2", "Form encoded"); +end + +function formdecode(formdecode) + local t = formdecode("one=1&two=2"); + assert_table(t[1]); + assert_equal(t[1].name, "one"); assert_equal(t[1].value, "1"); + assert_table(t[2]); + assert_equal(t[2].name, "two"); assert_equal(t[2].value, "2"); + + local t = formdecode("one+two=1&two+one%26=2"); + assert_equal(t[1].name, "one two"); assert_equal(t[1].value, "1"); + assert_equal(t[2].name, "two one&"); assert_equal(t[2].value, "2"); +end |