2 local http
= require
"util.http";
4 describe("util.http", function()
5 describe("#urlencode()", function()
6 it("should not change normal characters", function()
7 assert.are
.equal(http
.urlencode("helloworld123"), "helloworld123");
10 it("should escape spaces", function()
11 assert.are
.equal(http
.urlencode("hello world"), "hello%20world");
14 it("should escape important URL characters", function()
15 assert.are
.equal(http
.urlencode("This & that = something"), "This%20%26%20that%20%3d%20something");
19 describe("#urldecode()", function()
20 it("should not change normal characters", function()
21 assert.are
.equal("helloworld123", http
.urldecode("helloworld123"), "Normal characters not escaped");
24 it("should decode spaces", function()
25 assert.are
.equal("hello world", http
.urldecode("hello%20world"), "Spaces escaped");
28 it("should decode important URL characters", function()
29 assert.are
.equal("This & that = something", http
.urldecode("This%20%26%20that%20%3d%20something"), "Important URL chars escaped");
32 it("should decode both lower and uppercase", function ()
33 assert.are
.equal("This & that = {something}.", http
.urldecode("This%20%26%20that%20%3D%20%7Bsomething%7D%2E"), "Important URL chars escaped");
38 describe("#formencode()", function()
39 it("should encode basic data", function()
40 assert.are
.equal(http
.formencode({ { name
= "one", value
= "1"}, { name
= "two", value
= "2" } }), "one=1&two=2", "Form encoded");
43 it("should encode special characters with escaping", function()
44 assert.are
.equal(http
.formencode({ { name
= "one two", value
= "1"}, { name
= "two one&", value
= "2" } }), "one+two=1&two+one%26=2", "Form encoded");
48 describe("#formdecode()", function()
49 it("should decode basic data", function()
50 local t
= http
.formdecode("one=1&two=2");
52 { name
= "one", value
= "1" };
53 { name
= "two", value
= "2" };
59 it("should decode special characters", function()
60 local t
= http
.formdecode("one+two=1&two+one%26=2");
62 { name
= "one two", value
= "1" };
63 { name
= "two one&", value
= "2" };
70 describe("normalize_path", function ()
71 it("root path is always '/'", function ()
72 assert.equal("/", http
.normalize_path("/"));
73 assert.equal("/", http
.normalize_path(""));
74 assert.equal("/", http
.normalize_path("/", true));
75 assert.equal("/", http
.normalize_path("", true));
78 it("works", function ()
79 assert.equal("/foo", http
.normalize_path("foo"));
80 assert.equal("/foo", http
.normalize_path("/foo"));
81 assert.equal("/foo", http
.normalize_path("foo/"));
82 assert.equal("/foo", http
.normalize_path("/foo/"));
85 it("is_dir works", function ()
86 assert.equal("/foo/", http
.normalize_path("foo", true));
87 assert.equal("/foo/", http
.normalize_path("/foo", true));
88 assert.equal("/foo/", http
.normalize_path("foo/", true));
89 assert.equal("/foo/", http
.normalize_path("/foo/", true));