Comparison

tests/test_net_http.lua @ 4339:63304d323983

tests/test.lua, tests/test_net_http.lua: Tests for net.http's url and form encoding/decoding functions
author Matthew Wild <mwild1@gmail.com>
date Wed, 10 Aug 2011 17:49:37 -0400
comparison
equal deleted inserted replaced
4338:5d5d6c6d121a 4339:63304d323983
1 -- Prosody IM
2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
4 --
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
7 --
8
9 function urlencode(urlencode)
10 assert_equal(urlencode("helloworld123"), "helloworld123", "Normal characters not escaped");
11 assert_equal(urlencode("hello world"), "hello%20world", "Spaces escaped");
12 assert_equal(urlencode("This & that = something"), "This%20%26%20that%20%3d%20something", "Important URL chars escaped");
13 end
14
15 function urldecode(urldecode)
16 assert_equal("helloworld123", urldecode("helloworld123"), "Normal characters not escaped");
17 assert_equal("hello world", urldecode("hello%20world"), "Spaces escaped");
18 assert_equal("This & that = something", urldecode("This%20%26%20that%20%3d%20something"), "Important URL chars escaped");
19 assert_equal("This & that = something", urldecode("This%20%26%20that%20%3D%20something"), "Important URL chars escaped");
20 end
21
22 function formencode(formencode)
23 assert_equal(formencode({ { name = "one", value = "1"}, { name = "two", value = "2" } }), "one=1&two=2", "Form encoded");
24 assert_equal(formencode({ { name = "one two", value = "1"}, { name = "two one&", value = "2" } }), "one+two=1&two+one%26=2", "Form encoded");
25 end
26
27 function formdecode(formdecode)
28 local t = formdecode("one=1&two=2");
29 assert_table(t[1]);
30 assert_equal(t[1].name, "one"); assert_equal(t[1].value, "1");
31 assert_table(t[2]);
32 assert_equal(t[2].name, "two"); assert_equal(t[2].value, "2");
33
34 local t = formdecode("one+two=1&two+one%26=2");
35 assert_equal(t[1].name, "one two"); assert_equal(t[1].value, "1");
36 assert_equal(t[2].name, "two one&"); assert_equal(t[2].value, "2");
37 end