Start manual rewrite

This commit is contained in:
Radu Macocian (admac)
2026-03-17 10:13:24 +01:00
parent 70016196c1
commit 7f7b38e394
3 changed files with 57 additions and 760 deletions

42
tests/test_parse_line.lua Normal file
View 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))