-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComparisons.lua
More file actions
63 lines (62 loc) · 2 KB
/
Comparisons.lua
File metadata and controls
63 lines (62 loc) · 2 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
local Comparisons = {
MinArgsDefault = 2,
MinArgs = {
errors = 1,
fail = 1,
truthy = 1,
falsy = 1,
},
}
local comparisonsObj = script.Parent.ComparisonsCode
local source = comparisonsObj.Source
local ComparisonsCode = require(comparisonsObj)
local threshold = 0.00001 -- difference at which numbers are considered unequal
local comparisonsExpectedFirst = ComparisonsCode(true, threshold)
local comparisonsExpectedSecond = ComparisonsCode(false, threshold)
function Comparisons.GetComparisons(expectedFirst)
return expectedFirst and comparisonsExpectedFirst or comparisonsExpectedSecond
end
function Comparisons.GetDocs(header)
local s = {
header("Available Assertions"), [=[
In the below functions, 'a' and 'b' are for 'actual' and 'expected'.
By default, 'actual' comes first, but this can be changed by having 'expectedFirst = true' in the relevant TestConfig.
]=]}
local startedAliases = false
local allowNewlines = false -- don't allow blank lines until we have at least 1 line of content
for line in source:gmatch("(.-)\n") do -- note: won't get last line (but we don't need it)
local name, args, comment = line:match("^\t(%w+) = function(%([^)]+%))[ \t]*(%-?%-?[^\n]*)$")
if name then
if comment:sub(1, 2) ~= "--" then comment = nil end
s[#s + 1] = ("t.%s%s%s"):format(name, args, comment and " " .. comment or "")
allowNewlines = true
elseif line:match("^%s*$") then
if allowNewlines then
s[#s + 1] = "" -- adds a newline (due to concat below)
end
else
comment = line:match("^\t\t%-%-\t(.*)")
if comment then
s[#s + 1] = "\t-- " .. comment
else
local alias, fullName = line:match("^c%.(%w+) = c%.(%w+)")
if alias then
if not startedAliases then
startedAliases = true
s[#s + 1] = "\nAliases:" -- newline
end
s[#s + 1] = ("\t%s == %s"):format(alias, fullName)
end
end
end
end
for i = #s, 1, -1 do -- Remove trailing blank lines
if s[i] == "" then
s[i] = nil
else
break
end
end
return table.concat(s, "\n")
end
return Comparisons