-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.lua
More file actions
98 lines (74 loc) · 1.91 KB
/
Test.lua
File metadata and controls
98 lines (74 loc) · 1.91 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
local function serialize(o)
local s = "";
if o == nil then
s = "(nil)";
elseif type(o) == "number" or type(o) == "boolean" then
s = tostring(o);
elseif type(o) == "string" then
s = string.format("%q", o);
elseif type(o) == "function" then
s = "(function)";
elseif type(o) == "table" then
s = "{";
for k,v in pairs(o) do
s = s..k.."="..serialize(v)..",";
end
s = s.."}";
else
error("cannot serialize a "..type(o));
end
return s;
end
local function printf(stringFormat, ...)
print(string.format(stringFormat, ...));
end;
local function prints(tbl)
print(serialize(tbl));
end
-- create RoM API stubs
SELECTED_CHAT_FRAME = {};
DEFAULT_CHAT_FRAME = SELECTED_CHAT_FRAME;
function SELECTED_CHAT_FRAME:AddMessage(s) print(s) end;
SlashCmdList = {};
StaticPopupDialogs = {};
StaticPopupDialogs["OPEN_WEBROWER"] = { link = "" };
function ChatFrame_OnHyperlinkClick()
end
function getglobal()
return null;
end
function StaticPopup_Show(txt)
printf("%s to %s", txt, StaticPopupDialogs["OPEN_WEBROWER"].link);
end
function IsShiftKeyDown()
return false;
end
function IsCtrlKeyDown()
return false;
end
dofile("WebLinks.lua");
WebLinks.HookApi();
-------------------------------
local webLink = "https://ts3.hoster.com?port=9987"
local tsLink = "ts3server://ts3.hoster.com?port=9987"
local wwwLink = "www.google.com"
local function processLink(link)
local msg = string.format("click here %s now", link);
msg = WebLinks.ConvertWebLinks(msg);
print(msg);
local _, gameLink = WebLinks.parseHyperlink(msg);
print(gameLink);
return gameLink
end
assert(webLink==processLink(webLink))
assert(tsLink==processLink(tsLink))
assert("https://"..wwwLink==processLink(wwwLink))
local notALink = "wwwHans"
local notALink2 = "www. adsf"
local function processText(text)
local msg = WebLinks.ConvertWebLinks(text)
print(msg)
return msg
end
assert(processText(notALink)==notALink)
assert(processText(notALink2)==notALink2)