-
Notifications
You must be signed in to change notification settings - Fork 1
/
unittest.lua
48 lines (43 loc) · 1.37 KB
/
unittest.lua
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
core = {}
minetest = core
local callback
function esc(msg)
return msg:gsub("\x1b", "\\")
end
function core.colorize(x, text)
return "\x1b(c@" .. x .. ")" .. text .. "\x1b(c@#ffffff)"
end
function core.get_color_escape_sequence(x)
return "\x1b(c@" .. x .. ")"
end
function core.display_chat_message(msg)
print("Out: " .. esc(msg))
end
function core.register_on_receiving_chat_message(func)
callback = func
end
function core.strip_colors(msg)
return (msg:gsub("\x1b%([bc]@[^)]+%)", ""))
end
function core.sha1()
return ("FOOBARZ"):rep(5)
end
dofile("init.lua")
local test_table = {
"*** singleplayer joined the game",
"*** \x1b(T@__builtin)\x1bFsingleplayer\x1bE joined the game.\x1bE",
"* singleplayer needs action like a true survivor",
"\x1b(T@__builtin)Privileges of \x1bFsingleplayer\x1bE: \x1bFyou, spin, me, right, round, babe\x1bE\x1bE",
"<singleplayer> buzz baz",
"\x1b(c@#abcdef)[Admin] <singleplayer> foo bar\x1b(c@#ffffff)",
"\x1b(c@#FF0000)<singleplayer>\x1b(c@#ffffff) not modified",
"\x1b(c@#FF4444)<singleplayer> \x1b(c@#ffffff)CTF format",
"\x1b(c@#F00)<singleplayer> \x1b(c@#FFF)\x1b(c@#0F0)Somebody\x1b(c@#FFF) once told me"
}
local time = os.clock()
for i, v in pairs(test_table) do
print("\nIn: " .. esc(v))
callback(v)
end
local end_time = (os.clock() - time) * 1000^2 / #test_table
print("==> " .. math.floor(end_time + 0.5) .. " μs per chat message")