Skip to content

Commit

Permalink
increase test coverage and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
prichrd committed Mar 3, 2024
1 parent 79fbe81 commit e3aa816
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 22 deletions.
44 changes: 22 additions & 22 deletions lua/netrw/parse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ local parse_liststyle_0 = function(line, curdir)
}
end

local ext = vim.fn.fnamemodify(line, ":e")
if string.sub(ext, -1) == "*" then
ext = string.sub(ext, 1, -2)
line = string.sub(line, 1, -2)
end
return {
dir = curdir,
node = line,
extension = ext,
type = M.TYPE_FILE,
}
local ext = vim.fn.fnamemodify(line, ":e")
if string.sub(ext, -1) == "*" then
ext = string.sub(ext, 1, -2)
line = string.sub(line, 1, -2)
end
return {
dir = curdir,
node = line,
extension = ext,
type = M.TYPE_FILE,
}
end

---@param line string
Expand Down Expand Up @@ -68,17 +68,17 @@ local parse_liststyle_1 = function(line, curdir)
end

local file = vim.fn.substitute(line, "^\\(\\%(\\S\\+ \\)*\\S\\+\\).\\{-}$", "\\1", "e")
local ext = vim.fn.fnamemodify(file, ":e")
if string.sub(ext, -1) == "*" then
ext = string.sub(ext, 1, -2)
file = string.sub(file, 1, -2)
end
return {
dir = curdir,
node = file,
extension = ext,
type = M.TYPE_FILE,
}
local ext = vim.fn.fnamemodify(file, ":e")
if string.sub(ext, -1) == "*" then
ext = string.sub(ext, 1, -2)
file = string.sub(file, 1, -2)
end
return {
dir = curdir,
node = file,
extension = ext,
type = M.TYPE_FILE,
}
end

---@param line string
Expand Down
18 changes: 18 additions & 0 deletions test/spec/netrw/parse_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ local testcases = {
type = parse.TYPE_SYMLINK,
},
},
{
liststyle = 0,
line = "executable.sh*",
expected = {
dir = curdir,
node = "executable.sh",
type = parse.TYPE_FILE,
},
},

--
-- liststyle 1
Expand Down Expand Up @@ -194,6 +203,15 @@ local testcases = {
extension = "md",
type = parse.TYPE_SYMLINK,
},
{
liststyle = 1,
line = "executable.sh* 56 Mon 26 Jun 09:15:59 2023",
expected = {
dir = curdir,
node = "executable.sh",
type = parse.TYPE_FILE,
},
},
},
}

Expand Down

0 comments on commit e3aa816

Please sign in to comment.