Skip to content

Commit

Permalink
feat(#7): move to directory dialog
Browse files Browse the repository at this point in the history
Utilities:
- list_directories
  • Loading branch information
IlyasYOY committed May 12, 2023
1 parent 086dfdb commit a4b3a28
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lua/obs/utils.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
local File = require "coredor.file"

local M = {}

function M.list_directories(path_string)
if path_string == nil then
error "path must not be nil"
end

local file = File:new(path_string)
local plenary_file = file:as_plenary()

if not plenary_file:exists() then
error("path '" .. path_string .. "' must exist")
end
if not plenary_file:is_dir() then
error(
"path '" .. path_string .. "' must point to directory, not a file"
)
end
end

return M
30 changes: 30 additions & 0 deletions lua/obs/utils_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
local spec = require "coredor.spec"
local coredor = require "coredor"

describe("list directories", function()
local utils = require "obs.utils"
local list_directories = utils.list_directories
local temp_file_fixture = spec.temp_file_fixture()

it("nil parameter causes error", function()
assert.has_error(function()
list_directories()
end, "path must not be nil")
end)

it("not existing directory causes error", function()
local invalid_directory_path = "invalid directory " .. coredor.uuid()

assert.has_error(function()
list_directories(invalid_directory_path)
end, "path '" .. invalid_directory_path .. "' must exist")
end)

it("not directory causes error", function()
local file_path = temp_file_fixture.path

assert.has_error(function()
list_directories(file_path)
end, "path '" .. file_path .. "' must point to directory, not a file")
end)
end)

0 comments on commit a4b3a28

Please sign in to comment.