From d0c7c5b0dd9d20bfc323dc10c67f9de12d58c343 Mon Sep 17 00:00:00 2001 From: ame Date: Mon, 26 Aug 2024 22:33:07 -0500 Subject: initial param matching --- tests/net.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests') diff --git a/tests/net.lua b/tests/net.lua index 25ca696..fdb17d4 100644 --- a/tests/net.lua +++ b/tests/net.lua @@ -17,6 +17,14 @@ net.listen( io.pprint("online") _G.server = server + + server:all("/{name}", function(res, req) + print("name is "..req.name) + end) + server:all("*", function(res, req) + print("all") + end) + server:all("/", function(res, req) b = crypto.md5("hello") -- cgit v1.2.3 From 4f0b3173cae639de5874afaf2df6ab113c7277fd Mon Sep 17 00:00:00 2001 From: amelia squires Date: Thu, 29 Aug 2024 00:10:05 -0500 Subject: should be working + tests --- tests/match.lua | 37 +++++++++++++++++++++++++++++++++++++ tests/net.lua | 13 ++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 tests/match.lua (limited to 'tests') diff --git a/tests/match.lua b/tests/match.lua new file mode 100644 index 0000000..d9c1533 --- /dev/null +++ b/tests/match.lua @@ -0,0 +1,37 @@ +llb = require "lullaby" + +function test(a, b, match, expect) + res, out = llb.test._match(a, b) + + if res ~= match then + return llb.io.error("res != match") + end + + if res == 0 then return end + + if llb.array.len(out) ~= llb.array.len(expect) then + return llb.io.error("out != expect") + end + + for i, v in ipairs(expect) do + if v ~= out[i] then + return llb.io.error("out != expect") + end + end + llb.io.pprint(out) +end + +test("/{test}/","/name/", 1, {test="name"}) +test("*","/wdejowe/wde", 1, {}) +test("/*/{hello}/{meow}/end","/blah/blah/hii/end", 1, {hello="blah", meow="hii"}) +test("/*/*/{test}/*/*/end/*/real","/a/b/testing/d/e/end/f/real", 1, {test="testing"}) +test("/*/a/b/end/{word}","/w/o/m/p/a/b/end/meow", 1, {word="meow"}) +test("*", "meow/meow/meow", 1, {}) +test("{meow}", "owo", 1, {meow="owo"}) +test("/{meow}", "/owo", 1, {meow="owo"}) +test("{meow}", "/", 0) +test("/{meow}", "/", 0) + + + + diff --git a/tests/net.lua b/tests/net.lua index fdb17d4..940e2fb 100644 --- a/tests/net.lua +++ b/tests/net.lua @@ -19,12 +19,23 @@ net.listen( _G.server = server server:all("/{name}", function(res, req) - print("name is "..req.name) + --print("name is "..req.name) + print("name") end) + + server:all("/{name}/nya/{user}", function(res, req) + --print("name is "..req.name) + print("name id user") + end) + server:all("*", function(res, req) print("all") end) + server:all("/{name}/user/*/{id}", function(res, req) + print("owo") + end) + server:all("/", function(res, req) b = crypto.md5("hello") -- cgit v1.2.3 From 994225cdb84e6d145200266ea4386391684edd10 Mon Sep 17 00:00:00 2001 From: ame Date: Sun, 1 Sep 2024 20:18:34 -0500 Subject: clean --- tests/match.lua | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/match.lua b/tests/match.lua index d9c1533..000b1e7 100644 --- a/tests/match.lua +++ b/tests/match.lua @@ -2,13 +2,17 @@ llb = require "lullaby" function test(a, b, match, expect) res, out = llb.test._match(a, b) + + if res == 0 and res == match then return end - if res ~= match then - return llb.io.error("res != match") + if res ~= match then + return llb.io.error(a..":"..b.." res("..res..") != expected") end - if res == 0 then return end - + if res == 0 then + return llb.io.error(a..":"..b.." res == match") + end + if llb.array.len(out) ~= llb.array.len(expect) then return llb.io.error("out != expect") end @@ -18,10 +22,10 @@ function test(a, b, match, expect) return llb.io.error("out != expect") end end - llb.io.pprint(out) end test("/{test}/","/name/", 1, {test="name"}) +test("/", "/wawawawawawaw", 0) test("*","/wdejowe/wde", 1, {}) test("/*/{hello}/{meow}/end","/blah/blah/hii/end", 1, {hello="blah", meow="hii"}) test("/*/*/{test}/*/*/end/*/real","/a/b/testing/d/e/end/f/real", 1, {test="testing"}) @@ -31,7 +35,8 @@ test("{meow}", "owo", 1, {meow="owo"}) test("/{meow}", "/owo", 1, {meow="owo"}) test("{meow}", "/", 0) test("/{meow}", "/", 0) - - - +test("/*/", "/test", 0) +test("/{meow}/", "/aw", 0) +--i dont know if this should be valid, but idc +test("/{meow}/", "//", 1, {meow=""}) -- cgit v1.2.3 From af2da4242cfe192e49ee490d8dd3a3b7fff02000 Mon Sep 17 00:00:00 2001 From: amelia squires Date: Wed, 4 Sep 2024 01:17:25 -0500 Subject: add to server, and fix leaks --- tests/net.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/net.lua b/tests/net.lua index 940e2fb..90a18c3 100644 --- a/tests/net.lua +++ b/tests/net.lua @@ -21,19 +21,24 @@ net.listen( server:all("/{name}", function(res, req) --print("name is "..req.name) print("name") + io.pprint(req.paramaters) end) server:all("/{name}/nya/{user}", function(res, req) --print("name is "..req.name) - print("name id user") + print("name user") + io.pprint(req.paramaters) end) server:all("*", function(res, req) print("all") + io.pprint(req.paramaters) end) server:all("/{name}/user/*/{id}", function(res, req) print("owo") + io.pprint(req.paramaters) + end) server:all("/", function(res, req) -- cgit v1.2.3