Fix newlines and intendation

This commit is contained in:
mpeterv
2015-09-10 17:33:27 +03:00
parent 0c1e6e703d
commit 1adcc2da76
2 changed files with 1444 additions and 1444 deletions

View File

@@ -1,19 +1,19 @@
if not markdown then if not markdown then
require "markdown" require "markdown"
end end
-- Splits the text into an array of separate lines. -- Splits the text into an array of separate lines.
local function split(text, sep) local function split(text, sep)
sep = sep or "\n" sep = sep or "\n"
local lines = {} local lines = {}
local pos = 1 local pos = 1
while true do while true do
local b,e = text:find(sep, pos) local b,e = text:find(sep, pos)
if not b then table.insert(lines, text:sub(pos)) break end if not b then table.insert(lines, text:sub(pos)) break end
table.insert(lines, text:sub(pos, b-1)) table.insert(lines, text:sub(pos, b-1))
pos = e + 1 pos = e + 1
end end
return lines return lines
end end
---------------------------------------------------------------------- ----------------------------------------------------------------------
@@ -28,14 +28,14 @@ end
-- order. -- order.
local TESTS = {} local TESTS = {}
local TESTS_MT = { local TESTS_MT = {
__index = _G, __index = _G,
__newindex = function(t,k,v) __newindex = function(t,k,v)
if k:sub(1,1) == "_" then rawset(t,k,v) return end if k:sub(1,1) == "_" then rawset(t,k,v) return end
if t._indices == nil then t._indices = {} end if t._indices == nil then t._indices = {} end
table.insert(t._indices, k) table.insert(t._indices, k)
rawset(t,k,v) rawset(t,k,v)
end end
} }
setmetatable(TESTS, TESTS_MT) setmetatable(TESTS, TESTS_MT)
@@ -4404,75 +4404,75 @@ setfenv(1, _G)
-- Test running function -- Test running function
local function run_tests() local function run_tests()
-- Do any <pre></pre> sequences in s1 and s2 match up perfectly? -- Do any <pre></pre> sequences in s1 and s2 match up perfectly?
local function pre_equal(s1, s2) local function pre_equal(s1, s2)
local pre = {} local pre = {}
for p in s1:gfind("<pre>.-</pre>") do for p in s1:gfind("<pre>.-</pre>") do
pre[#pre+1] = p pre[#pre+1] = p
end end
for p in s2:gfind("<pre>.-</pre>") do for p in s2:gfind("<pre>.-</pre>") do
if p ~= pre[1] then return false end if p ~= pre[1] then return false end
table.remove(pre, 1) table.remove(pre, 1)
end end
return #pre == 0 return #pre == 0
end end
-- Are s1 and s2 equal except for whitespace issues. -- Are s1 and s2 equal except for whitespace issues.
local function nonspace_equal(s1, s2) local function nonspace_equal(s1, s2)
s1 = s1:gsub("[ \t\n\r]", "") s1 = s1:gsub("[ \t\n\r]", "")
s2 = s2:gsub("[ \t\n\r]", "") s2 = s2:gsub("[ \t\n\r]", "")
return s1 == s2 return s1 == s2
end end
-- Runs a single test -- Runs a single test
local function run_single_test(name, source, desired) local function run_single_test(name, source, desired)
local result = markdown(source) local result = markdown(source)
local res = pre_equal(result, desired) and nonspace_equal(result, desired) local res = pre_equal(result, desired) and nonspace_equal(result, desired)
if not res and not quiet_mode then if not res and not quiet_mode then
print("********** TEST FAILED **********") print("********** TEST FAILED **********")
print(name) print(name)
print("----- Input:") print("----- Input:")
print(source) print(source)
print("----- Expected output:") print("----- Expected output:")
print(desired) print(desired)
print("----- Actual output:") print("----- Actual output:")
print(result) print(result)
print("*********************************") print("*********************************")
print() print()
end end
return res return res
end end
-- Runs a specified test battery -- Runs a specified test battery
local function run_test(name, code) local function run_test(name, code)
local failed, succeeded = 0,0 local failed, succeeded = 0,0
local data = split(code, "\n~[ \t]*\n") local data = split(code, "\n~[ \t]*\n")
for i = 1, #data, 2 do for i = 1, #data, 2 do
if run_single_test(name, data[i], data[i+1]) then if run_single_test(name, data[i], data[i+1]) then
succeeded = succeeded + 1 succeeded = succeeded + 1
else else
failed = failed + 1 failed = failed + 1
end end
end end
if failed>0 and not quiet_mode then if failed>0 and not quiet_mode then
print(string.format("%-20s %15s %5i %15s %5i", name, "Succeeded:", succeeded, "Failed:", failed)) print(string.format("%-20s %15s %5i %15s %5i", name, "Succeeded:", succeeded, "Failed:", failed))
end end
return failed return failed
end end
total_failed = 0 total_failed = 0
for _,k in ipairs(TESTS._indices) do for _,k in ipairs(TESTS._indices) do
total_failed = total_failed + run_test(k,TESTS[k]) total_failed = total_failed + run_test(k,TESTS[k])
end end
if total_failed > 0 then if total_failed > 0 then
os.exit(-1) os.exit(-1)
end end
end end
for i=1,#arg do for i=1,#arg do
if arg[i] == "-q" then if arg[i] == "-q" then
quiet_mode = true quiet_mode = true
end end
end end
run_tests() run_tests()

File diff suppressed because it is too large Load Diff