1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#!/usr/bin/lua
local marigold = require 'marigold'
function test(description, func)
io.write(description .. ': ')
local result, msg = pcall(func)
if result == true then
print("OK")
else
print("FAIL")
print(debug.traceback(msg))
print()
end
end
test("marigold.get_metavars correctly calls os.getenv", function()
-- mock os.getenv
local old_getenv = os.getenv
local env_tbl = {
AUTH_TYPE = 'some auth type',
CONTENT_LENGTH = 'a zillion',
GATEWAY_INTERFACE = 'idk, something',
PATH_INFO = 'youll see, its a secret',
PATH_TRANSLATED = 'i told you its a secret!',
QUERY_STRING = 'which string do you want?',
REMOTE_ADDR = 'probably somewhere in nunavut',
REMOTE_HOST = 'woah wait are we talking about parasites?',
REMOTE_IDENT = 'are you a cop?',
REMOTE_USER = 'seriously, you have to tell me if you are',
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
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)
|