mirror of
https://github.com/macocianradu/nvim-http.git
synced 2026-03-18 21:00:05 +00:00
Start manual rewrite
This commit is contained in:
42
tests/test_parse_line.lua
Normal file
42
tests/test_parse_line.lua
Normal file
@@ -0,0 +1,42 @@
|
||||
local M = require('nvim_http')
|
||||
|
||||
-- Test cases
|
||||
local tests = {
|
||||
{"GET https://example.com", "GET", "https://example.com"},
|
||||
{"POST /api/users", "POST", "/api/users"},
|
||||
{"DELETE /api/users/123", "DELETE", "/api/users/123"},
|
||||
{"PUT /api/users/123 body", "PUT", "/api/users/123 body"},
|
||||
{"PATCH https://api.example.com/v1/resource", "PATCH", "https://api.example.com/v1/resource"},
|
||||
{"INVALID", nil, nil},
|
||||
{"", nil, nil},
|
||||
{" ", nil, nil},
|
||||
}
|
||||
|
||||
print("Testing parse_line function:")
|
||||
print("=" .. string.rep("=", 70))
|
||||
|
||||
local passed = 0
|
||||
local failed = 0
|
||||
|
||||
for i, test in ipairs(tests) do
|
||||
local input, expected_a, expected_b = test[1], test[2], test[3]
|
||||
local a, b = M.parse_line(input)
|
||||
|
||||
local success = (a == expected_a and b == expected_b)
|
||||
local status = success and "✓ PASS" or "✗ FAIL"
|
||||
|
||||
if success then
|
||||
passed = passed + 1
|
||||
else
|
||||
failed = failed + 1
|
||||
end
|
||||
|
||||
print(string.format("%s Test %d: '%s'", status, i, input))
|
||||
print(string.format(" Got: a=%s, b=%s", tostring(a), tostring(b)))
|
||||
if not success then
|
||||
print(string.format(" Expected: a=%s, b=%s", tostring(expected_a), tostring(expected_b)))
|
||||
end
|
||||
end
|
||||
|
||||
print("=" .. string.rep("=", 70))
|
||||
print(string.format("Results: %d passed, %d failed", passed, failed))
|
||||
Reference in New Issue
Block a user