Test tool to verify URL parser

Close #9059
This commit is contained in:
Udo Hoffmann 2020-10-25 17:52:46 +01:00 committed by Don HO
parent 210ae7e1d3
commit 9cd6e6513f
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E
12 changed files with 741 additions and 1 deletions

View File

@ -0,0 +1,6 @@
-- Startup script for URL detection verification test
endNppAfterUrlTest = 1
local nppDir = npp:GetNppDirectory()
local verifyUrlDetection = loadfile(nppDir .."\\" .. "..\\Test\\UrlDetection\\verifyUrlDetection.lua")
pcall(verifyUrlDetection)

View File

@ -0,0 +1,70 @@
What is the URL detection test
------------------------------
The URL detection test is designed to check,
whether the clickable detection works as expected or not.
It uses text files as input. These text files contain a pair of
lines for each URL to test. The first line contains the URL, the
second line contains a sequence of characters, which are a mask,
consisting of '0' or '1' characters, describing whether this
position in the line should be detected as URL.
Example:
u http://dot.com u
m 11111111111111 m
As can be seen, the URL is enclosed in "u " and " u", the mask
is enclosed in "m " and " m". The mask line must follow the URL
line immediately. A '1' in the mask line says, that this position
should be detected as URL, a '0' says the opposite.
It is possible, to put arbitrary text between the pairs of test
lines, to comment the test cases. Obviously, none of the comment
lines should start and end with a single 'u' or 'm' character.
The test files can also be regarded as living document about what
is currently detected as URL and what not.
How to conduct the URL detection test
-------------------------------------
Since the URL detection only takes place in the visible part of
the edit windows, the test can only be run from inside an opened
Notepad++ with a visible edit window.
Since the test script is written in Lua, a prerequisite to conduct
the test is, that the Lua plugin is installed. The plugin can be found
at https://github.com/dail8859/LuaScript/releases.
To conduct the test:
1. Open the verifyUrlDetection.lua with Notepad++.
2. Display the Lua console window (Plugins --> LuaScript --> Show Console)
3. Execute the opened script file (Plugins --> LuaScript --> Execute Current File)
The test results will be displayed in the Lua console window.
!!! Please be aware, that there should NO keyboard or mouse or whatever
input be applied to Notepad++ while this test is running.
How to extend the URL detection test
------------------------------------
It is possible to add test files to the URL detection test
by copying the new files into this directory and include the filenames
in the testFiles list at the beginning of verifyUrlDetection.lua.
Automated version of the URL detection test
-------------------------------------------
An automated version of the test can be conducted by running verifyUrlDetection.ps1.
This is mainly to run the test in Appveyor.

View File

@ -0,0 +1,197 @@
local testFiles = {"verifyUrlDetection_1a",
"verifyUrlDetection_1b"}
local URL_INDIC = 8
local timerInterval = 10
local function verifyUrlDetection()
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
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
print("good bye")
npp:MenuCommand(IDM_FILE_EXIT)
end
end
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)
end
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
testResults[nFile] = "KO"
print("KO", "Cannot open output file \""..fileName.."\"")
print()
nFile = nFile + 1;
end
else
testResults[nFile] = "KO"
print("KO", "Cannot open file \""..fileName.."\"")
print()
nFile = nFile + 1;
end
end
return fileAvail
end
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
editor.TargetEnd = editor.Length
iRes = editor:SearchInTarget("^m .+ m$")
if iRes >= 0 then
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
else
editor:GotoPos(mFrom)
OKorKO = "KO"
print("KO", "Mask line not following immediately after URL line")
return -1
end
else
OKorKO = "KO"
print ("KO", "Mask line not found")
return -1
end
else
return 0
end
end
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"
end
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")
OKorKO = "KO"
Res = 1
end
end
else
outFile:write("KO", "\t", "internal error", "\n")
OKorKO = "KO"
end
return Res
end
local function goForward(timer)
if task < 0 then
task = task + 1
if task == 0 then
if not nextFile() then
npp.StopTimer(timer)
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)
else
Summary()
end
else
Summary()
end
end
elseif task == 1 then
if verifyURL() == 0 then
npp.StopTimer(timer)
print()
Summary()
else
curPos = mTo
task = 0
end
else
npp.stopTimer(timer)
print("KO---", "Internal impossibility")
print()
Summary()
end
end
npp.StartTimer(timerInterval, goForward)
end
npp.ClearConsole()
verifyUrlDetection()

View File

@ -0,0 +1,57 @@
try {
if (Test-Path -Path '..\..\Bin\plugins' -PathType Container)
{
if (Test-Path -Path '..\..\Bin\plugins_save' -PathType Container)
{
"Backup for plugins directory already exists"
exit -1
}
"Backing up plugin directory ..."
Move-Item ..\..\Bin\plugins ..\..\bin\plugins_save
}
"Installing Lua plugin for testing ..."
Copy-Item -Path .\plugins -Destination ..\..\bin -Recurse
"Testing ..."
..\..\bin\notepad++.exe | Out-Null
if (Test-Path -Path '..\..\Bin\plugins_save' -PathType Container)
{
"Removing Lua plugin ..."
Remove-Item -Path ..\..\Bin\plugins -Recurse -Force
"Restoring plugin directory ..."
Move-Item ..\..\Bin\plugins_save ..\..\bin\plugins
}
$expectedRes = Get-Content .\verifyUrlDetection_1a.expected.result
$generatedRes = Get-Content .\verifyUrlDetection_1a.result
if (Compare-Object -ReferenceObject $expectedRes -DifferenceObject $generatedRes)
{
"Unexpected test results for verifyUrlDetection_1a"
exit -1
}
else
{
Remove-Item .\verifyUrlDetection_1a.result
$expectedRes = Get-Content .\verifyUrlDetection_1b.expected.result
$generatedRes = Get-Content .\verifyUrlDetection_1b.result
if (Compare-Object -ReferenceObject $expectedRes -DifferenceObject $generatedRes)
{
"Unexpected test results for verifyUrlDetection_1b"
exit -1
}
else
{
Remove-Item .\verifyUrlDetection_1b.result
"URL detection test OK"
exit 0
}
}
}
catch
{
"Unexpected behavior while URL detection test"
exit -1
}

View File

@ -0,0 +1,284 @@
=== URLs which are handled OK so far ===
u http://test.com u
m 111111111111111 m
u HTTP://UPCASE.UP u
m 1111111111111111 m
u http: u
m 00000 m
u mailto: u
m 0000000 m
Preceding none-whitespace characters:
u !http://test.com u
m 0111111111111111 m
u "http://test.com u
m 0111111111111111 m
u #http://test.com u
m 0111111111111111 m
u $http://test.com u
m 0111111111111111 m
u %http://test.com u
m 0111111111111111 m
u &http://test.com u
m 0111111111111111 m
u 'http://test.com u
m 0111111111111111 m
u (http://test.com u
m 0111111111111111 m
u )http://test.com u
m 0111111111111111 m
u *http://test.com u
m 0111111111111111 m
u +http://test.com u
m 0111111111111111 m
u ,http://test.com u
m 0111111111111111 m
u -http://test.com u
m 0111111111111111 m
u .http://test.com u
m 0111111111111111 m
u /http://test.com u
m 0111111111111111 m
u 1http://test.com u
m 0000000000000000 m
u 9http://test.com u
m 0000000000000000 m
u :http://test.com u
m 0111111111111111 m
u ;http://test.com u
m 0111111111111111 m
u <http://test.com u
m 0111111111111111 m
u >http://test.com u
m 0111111111111111 m
u ?http://test.com u
m 0111111111111111 m
u @http://test.com u
m 0111111111111111 m
u Ahttp://test.com u
m 0000000000000000 m
u Zhttp://test.com u
m 0000000000000000 m
u [http://test.com u
m 0111111111111111 m
u \http://test.com u
m 0111111111111111 m
u ]http://test.com u
m 0111111111111111 m
u ^http://test.com u
m 0111111111111111 m
u _http://test.com u
m 0000000000000000 m
u `http://test.com u
m 0111111111111111 m
u ahttp://test.com u
m 0000000000000000 m
u zhttp://test.com u
m 0000000000000000 m
u {http://test.com u
m 0111111111111111 m
u |http://test.com u
m 0111111111111111 m
u }http://test.com u
m 0111111111111111 m
u ~http://test.com u
m 0111111111111111 m
Query parsing:
u https://duckduckgo.com/?q=windows+delete+"GameBarPresenceWriter.exe" u
m 11111111111111111111111111111111111111111111111111111111111111111111 m
u "https://duckduckgo.com/?q=windows+delete+"GameBarPresenceWriter.exe"" u
m 0111111111111111111111111111111111111111111111111111111111111111111110 m
u "https://duckduckgo.com/?q=windows+delete+"GameBarPresenceWriter.exe" u
m 011111111111111111111111111111111111111111111111111111111111111111111 m
u "https://duckduckgo/com/?q=windows+delete+GameBarPresenceWriter.exe" u
m 01111111111111111111111111111111111111111111111111111111111111111110 m
u "https://duckduckgo.com/?q=windows+delete+""GameBarPresenceWriter.exe" u
m 0111111111111111111111111111111111111111111100000000000000000000000000 m
u https://www.youtube.com/watch?v=VmcftreqQ6E&list=PnQIRE5O5JpiLL&index=xxx u
m 1111111111111111111111111111111111111111111111111111111111111111111111111 m
Space detection:
u "http://github.com/notepad-plus-plus/notepad-plus-plus" u
m 0111111111111111111111111111111111111111111111111111110 m
u "https://github.com /notepad-plus-plus/notepad-plus-plus" u
m 011111111111111111100000000000000000000000000000000000000 m
u "https://github.com/notepad plus plus/notepad-plus-plus" u
m 01111111111111111111111111100000000000000000000000000000 m
Unwanted trailing character removal:
u (https://github.com/notepad-plus-plus/notepad-plus-plus) u
m 01111111111111111111111111111111111111111111111111111110 m
u https://github.com/notepad-plus-plus/notepad-plus-plus; u
m 1111111111111111111111111111111111111111111111111111110 m
u https://github.com/notepad-plus-plus/notepad-plus-plus? u
m 1111111111111111111111111111111111111111111111111111110 m
u https://github.com/notepad-plus-plus/notepad-plus-plus! u
m 1111111111111111111111111111111111111111111111111111110 m
u https://github.com/notepad-plus-plus/notepad-plus-plus# u
m 1111111111111111111111111111111111111111111111111111110 m
u http://github.com/notepad-plus-plus/notepad-plus-plus#fragment u
m 11111111111111111111111111111111111111111111111111111111111111 m
u (e.g., https://en.wikipedia.org/wiki/Saw_(2003_film))? u
m 000000011111111111111111111111111111111111111111111100 m
u (https://en.wikipedia.org/wiki/Saw_(2003_film)) u
m 01111111111111111111111111111111111111111111110 m
u (https://en.wikipedia.org/wiki/Saw_2003_film) u
m 011111111111111111111111111111111111111111110 m
International characters:
u https://apache-windows.ru/как-установить-сервер-apache-c-php-mysql-и-phpmyadmin-на-windows/ u
m 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 m
u https://www.rnids.rs/национални-домени/регистрација-националних-домена u
m 1111111111111111111111111111111111111111111111111111111111111111111111 m
u https://www.morfix.co.il/שלום u
m 11111111111111111111111111111 m
u https://www.amazon.fr/GRÜNTEK-Ebrancheur-Cisailles-crémaillère-SATISFAIT/dp/B01COZUA4E/ u
m 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 m
u https://www.amazon.fr/Gardena-coupe-branches-TeleCut-520-670-télescopiques/dp/B07JLJ4N44/ u
m 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 m
Instagram links:
u https://ig.com/?query=c761&vars={"id":"0815","first":100} u
m 111111111111111111111111111111111111111111111111111111111 m
u {https://ig.com/?query=c761&vars={"id":"0815","first":100}} u
m 01111111111111111111111111111111111111111111111111111111110 m
u [https://ig.com/?query=c761&vars={"id":"0815","first":100}] u
m 01111111111111111111111111111111111111111111111111111111110 m
u "https://ig.com/?query=c761&vars={"id":"0815","first":100}" u
m 01111111111111111111111111111111111111111111111111111111110 m
Links in LaTeX:
u \href{https://weblink.com/}{click me} u
m 0000001111111111111111111100000000000 m
u \href{https://ig.com/?query=c761&vars={"id":"0815","first":100}}{click me} u
m 00000011111111111111111111111111111111111111111111111111111111100000000000 m
Mail:
u mailto:don.h@free.fr u
m 11111111111111111111 m
u <don.h@free.fr> u
m 000000000000000 m
u <mailto:don.h@free.fr> u
m 0111111111111111111110 m
u http:don.h@free.fr u
m 000000000000000000 m
FTP:
u <ftp://ds.internic.net/rfc/rfc977.txt> u
m 01111111111111111111111111111111111110 m
u ftp://host:444/0a_gopher_selector%09%09some_gplus_stuff u
m 1111111111111111111111111111111111111111111111111111111 m
u ftp://host:abc/0a_gopher_selector%09%09some_gplus_stuff u
m 0000000000000000000000000000000000000000000000000000000 m
FILE:
u file://Hello%20world.txt u
m 111111111111111111111111 m
u "file://Hello%20world.txt" u
m 01111111111111111111111110 m
u "file://Hello world.txt" u
m 011111111111100000000000 m
u file://127.0.0.1/c$/Tools\Npp%20Test%20Data/Test3/3812.pdf u
m 1111111111111111111111111111111111111111111111111111111111 m

View File

@ -0,0 +1,81 @@
OK u http://test.com u
OK u HTTP://UPCASE.UP u
OK u http: u
OK u mailto: u
OK u !http://test.com u
OK u "http://test.com u
OK u #http://test.com u
OK u $http://test.com u
OK u %http://test.com u
OK u &http://test.com u
OK u 'http://test.com u
OK u (http://test.com u
OK u )http://test.com u
OK u *http://test.com u
OK u +http://test.com u
OK u ,http://test.com u
OK u -http://test.com u
OK u .http://test.com u
OK u /http://test.com u
OK u 1http://test.com u
OK u 9http://test.com u
OK u :http://test.com u
OK u ;http://test.com u
OK u <http://test.com u
OK u >http://test.com u
OK u ?http://test.com u
OK u @http://test.com u
OK u Ahttp://test.com u
OK u Zhttp://test.com u
OK u [http://test.com u
OK u \http://test.com u
OK u ]http://test.com u
OK u ^http://test.com u
OK u _http://test.com u
OK u `http://test.com u
OK u ahttp://test.com u
OK u zhttp://test.com u
OK u {http://test.com u
OK u |http://test.com u
OK u }http://test.com u
OK u ~http://test.com u
OK u https://duckduckgo.com/?q=windows+delete+"GameBarPresenceWriter.exe" u
OK u "https://duckduckgo.com/?q=windows+delete+"GameBarPresenceWriter.exe"" u
OK u "https://duckduckgo.com/?q=windows+delete+"GameBarPresenceWriter.exe" u
OK u "https://duckduckgo/com/?q=windows+delete+GameBarPresenceWriter.exe" u
OK u "https://duckduckgo.com/?q=windows+delete+""GameBarPresenceWriter.exe" u
OK u https://www.youtube.com/watch?v=VmcftreqQ6E&list=PnQIRE5O5JpiLL&index=xxx u
OK u "http://github.com/notepad-plus-plus/notepad-plus-plus" u
OK u "https://github.com /notepad-plus-plus/notepad-plus-plus" u
OK u "https://github.com/notepad plus plus/notepad-plus-plus" u
OK u (https://github.com/notepad-plus-plus/notepad-plus-plus) u
OK u https://github.com/notepad-plus-plus/notepad-plus-plus; u
OK u https://github.com/notepad-plus-plus/notepad-plus-plus? u
OK u https://github.com/notepad-plus-plus/notepad-plus-plus! u
OK u https://github.com/notepad-plus-plus/notepad-plus-plus# u
OK u http://github.com/notepad-plus-plus/notepad-plus-plus#fragment u
OK u (e.g., https://en.wikipedia.org/wiki/Saw_(2003_film))? u
OK u (https://en.wikipedia.org/wiki/Saw_(2003_film)) u
OK u (https://en.wikipedia.org/wiki/Saw_2003_film) u
OK u https://apache-windows.ru/как-установить-сервер-apache-c-php-mysql-и-phpmyadmin-на-windows/ u
OK u https://www.rnids.rs/национални-домени/регистрација-националних-домена u
OK u https://www.morfix.co.il/שלום u
OK u https://www.amazon.fr/GRÜNTEK-Ebrancheur-Cisailles-crémaillère-SATISFAIT/dp/B01COZUA4E/ u
OK u https://www.amazon.fr/Gardena-coupe-branches-TeleCut-520-670-télescopiques/dp/B07JLJ4N44/ u
OK u https://ig.com/?query=c761&vars={"id":"0815","first":100} u
OK u {https://ig.com/?query=c761&vars={"id":"0815","first":100}} u
OK u [https://ig.com/?query=c761&vars={"id":"0815","first":100}] u
OK u "https://ig.com/?query=c761&vars={"id":"0815","first":100}" u
OK u \href{https://weblink.com/}{click me} u
OK u \href{https://ig.com/?query=c761&vars={"id":"0815","first":100}}{click me} u
OK u mailto:don.h@free.fr u
OK u <don.h@free.fr> u
OK u <mailto:don.h@free.fr> u
OK u http:don.h@free.fr u
OK u <ftp://ds.internic.net/rfc/rfc977.txt> u
OK u ftp://host:444/0a_gopher_selector%09%09some_gplus_stuff u
OK u ftp://host:abc/0a_gopher_selector%09%09some_gplus_stuff u
OK u file://Hello%20world.txt u
OK u "file://Hello%20world.txt" u
OK u "file://Hello world.txt" u
OK u file://127.0.0.1/c$/Tools\Npp%20Test%20Data/Test3/3812.pdf u

View File

@ -0,0 +1,25 @@
=== URLs which can be handled better ===
International characters directly before URL:
u ähttp://test.com u
m 0000000000000000 m
u домhttp://test.com u
m 000000000000000000 m
Apostrophes:
u https://en.wikipedia.org/wiki/Murphy's_law u
m 111111111111111111111111111111111111111111 m
u http://xxx.xxx/Tom's%20sisters'%20careers u
m 11111111111111111111111111111111111111111 m
u http://xxx.xxx/Tom's%20sisters' u
m 1111111111111111111111111111111 m
u http://xxx.xxx/Tom's%20sisters'' u
m 11111111111111111111111111111111 m

View File

@ -0,0 +1,18 @@
KO u ähttp://test.com u
ok m 0000000000000000 m
ko m 0111111111111111 m
KO u домhttp://test.com u
ok m 000000000000000000 m
ko m 000111111111111111 m
KO u https://en.wikipedia.org/wiki/Murphy's_law u
ok m 111111111111111111111111111111111111111111 m
ko m 111111111111111111111111111111111111000000 m
KO u http://xxx.xxx/Tom's%20sisters'%20careers u
ok m 11111111111111111111111111111111111111111 m
ko m 11111111111111111100000000000000000000000 m
KO u http://xxx.xxx/Tom's%20sisters' u
ok m 1111111111111111111111111111111 m
ko m 1111111111111111110000000000000 m
KO u http://xxx.xxx/Tom's%20sisters'' u
ok m 11111111111111111111111111111111 m
ko m 11111111111111111100000000000000 m

View File

@ -852,7 +852,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
// replacement for obsolete custom SCN_SCROLLED
if (notification->updated & SC_UPDATE_V_SCROLL)
{
addHotSpot();
addHotSpot(notifyView);
}
// if it's searching/replacing, then do nothing

View File

@ -77,6 +77,8 @@ after_build:
.\unitTestLauncher.ps1
.\unitTestLauncher.ps1
#ATTENTION: current working dir is no longer at APPVEYOR_BUILD_FOLDER
cd ..\UrlDetection
.\verifyUrlDetection.ps1
}
if ($env:PLATFORM_INPUT -eq "mingw") {