diff options
| author | amelia squires <[email protected]> | 2024-09-08 05:13:11 -0500 |
|---|---|---|
| committer | amelia squires <[email protected]> | 2024-09-08 05:13:11 -0500 |
| commit | e9cb2e0f75cbfa6bde188b9e043ebfd8d30b9451 (patch) | |
| tree | 57368ce9ae49e89809171dc6ae85fde936a2b5f2 /tests | |
| parent | 6ca752754556c44c485c4534b5f3453c7a1490c7 (diff) | |
| parent | ab5c24cd0eb59b704cf98d388338293db3768c81 (diff) | |
merge rewrite-net-route-matching
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/match.lua | 42 | ||||
| -rw-r--r-- | tests/net.lua | 24 |
2 files changed, 66 insertions, 0 deletions
diff --git a/tests/match.lua b/tests/match.lua new file mode 100644 index 0000000..000b1e7 --- /dev/null +++ b/tests/match.lua @@ -0,0 +1,42 @@ +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(a..":"..b.." res("..res..") != expected") + 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 + + for i, v in ipairs(expect) do + if v ~= out[i] then + return llb.io.error("out != expect") + end + end +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"}) +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) +test("/*/", "/test", 0) +test("/{meow}/", "/aw", 0) +--i dont know if this should be valid, but idc +test("/{meow}/", "//", 1, {meow=""}) + diff --git a/tests/net.lua b/tests/net.lua index 25ca696..90a18c3 100644 --- a/tests/net.lua +++ b/tests/net.lua @@ -17,6 +17,30 @@ net.listen( io.pprint("online")
_G.server = server
+
+ 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 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)
b = crypto.md5("hello")
|
