summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-05-22 12:43:03 -0500
committersanine <sanine.not@pm.me>2022-05-22 12:43:03 -0500
commitfc4a406371fdf130d6f0db02d3a2e09112686b9f (patch)
tree6d3b0d75b1eb35f88979ad8828914d8c2788031f
parent9855e635835716c638ab72c844d5dac08288a20c (diff)
fix bug in tests and add marigold.h
-rw-r--r--marigold.lua30
-rwxr-xr-xtest.lua32
2 files changed, 55 insertions, 7 deletions
diff --git a/marigold.lua b/marigold.lua
index 939a7ba..c95ecb5 100644
--- a/marigold.lua
+++ b/marigold.lua
@@ -36,4 +36,34 @@
local marigold = {}
+marigold.get_metavars = function()
+ local vars = {
+ "AUTH_TYPE", "CONTENT_LENGTH",
+ "CONTENT_TYPE", "GATEWAY_INTERFACE",
+ "PATH_INFO", "PATH_TRANSLATED",
+ "QUERY_STRING", "REMOTE_ADDR",
+ "REMOTE_HOST", "REMOTE_IDENT",
+ "REMOTE_USER", "REQUEST_METHOD",
+ "SCRIPT_NAME", "SERVER_NAME",
+ "SERVER_PORT", "SERVER_PROTOCOL",
+ "SERVER_SOFTWARE"
+ }
+ local metavars = {}
+ for _, var in ipairs(vars) do
+ metavars[string.lower(var)] = os.getenv(var)
+ end
+ return metavars
+end
+
+
+marigold.h = function(tag_type, content, tbl)
+ local tag = {}
+ tag.tag = tag_type
+ tag.content = content
+ tag.attributes = {}
+ tag.children = {}
+ return tag
+end
+
+return marigold
diff --git a/test.lua b/test.lua
index d66f977..81d5d77 100755
--- a/test.lua
+++ b/test.lua
@@ -14,11 +14,6 @@ function test(description, func)
end
end
-function test_assert(str)
- local f = assert(loadstring('return ' .. str))
- assert(f(), 'assertion failed: ' .. str)
-end
-
test("marigold.get_metavars correctly calls os.getenv", function()
-- mock os.getenv
@@ -37,12 +32,35 @@ test("marigold.get_metavars correctly calls os.getenv", function()
REQUEST_METHOD = 'uhh, to do what?',
SCRIPT_NAME = 'pretty sure this is hamlet',
SERVER_NAME = 'this isnt a restaurant',
+ SERVER_PORT = 'what, like a ship?',
SERVER_PROTOCOL = 'no really, not a restaurant',
SERVER_SOFTWARE = 'not familiar with that dish...',
}
os.getenv = function(varname) return env_tbl[varname] end
-- actually call the function
- --local metavars = marigold.get_metavars()
- test_assert("type(metavars) == 'table'")
+ metavars = marigold.get_metavars()
+
+ assert(type(metavars) == 'table')
+ for k, v in pairs(env_tbl) do
+ assert(metavars[string.lower(k)])
+ assert(metavars[string.lower(k)] == env_tbl[k])
+ end
+
+ -- restore os.getenv
+ os.getenv = old_getenv
+end)
+
+
+test("marigold.h produces a correct basic tag", function()
+ local h = marigold.h
+ local h1 = h('h1', 'hello, world!')
+ assert(type(h1) == 'table')
+ assert(h1.tag == 'h1')
+ assert(h1.content == 'hello, world!')
+ -- should have no entries in the h1.attributes table
+ for k, v in pairs(h1.attributes) do
+ assert(false, string.format("%s, %s", tostring(k), tostring(v)))
+ end
+ assert(#(h1.children) == 0)
end)