Mercurial > prosody-hg
comparison spec/util_http_spec.lua @ 8236:4878e4159e12
Port tests to the `busted` test runner
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Fri, 15 Sep 2017 17:07:57 -0400 |
| parents | |
| children | 5203b6fd34d4 |
comparison
equal
deleted
inserted
replaced
| 8235:7d9a2c200736 | 8236:4878e4159e12 |
|---|---|
| 1 | |
| 2 local http = require "util.http"; | |
| 3 | |
| 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"); | |
| 8 end); | |
| 9 | |
| 10 it("should escape spaces", function() | |
| 11 assert.are.equal(http.urlencode("hello world"), "hello%20world"); | |
| 12 end); | |
| 13 | |
| 14 it("should escape important URL characters", function() | |
| 15 assert.are.equal(http.urlencode("This & that = something"), "This%20%26%20that%20%3d%20something"); | |
| 16 end); | |
| 17 end); | |
| 18 | |
| 19 describe("#urldecode()", function() | |
| 20 it("should not change normal characters", function() | |
| 21 assert.are.equal("helloworld123", http.urldecode("helloworld123"), "Normal characters not escaped"); | |
| 22 end); | |
| 23 | |
| 24 it("should decode spaces", function() | |
| 25 assert.are.equal("hello world", http.urldecode("hello%20world"), "Spaces escaped"); | |
| 26 end); | |
| 27 | |
| 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"); | |
| 30 end); | |
| 31 end); | |
| 32 | |
| 33 describe("#formencode()", function() | |
| 34 it("should encode basic data", function() | |
| 35 assert.are.equal(http.formencode({ { name = "one", value = "1"}, { name = "two", value = "2" } }), "one=1&two=2", "Form encoded"); | |
| 36 end); | |
| 37 | |
| 38 it("should encode special characters with escaping", function() | |
| 39 assert.are.equal(http.formencode({ { name = "one two", value = "1"}, { name = "two one&", value = "2" } }), "one+two=1&two+one%26=2", "Form encoded"); | |
| 40 end); | |
| 41 end); | |
| 42 | |
| 43 describe("#formdecode()", function() | |
| 44 it("should decode basic data", function() | |
| 45 local t = http.formdecode("one=1&two=2"); | |
| 46 assert.are.same(t, { | |
| 47 { name = "one", value = "1" }; | |
| 48 { name = "two", value = "2" }; | |
| 49 one = "1"; | |
| 50 two = "2"; | |
| 51 }); | |
| 52 end); | |
| 53 | |
| 54 it("should decode special characters", function() | |
| 55 local t = http.formdecode("one+two=1&two+one%26=2"); | |
| 56 assert.are.same(t, { | |
| 57 { name = "one two", value = "1" }; | |
| 58 { name = "two one&", value = "2" }; | |
| 59 ["one two"] = "1"; | |
| 60 ["two one&"] = "2"; | |
| 61 }); | |
| 62 end); | |
| 63 end); | |
| 64 end); |
