Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Merge pull request #538 from michelboaventura/master
Implements suffix argument to File::basename
- Loading branch information
Showing
with
10 additions
and
3 deletions.
-
+2
−0
tests/objects/test_fileobject.py
-
+8
−3
topaz/objects/fileobject.py
|
@@ -256,6 +256,8 @@ def test_basename(self, space): |
|
|
assert space.str_w(space.execute("return File.basename('ab')")) == "ab" |
|
|
assert space.str_w(space.execute("return File.basename('/ab')")) == "ab" |
|
|
assert space.str_w(space.execute("return File.basename('/foo/bar/ab')")) == "ab" |
|
|
assert space.str_w(space.execute("return File.basename('ab.rb', '.rb')")) == "ab" |
|
|
assert space.str_w(space.execute("return File.basename('ab.rb', 'b.rb')")) == "a" |
|
|
|
|
|
def test_truncate(self, space, tmpdir): |
|
|
f = tmpdir.join("file.txt") |
|
|
|
@@ -199,11 +199,16 @@ def method_identicalp(self, space, file, other): |
|
|
return space.newbool(file_stat.st_dev == other_stat.st_dev and |
|
|
file_stat.st_ino == other_stat.st_ino) |
|
|
|
|
|
@classdef.singleton_method("basename", filename="path") |
|
|
def method_basename(self, space, filename): |
|
|
@classdef.singleton_method("basename", filename="path", suffix="path") |
|
|
def method_basename(self, space, filename, suffix=None): |
|
|
i = filename.rfind("/") + 1 |
|
|
assert i >= 0 |
|
|
return space.newstr_fromstr(filename[i:]) |
|
|
filename = filename[i:] |
|
|
if suffix is not None and filename.endswith(suffix): |
|
|
end = len(filename) - len(suffix) |
|
|
assert end >= 0 |
|
|
filename = filename[:end] |
|
|
return space.newstr_fromstr(filename) |
|
|
|
|
|
@classdef.singleton_method("umask", mask="int") |
|
|
def method_umask(self, space, mask=-1): |
|
|