diff options
author | Waqas Hussain <waqas20@gmail.com> | 2017-09-15 17:07:57 -0400 |
---|---|---|
committer | Waqas Hussain <waqas20@gmail.com> | 2017-09-15 17:07:57 -0400 |
commit | 67293fc09fea737de37a2fea7b211aa44695b5bf (patch) | |
tree | b5cd2d09f0ee7e1e9e13feec26defe4f7d9f5003 /spec/util_http_spec.lua | |
parent | 4c6c255113df008869577d4ec0291ff880b1273c (diff) | |
download | prosody-67293fc09fea737de37a2fea7b211aa44695b5bf.tar.gz prosody-67293fc09fea737de37a2fea7b211aa44695b5bf.zip |
Port tests to the `busted` test runner
Diffstat (limited to 'spec/util_http_spec.lua')
-rw-r--r-- | spec/util_http_spec.lua | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/spec/util_http_spec.lua b/spec/util_http_spec.lua new file mode 100644 index 00000000..bacfcfb5 --- /dev/null +++ b/spec/util_http_spec.lua @@ -0,0 +1,64 @@ + +local http = require "util.http"; + +describe("util.http", function() + describe("#urlencode()", function() + it("should not change normal characters", function() + assert.are.equal(http.urlencode("helloworld123"), "helloworld123"); + end); + + it("should escape spaces", function() + assert.are.equal(http.urlencode("hello world"), "hello%20world"); + end); + + it("should escape important URL characters", function() + assert.are.equal(http.urlencode("This & that = something"), "This%20%26%20that%20%3d%20something"); + end); + end); + + describe("#urldecode()", function() + it("should not change normal characters", function() + assert.are.equal("helloworld123", http.urldecode("helloworld123"), "Normal characters not escaped"); + end); + + it("should decode spaces", function() + assert.are.equal("hello world", http.urldecode("hello%20world"), "Spaces escaped"); + end); + + it("should decode important URL characters", function() + assert.are.equal("This & that = something", http.urldecode("This%20%26%20that%20%3d%20something"), "Important URL chars escaped"); + end); + end); + + describe("#formencode()", function() + it("should encode basic data", function() + assert.are.equal(http.formencode({ { name = "one", value = "1"}, { name = "two", value = "2" } }), "one=1&two=2", "Form encoded"); + end); + + it("should encode special characters with escaping", function() + assert.are.equal(http.formencode({ { name = "one two", value = "1"}, { name = "two one&", value = "2" } }), "one+two=1&two+one%26=2", "Form encoded"); + end); + end); + + describe("#formdecode()", function() + it("should decode basic data", function() + local t = http.formdecode("one=1&two=2"); + assert.are.same(t, { + { name = "one", value = "1" }; + { name = "two", value = "2" }; + one = "1"; + two = "2"; + }); + end); + + it("should decode special characters", function() + local t = http.formdecode("one+two=1&two+one%26=2"); + assert.are.same(t, { + { name = "one two", value = "1" }; + { name = "two one&", value = "2" }; + ["one two"] = "1"; + ["two one&"] = "2"; + }); + end); + end); +end); |