mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
path: add helper for checking a file extension
This commit is contained in:
parent
70d0bee765
commit
13b8857300
@ -1704,6 +1704,13 @@ int path_with_url(const char *fname)
|
|||||||
return path_is_url(p);
|
return path_is_url(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool path_with_extension(const char *path, const char *extension)
|
||||||
|
{
|
||||||
|
const char *last_dot = strrchr(path, '.');
|
||||||
|
if (!last_dot) { return false; }
|
||||||
|
return strcmp(last_dot + 1, extension) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return TRUE if "name" is a full (absolute) path name or URL.
|
* Return TRUE if "name" is a full (absolute) path name or URL.
|
||||||
*/
|
*/
|
||||||
|
@ -603,4 +603,21 @@ describe('path.c', function()
|
|||||||
eq(FAIL, path_is_absolute('not/in/my/home~/directory'))
|
eq(FAIL, path_is_absolute('not/in/my/home~/directory'))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('path_with_extension', function()
|
||||||
|
local function path_with_extension(filename, extension)
|
||||||
|
local c_filename = to_cstr(filename)
|
||||||
|
local c_extension = to_cstr(extension)
|
||||||
|
return cimp.path_with_extension(c_filename, c_extension)
|
||||||
|
end
|
||||||
|
|
||||||
|
itp('returns true if filename includes a provided extension', function()
|
||||||
|
eq(true, path_with_extension('/some/path/file.lua', 'lua'))
|
||||||
|
end)
|
||||||
|
|
||||||
|
itp('returns false if filename does not include a provided extension', function()
|
||||||
|
eq(false, path_with_extension('/some/path/file.vim', 'lua'))
|
||||||
|
eq(false, path_with_extension('/some/path/file', 'lua'))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user