Skip to content

Commit

Permalink
移除equal_extension
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Apr 2, 2024
1 parent a2914d5 commit ab1f346
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 34 deletions.
22 changes: 3 additions & 19 deletions binding/lua_filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ namespace bee::lua_filesystem {

static int extension(lua_State* L) {
path_ptr self = getpathptr(L, 1);
push(L, self->extension());
auto u8str = self->extension().generic_u8string();
auto str = u8tostrview(u8str);
lua_pushlstring(L, str.data(), str.size());
return 1;
}

Expand Down Expand Up @@ -292,23 +294,6 @@ namespace bee::lua_filesystem {
return 1;
}

static int equal_extension(lua_State* L) {
path_ptr self = getpathptr(L, 1);
path_ptr path = getpathptr(L, 2);
auto selfext = self->extension();
auto pathext = path->native();
if (selfext.empty()) {
lua_pushboolean(L, pathext.empty());
return 1;
}
if (pathext[0] != '.') {
lua_pushboolean(L, path_helper::equal(selfext, fs::path::string_type { '.' } + pathext));
return 1;
}
lua_pushboolean(L, path_helper::equal(selfext, pathext));
return 1;
}

static int lexically_normal(lua_State* L) {
path_ptr self = getpathptr(L, 1);
push(L, self->lexically_normal());
Expand Down Expand Up @@ -356,7 +341,6 @@ namespace bee::lua_filesystem {
{ "remove_filename", remove_filename },
{ "replace_filename", replace_filename },
{ "replace_extension", replace_extension },
{ "equal_extension", equal_extension },
{ "lexically_normal", lexically_normal },
{ NULL, NULL },
};
Expand Down
16 changes: 1 addition & 15 deletions test/test_filesystem.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ end

function test_fs:test_extension()
local function get_extension(path)
return fs.path(path):extension():string()
return fs.path(path):extension()
end
lt.assertEquals(get_extension("a/b/c.ext"), ".ext")
lt.assertEquals(get_extension("a/b/c"), "")
Expand Down Expand Up @@ -192,20 +192,6 @@ function test_fs:test_replace_extension()
lt.assertEquals(replace_extension("c.ext", ".lua"), "c.lua")
end

function test_fs:test_equal_extension()
local function equal_extension(path, ext)
return lt.assertEquals(fs.path(path):equal_extension(ext), true)
end
equal_extension("a/b/c.ext", ".ext")
equal_extension("a/b/c.ext", "ext")
equal_extension("a/b/c", "")
equal_extension("a/b/.ext", "")
equal_extension("a/b/c.", ".")
equal_extension("a/b/c..", ".")
equal_extension("a/b/c..lua", ".lua")
equal_extension("a/b/c..lua", "lua")
end

function test_fs:test_get_permissions()
local filename = "temp.txt"
create_file(filename)
Expand Down

0 comments on commit ab1f346

Please sign in to comment.