lib/file: more documentation and nitunit tests
authorJean Privat <jean@pryen.org>
Fri, 21 Mar 2014 15:32:37 +0000 (11:32 -0400)
committerJean Privat <jean@pryen.org>
Fri, 21 Mar 2014 15:32:37 +0000 (11:32 -0400)
Fixes #160
Fixes #161
Signed-off-by: Jean Privat <jean@pryen.org>

lib/standard/file.nit

index 93094e4..93020b8 100644 (file)
@@ -219,7 +219,10 @@ redef class String
        # return true if a file with this names exists
        fun file_exists: Bool do return to_cstring.file_exists
 
+       # The status of a file. see POSIX stat(2).
        fun file_stat: FileStat do return to_cstring.file_stat
+
+       # The status of a file or of a symlink. see POSIX lstat(2).
        fun file_lstat: FileStat do return to_cstring.file_lstat
 
        # Remove a file, return true if success
@@ -240,7 +243,17 @@ redef class String
                output.close
        end
 
-       # remove the trailing extension "ext"
+       # Remove the trailing extension `ext`.
+       #
+       # `ext` usually starts with a dot but could be anything.
+       #
+       #     assert "file.txt".strip_extension(".txt")  == "file"
+       #     assert "file.txt".strip_extension("le.txt")  == "fi"
+       #     assert "file.txt".strip_extension("xt")  == "file.t"
+       #
+       # if `ext` is not present, `self` is returned unmodified.
+       #
+       #     assert "file.txt".strip_extension(".tar.gz")  == "file.txt"
        fun strip_extension(ext: String): String
        do
                if has_suffix(ext) then