perf(utils): linear scan is_uri (#2648)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
local utils = require "telescope.utils"
|
||||
|
||||
describe("is_uri", function()
|
||||
it("detects valid uris", function()
|
||||
describe("detects valid uris", function()
|
||||
local uris = {
|
||||
[[https://www.example.com/index.html]],
|
||||
[[ftp://ftp.example.com/files/document.pdf]],
|
||||
@@ -16,40 +16,64 @@ describe("is_uri", function()
|
||||
}
|
||||
|
||||
for _, uri in ipairs(uris) do
|
||||
assert.True(utils.is_uri(uri))
|
||||
it(uri, function()
|
||||
assert.True(utils.is_uri(uri))
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
it("handles windows paths", function()
|
||||
describe("detects invalid uris/paths", function()
|
||||
local inputs = {
|
||||
"hello",
|
||||
"hello:",
|
||||
"123",
|
||||
}
|
||||
for _, input in ipairs(inputs) do
|
||||
it(input, function()
|
||||
assert.False(utils.is_uri(input))
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
describe("handles windows paths", function()
|
||||
local paths = {
|
||||
[[C:\Users\Usuario\Documents\archivo.txt]],
|
||||
[[D:\Projects\project_folder\source_code.py]],
|
||||
[[E:\Music\song.mp3]],
|
||||
}
|
||||
for _, path in ipairs(paths) do
|
||||
assert.False(utils.is_uri(path))
|
||||
|
||||
for _, uri in ipairs(paths) do
|
||||
it(uri, function()
|
||||
assert.False(utils.is_uri(uri))
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
it("handles linux paths", function()
|
||||
describe("handles linux paths", function()
|
||||
local paths = {
|
||||
[[/home/usuario/documents/archivo.txt]],
|
||||
[[/var/www/html/index.html]],
|
||||
[[/mnt/backup/backup_file.tar.gz]],
|
||||
}
|
||||
|
||||
for _, path in ipairs(paths) do
|
||||
assert.False(utils.is_uri(path))
|
||||
it(path, function()
|
||||
assert.False(utils.is_uri(path))
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
it("handles macos paths", function()
|
||||
describe("handles macos paths", function()
|
||||
local paths = {
|
||||
[[/Users/Usuario/Documents/archivo.txt]],
|
||||
[[/Applications/App.app/Contents/MacOS/app_executable]],
|
||||
[[/Volumes/ExternalDrive/Data/file.xlsx]],
|
||||
}
|
||||
|
||||
for _, path in ipairs(paths) do
|
||||
assert.False(utils.is_uri(path))
|
||||
it(path, function()
|
||||
assert.False(utils.is_uri(path))
|
||||
end)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user