aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorame <[email protected]>2024-08-03 02:30:02 -0500
committerame <[email protected]>2024-08-03 02:30:02 -0500
commit37dc46c19843f3328e06c7199548238f056c1a6b (patch)
treecbfee9fffc70d07bfd6b632e1f73b17da19d578c /tests
parent3aaf4185c489830ff6c56c9a359584d5003f92ec (diff)
fix tests, module based require, thread improvments
Diffstat (limited to 'tests')
-rw-r--r--tests/h.lua34
-rw-r--r--tests/hash.lua2
-rw-r--r--tests/net.lua63
-rw-r--r--tests/net2.lua23
4 files changed, 47 insertions, 75 deletions
diff --git a/tests/h.lua b/tests/h.lua
index 310d6a8..9717650 100644
--- a/tests/h.lua
+++ b/tests/h.lua
@@ -1,31 +1,11 @@
-llib = require "llib"
+llib = require "lullaby"
+llib.config.set({print_meta = 1})
-llib.config.set({print_meta=1,max_depth=22})
---llib.thread.lock(1)
---llib.thread.lock(2)
---llib.thread.unlock(2)
-a = llib.thread.buffer(llib.crypto.md5())
+local a = llib.crypto.sha1()
+local b = llib.thread.buffer(a)
-print(a:get():final())
-for i=1,2009 do
- llib.thread.async(function (res)
- --llib.io.pprint(a);
- --l = a + a
- --a:mod(function(e) return e:update("meow") end)
- end)
-end
+llib.io.pprint(a)
+llib.io.pprint(b)
+llib.io.pprint((b + "meow"):final())
---os.execute("sleep 1")
-print(a:get():final())
---print("unlock")
---llib.thread.unlock(1)
-
-
---awa = thread_a:await()
-
---print(awa:await())
---print((awa + "hi"):final())
---thread_a:clean()
-
-print("clean exit")
diff --git a/tests/hash.lua b/tests/hash.lua
index b35515a..60d33a8 100644
--- a/tests/hash.lua
+++ b/tests/hash.lua
@@ -1,4 +1,4 @@
-llib = require "llib"
+llib = require "lullaby"
local hashes_working = 0
local hashes_failed = 0
diff --git a/tests/net.lua b/tests/net.lua
index 1afd02f..25ca696 100644
--- a/tests/net.lua
+++ b/tests/net.lua
@@ -1,66 +1,35 @@
-llib = require "llib"
-llib.config.set({max_depth=5})
---local print = llib.io.pprint
+--yes, this is kinda a mess of requires, just proof it works:3
+net = require "lullaby.net"
+io = require "lullaby.io"
+crypto = require "lullaby.crypto"
+config = require "lullaby.config"
+
+config.set({max_depth=5})
+
sleep = function(a)
local sec = tonumber(os.clock() + a);
while (os.clock() < sec) do
end
end
-aea = 5
-local wowa = 5
---_G.wo = llib
-_G._llib = _G.llib
---_G.ww = llib
---llib.io.pprint(_G)
-llib.net.listen(
+
+net.listen(
function(server)
- --llib = nil
- --llib.io.pprint(_G)
- llib.io.pprint("online")
+
+ io.pprint("online")
_G.server = server
server:all("/", function(res, req)
- b = llib.crypto.md5("hello")
+ b = crypto.md5("hello")
- --llib.io.pprint(a + '5')
res:send(b)
- --llib.io.pprint(res)
- --llib.io.pprint(res)
- --print(res.send)
- --res:send("hi");
- --res.Code = 201
- --wwo.sleep(1)
- --wwo.llib.io.pprint(wwo.sleep)
- --require "llib"
- --llib.io.pprint(_G)
- --_G.llib.io.pprint(_G.ww)
- --llib.io.pprint(_G.wo)
- --print("hi from first")
- --llib.io.pprint(llib.crypto.md5("hewwo"))
- --_G.sleep(1)
- --_G.llib.io.pprint(_G._G._G._llib.crypto.md5("hi"))
- --_G.llib.io.pprint(_G._Go)
- --_G.llib.io.pprint(_G.wo.crypto.md5("55"))
- --_G.llib.io.pprint(req)
- --print(req.partial)
- --_G.llib.io.pprint(_G.llib.io.readfile(".gitignore"))
- --print(req._bytes)
- --res:send(_G.llib.io.readfile("llib.dll"))
- --_G.llib.io.pprint(_G.llib.crypto.md5(_G.llib.io.readfile(".gitignore")))
- --_G.llib.io.pprint(req)
- --_G.llib.io.pprint(req)
- --print("start")
a = req:roll()
- --print(a)
+
while a > -1 do
a = req:roll()
print(req._bytes .. "/" .. req["Content-Length"])
- --print(a)
end
- llib.io.pprint(req)
- --_G.llib.io.pprint(req)
- --_G.llib.io.pprint("hi")
- --res:send("done")
+ io.pprint(req)
+
end)
server:GET("/aa", function(res, req)
diff --git a/tests/net2.lua b/tests/net2.lua
new file mode 100644
index 0000000..0ef3644
--- /dev/null
+++ b/tests/net2.lua
@@ -0,0 +1,23 @@
+--(this is in tests/net2.lua)
+net = require "lullaby.net"
+crypto = require "lullaby.crypto"
+local port = 8080
+MAX_LENGTH = 2048
+
+net.listen(function(server)
+
+ --listen to post requests at localhost:8080 (root directory)
+ server:POST("/", function(res, req)
+ --creates a sha0 hash object
+ local hash = crypto.sha0()
+ --loads an extra 2048 characters from the request body (the body is not guaranteed to be >= 2048 characters, reasoning in docs)
+ req:roll(MAX_LENGTH)
+
+ --incremental hashes allow updating via addition, in this case adding the body and getting a string from it
+ hash = (hash + req.Body):final()
+ --send the hash to the client, closes connection, but thread is live until it ends
+ res:send(hash)
+ end)
+
+end, port)
+