mirror of
https://github.com/zoriya/telescope.nvim.git
synced 2026-08-10 08:08:15 +00:00
In order to maintain plenary compatibility (for now, and slightly for
other edgecase reasons), avoid converting backslashes to forward
slashes.
(cherry picked from commit 1e59188575)
106 lines
2.7 KiB
Lua
106 lines
2.7 KiB
Lua
local utils = require "telescope.utils"
|
|
|
|
describe("path_expand()", function()
|
|
it("removes trailing /", function()
|
|
assert.is.equal("/home/user", utils.path_expand "/home/user/")
|
|
end)
|
|
|
|
it("works with /", function()
|
|
assert.is.equal("/", utils.path_expand "/")
|
|
end)
|
|
|
|
it("works with ~", function()
|
|
assert.is.equal(vim.loop.os_homedir() .. "/src/foo", utils.path_expand "~/src/foo")
|
|
end)
|
|
|
|
it("handles duplicate /", function()
|
|
assert.is.equal("/home/user", utils.path_expand "/home///user")
|
|
end)
|
|
|
|
it("preserves fake whitespace characters and whitespace", function()
|
|
local path_space = "/home/user/hello world"
|
|
assert.is.equal(path_space, utils.path_expand(path_space))
|
|
local path_newline = [[/home/user/hello\nworld]]
|
|
assert.is.equal(path_newline, utils.path_expand(path_newline))
|
|
end)
|
|
end)
|
|
|
|
describe("is_uri", function()
|
|
describe("detects valid uris", function()
|
|
local uris = {
|
|
[[https://www.example.com/index.html]],
|
|
[[ftp://ftp.example.com/files/document.pdf]],
|
|
[[mailto:user@example.com]],
|
|
[[tel:+1234567890]],
|
|
[[file:///home/user/documents/report.docx]],
|
|
[[news:comp.lang.python]],
|
|
[[ldap://ldap.example.com:389/dc=example,dc=com]],
|
|
[[git://github.com/user/repo.git]],
|
|
[[steam://run/123456]],
|
|
[[magnet:?xt=urn:btih:6B4C3343E1C63A1BC36AEB8A3D1F52C4EDEEB096]],
|
|
}
|
|
|
|
for _, uri in ipairs(uris) do
|
|
it(uri, function()
|
|
assert.True(utils.is_uri(uri))
|
|
end)
|
|
end
|
|
end)
|
|
|
|
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 _, uri in ipairs(paths) do
|
|
it(uri, function()
|
|
assert.False(utils.is_uri(uri))
|
|
end)
|
|
end
|
|
end)
|
|
|
|
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
|
|
it(path, function()
|
|
assert.False(utils.is_uri(path))
|
|
end)
|
|
end
|
|
end)
|
|
|
|
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
|
|
it(path, function()
|
|
assert.False(utils.is_uri(path))
|
|
end)
|
|
end
|
|
end)
|
|
end)
|