2020-10-25 16:52:46 +00:00
|
|
|
local testFiles = {"verifyUrlDetection_1a",
|
|
|
|
"verifyUrlDetection_1b"}
|
|
|
|
local URL_INDIC = 8
|
|
|
|
local timerInterval = 10
|
|
|
|
|
2020-11-01 02:28:18 +00:00
|
|
|
local curPos = 0
|
|
|
|
local task = -1
|
|
|
|
local uFrom = 0
|
|
|
|
local uTo = 0
|
|
|
|
local mFrom = 0
|
|
|
|
local mTo = 0
|
|
|
|
local OKorKO = "OK"
|
|
|
|
local nFile = 1
|
|
|
|
local testResults = {}
|
|
|
|
local outFile = nil
|
2020-10-25 16:52:46 +00:00
|
|
|
|
2020-11-01 02:28:18 +00:00
|
|
|
local function Summary()
|
|
|
|
local resLine = ""
|
|
|
|
local i = 1
|
|
|
|
while testFiles[i] ~= nil do
|
|
|
|
if testResults[i] == nil then
|
|
|
|
testResults[i] = "KO"
|
|
|
|
end
|
|
|
|
print(testFiles[i] .. ": " .. testResults[i])
|
|
|
|
i = i + 1
|
|
|
|
end
|
|
|
|
print(resLine)
|
|
|
|
if endNppAfterUrlTest ~= nil then
|
|
|
|
npp:MenuCommand(IDM_FILE_EXIT)
|
2020-10-25 16:52:46 +00:00
|
|
|
end
|
2020-11-01 02:28:18 +00:00
|
|
|
end
|
2020-10-25 16:52:46 +00:00
|
|
|
|
2020-11-01 02:28:18 +00:00
|
|
|
local function nextFile()
|
|
|
|
local fileAvail = false
|
|
|
|
if outFile ~= nil then
|
|
|
|
io.close(outFile)
|
|
|
|
end
|
|
|
|
while (not fileAvail) and (testFiles[nFile] ~= nil) do
|
|
|
|
local fileName = npp:GetNppDirectory() .. "\\..\\Test\\UrlDetection\\" .. testFiles[nFile]
|
|
|
|
fileAvail = npp:SwitchToFile(fileName)
|
|
|
|
if not fileAvail then
|
|
|
|
local f = io.open(fileName,"r")
|
|
|
|
if f~=nil then
|
|
|
|
io.close(f)
|
|
|
|
fileAvail = npp:DoOpen(fileName)
|
2020-10-25 16:52:46 +00:00
|
|
|
end
|
2020-11-01 02:28:18 +00:00
|
|
|
end
|
|
|
|
-- print("Verifying " .. testFiles[nFile] .. " ...")
|
|
|
|
print("Verifying " .. npp:GetFileName() .. " ...")
|
|
|
|
if fileAvail then
|
|
|
|
local outFileName = fileName .. ".result"
|
|
|
|
outFile = io.open(outFileName,"w")
|
|
|
|
if outFile == nil then
|
2020-10-25 16:52:46 +00:00
|
|
|
testResults[nFile] = "KO"
|
2020-11-01 02:28:18 +00:00
|
|
|
print("KO", "Cannot open output file \""..fileName.."\"")
|
2020-10-25 16:52:46 +00:00
|
|
|
print()
|
|
|
|
nFile = nFile + 1;
|
|
|
|
end
|
2020-11-01 02:28:18 +00:00
|
|
|
else
|
|
|
|
testResults[nFile] = "KO"
|
|
|
|
print("KO", "Cannot open file \""..fileName.."\"")
|
|
|
|
print()
|
|
|
|
nFile = nFile + 1;
|
2020-10-25 16:52:46 +00:00
|
|
|
end
|
|
|
|
end
|
2020-11-01 02:28:18 +00:00
|
|
|
return fileAvail
|
|
|
|
end
|
2020-10-25 16:52:46 +00:00
|
|
|
|
2020-11-01 02:28:18 +00:00
|
|
|
local function scrollToNextURL()
|
|
|
|
editor.TargetStart = curPos
|
|
|
|
editor.TargetEnd = editor.Length
|
|
|
|
editor.SearchFlags = SCFIND_REGEXP
|
|
|
|
local iRes = editor:SearchInTarget("^u .+ u$")
|
|
|
|
if iRes >= 0 then
|
|
|
|
uFrom = editor.TargetStart
|
|
|
|
uTo = editor.TargetEnd
|
|
|
|
editor.TargetStart = uFrom
|
2020-10-25 16:52:46 +00:00
|
|
|
editor.TargetEnd = editor.Length
|
2020-11-01 02:28:18 +00:00
|
|
|
iRes = editor:SearchInTarget("^m .+ m$")
|
2020-10-25 16:52:46 +00:00
|
|
|
if iRes >= 0 then
|
2020-11-01 02:28:18 +00:00
|
|
|
mFrom = editor.TargetStart
|
|
|
|
mTo = editor.TargetEnd
|
|
|
|
local ln1 = editor:LineFromPosition(uFrom)
|
|
|
|
local ln2 = editor:LineFromPosition(mFrom)
|
|
|
|
if (ln1+1) == ln2 then
|
|
|
|
editor:ScrollRange(mTo, uFrom)
|
|
|
|
return 1
|
2020-10-25 16:52:46 +00:00
|
|
|
else
|
2020-11-01 02:28:18 +00:00
|
|
|
editor:GotoPos(mFrom)
|
2020-10-25 16:52:46 +00:00
|
|
|
OKorKO = "KO"
|
2020-11-01 02:28:18 +00:00
|
|
|
print("KO", "Mask line not following immediately after URL line")
|
2020-10-25 16:52:46 +00:00
|
|
|
return -1
|
|
|
|
end
|
|
|
|
else
|
2020-11-01 02:28:18 +00:00
|
|
|
OKorKO = "KO"
|
|
|
|
print ("KO", "Mask line not found")
|
|
|
|
return -1
|
2020-10-25 16:52:46 +00:00
|
|
|
end
|
2020-11-01 02:28:18 +00:00
|
|
|
else
|
|
|
|
return 0
|
2020-10-25 16:52:46 +00:00
|
|
|
end
|
2020-11-01 02:28:18 +00:00
|
|
|
end
|
2020-10-25 16:52:46 +00:00
|
|
|
|
2020-11-01 02:28:18 +00:00
|
|
|
local function verifyURL()
|
|
|
|
local mMsk = editor:textrange(mFrom, mTo)
|
|
|
|
editor:GotoPos(uFrom + 2)
|
|
|
|
local uMsk = "m "
|
|
|
|
local limit = mTo - mFrom -- if something goes wrong, edit.CurrentPos may never reach (uTo - 2).
|
|
|
|
while (editor.CurrentPos < uTo - 2) and (limit >= 0) do
|
|
|
|
if editor:IndicatorValueAt(URL_INDIC, editor.CurrentPos) == 0 then
|
|
|
|
uMsk = uMsk .. "0"
|
|
|
|
else
|
|
|
|
uMsk = uMsk .. "1"
|
2020-10-25 16:52:46 +00:00
|
|
|
end
|
2020-11-01 02:28:18 +00:00
|
|
|
editor:CharRight()
|
|
|
|
limit = limit - 1
|
|
|
|
end
|
|
|
|
local Res = 0
|
|
|
|
if limit >= 0 then
|
|
|
|
if editor:textrange(editor.CurrentPos, editor.CurrentPos + 2) == " u" then
|
|
|
|
uMsk = uMsk .. " m"
|
|
|
|
if uMsk == mMsk then
|
|
|
|
outFile:write("OK", "\t", editor:textrange(uFrom, uTo), "\n")
|
|
|
|
Res = 1
|
|
|
|
else
|
|
|
|
outFile:write("KO", "\t", editor:textrange(uFrom, uTo), "\n")
|
|
|
|
outFile:write("ok", "\t", mMsk, "\n")
|
|
|
|
outFile:write("ko", "\t", uMsk, "\n")
|
|
|
|
print("KO", "\t", editor:textrange(uFrom, uTo))
|
|
|
|
print("ok", "\t", mMsk)
|
|
|
|
print("ko", "\t", uMsk)
|
|
|
|
OKorKO = "KO"
|
|
|
|
Res = 1
|
2020-10-25 16:52:46 +00:00
|
|
|
end
|
|
|
|
end
|
2020-11-01 02:28:18 +00:00
|
|
|
else
|
|
|
|
outFile:write("KO", "\t", "internal error", "\n")
|
|
|
|
OKorKO = "KO"
|
2020-10-25 16:52:46 +00:00
|
|
|
end
|
2020-11-01 02:28:18 +00:00
|
|
|
return Res
|
|
|
|
end
|
2020-10-25 16:52:46 +00:00
|
|
|
|
2020-11-01 02:28:18 +00:00
|
|
|
local function goForward(timer)
|
|
|
|
if task < 0 then
|
|
|
|
task = task + 1
|
|
|
|
if task == 0 then
|
|
|
|
if not nextFile() then
|
2020-10-25 16:52:46 +00:00
|
|
|
npp.StopTimer(timer)
|
2020-11-01 02:28:18 +00:00
|
|
|
Summary()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif task == 0 then
|
|
|
|
local urlAvail = scrollToNextURL()
|
|
|
|
if urlAvail == 1 then
|
|
|
|
task = 1
|
|
|
|
else
|
|
|
|
npp.StopTimer(timer)
|
|
|
|
print(OKorKO)
|
|
|
|
print()
|
|
|
|
testResults[nFile] = OKorKO
|
|
|
|
if urlAvail == 0 then
|
|
|
|
nFile = nFile + 1
|
|
|
|
if nextFile() then
|
|
|
|
task = 0
|
|
|
|
curPos = 0
|
|
|
|
OKorKO = "OK"
|
|
|
|
npp.StartTimer(timerInterval, goForward)
|
2020-10-25 16:52:46 +00:00
|
|
|
else
|
|
|
|
Summary()
|
|
|
|
end
|
|
|
|
else
|
2020-11-01 02:28:18 +00:00
|
|
|
Summary()
|
2020-10-25 16:52:46 +00:00
|
|
|
end
|
2020-11-01 02:28:18 +00:00
|
|
|
end
|
|
|
|
elseif task == 1 then
|
|
|
|
if verifyURL() == 0 then
|
|
|
|
npp.StopTimer(timer)
|
2020-10-25 16:52:46 +00:00
|
|
|
print()
|
|
|
|
Summary()
|
2020-11-01 02:28:18 +00:00
|
|
|
else
|
|
|
|
curPos = mTo
|
|
|
|
task = 0
|
2020-10-25 16:52:46 +00:00
|
|
|
end
|
2020-11-01 02:28:18 +00:00
|
|
|
else
|
|
|
|
npp.stopTimer(timer)
|
|
|
|
print("KO", "Internal impossibility")
|
|
|
|
print()
|
|
|
|
Summary()
|
2020-10-25 16:52:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
npp.ClearConsole()
|
2020-11-01 02:28:18 +00:00
|
|
|
npp.StartTimer(timerInterval, goForward)
|
|
|
|
|