@@ -21,13 +21,19 @@ local function urlencode(list)
2121 return table.concat (result , " &" )
2222end
2323
24+ local function checkcode (code , expected )
25+ if code ~= expected then
26+ error (" expected code " .. expected .. " , got " .. tostring (code ))
27+ end
28+ end
29+
2430math.randomseed (os.time ())
2531
2632-- Tests function
2733
2834local function test_download_json ()
2935 local code , response = https .request (" https://raw.githubusercontent.com/rxi/json.lua/master/json.lua" )
30- assert (code == 200 , " expected code 200, got " .. code )
36+ checkcode (code , 200 )
3137 json = assert (loadstring (response , " =json.lua" ))()
3238end
3339
@@ -45,7 +51,7 @@ local function test_custom_header()
4551 [headerName ] = tostring (random )
4652 }
4753 })
48- assert (code == 200 , " expected code 200, got " .. code )
54+ checkcode (code , 200 )
4955 local root = json .decode (response )
5056
5157 -- Headers are case-insensitive
@@ -77,7 +83,7 @@ local function test_send(method, kind)
7783 method = method
7884 })
7985
80- assert (code == 200 , " expected code 200, got " .. code )
86+ checkcode (code , 200 )
8187 local root = json .decode (response )
8288
8389 for k , v in pairs (data ) do
8995-- Tests call
9096print (" test downloading json library" ) test_download_json ()
9197print (" test custom header" ) test_custom_header ()
98+ print (" test HEAD" ) test_head ()
9299
93100for _ , method in ipairs ({" POST" , " PUT" , " PATCH" , " DELETE" }) do
94101 for _ , kind in ipairs ({" form" , " json" }) do
0 commit comments