Skip to content

Commit

Permalink
test(util): add file extension tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HakonHarnes committed Dec 6, 2023
1 parent 9c716d1 commit e6bd2b0
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions tests/util_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,28 @@ local util = require("img-clip.util")

describe("util", function()
it("can get the directory path from the file path", function()
-- construct test input
local path_separator = package.config:sub(1, 1)
local test_path = "path" .. path_separator .. "to" .. path_separator .. "file.txt"
local expected_dir_path = "path" .. path_separator .. "to" .. path_separator

-- check if the correct directory path is returned
local dir_path = util.get_dir_path_from_filepath(test_path)
assert.equals(expected_dir_path, dir_path)
end)

it("can add a file extension to a filename", function()
assert.equals("file.png", util.add_file_ext("file", "png"))
assert.equals("file.png", util.add_file_ext("file.png", "png"))
assert.equals("file.png", util.add_file_ext("file.jpg", "png"))
assert.equals("file.png", util.add_file_ext("file.hello.world", "png"))
assert.equals("file.jpg", util.add_file_ext("file", "jpg"))
end)

it("can add a file extension to a filepath", function()
local path_separator = package.config:sub(1, 1)
local test_filepath = "path" .. path_separator .. "to" .. path_separator .. "file"
local expected_filepath = "path" .. path_separator .. "to" .. path_separator .. "file.png"

local filepath = util.add_file_ext(test_filepath, "png")
assert.equals(expected_filepath, filepath)
end)
end)

0 comments on commit e6bd2b0

Please sign in to comment.