Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
vm-001 committed Dec 16, 2023
1 parent 9357f0d commit 5964033
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions spec/parser_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'busted.runner'()

local Parser = require "router-tree.parser"

local function parse(parser)
local tokens = {}
local token = parser:next()
while token do
table.insert(tokens, token)
token = parser:next()
end
return tokens
end

describe("parser", function()
it("sanity", function()
local tests = {
{
path = "/info/:user/project/:sub",
tokens = { "/info/", ":user", "/project/", ":sub" },
},
{
path = "/api/v1/pay/*",
tokens = { "/api/v1/pay/", "*" },
},
{
path = "/api/v1/pay/*path",
tokens = { "/api/v1/pay/", "*path" },
},
{
path = "/api/v1/users/:id/*",
tokens = { "/api/v1/users/", ":id", "/", "*" },
},
{
path = "/api/v1/users/:id/*path",
tokens = { "/api/v1/users/", ":id", "/", "*path" },
}
}

for _, test in ipairs(tests) do
local parser = Parser.new(test.path)
assert(test.tokens, parse(parser))
end
end)
end)

0 comments on commit 5964033

Please sign in to comment.