diff --git a/spec/parser_spec.lua b/spec/parser_spec.lua new file mode 100644 index 0000000..e37b83f --- /dev/null +++ b/spec/parser_spec.lua @@ -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)