Change os/perm-str to os/perm-string.

This commit is contained in:
Calvin Rose 2020-04-03 15:23:29 -05:00
parent 95f1ef7561
commit a0d61e45d5
4 changed files with 20 additions and 5 deletions

View File

@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
## Unreleased - ???
- Add os/umask
- Add os/perm-int
- Add os/perm-str
- Add os/perm-string
## 1.8.1 - 2020-03-31
- Fix bugs for big endian systems

View File

@ -1303,7 +1303,7 @@ static const JanetReg os_cfuns[] = {
"os/chmod", os_chmod,
JDOC("(os/chmod path mode)\n\n"
"Change file permissions, where mode is a permission string as returned by "
"os/perm-str, or an integer as returned by os/perm-int. "
"os/perm-string, or an integer as returned by os/perm-int. "
"When mode is an integer, it is interpreted as a Unix permission value, best specified in octal, like "
"8r666 or 8r400. Windows will not differentiate between user, group, and other permissions, and thus will combine all of these permissions. Returns nil.")
},
@ -1445,8 +1445,8 @@ static const JanetReg os_cfuns[] = {
"Returns an absolute path as a string. Will raise an error on Windows.")
},
{
"os/perm-str", os_permission_string,
JDOC("(os/perm-str int)\n\n"
"os/perm-string", os_permission_string,
JDOC("(os/perm-string int)\n\n"
"Convert a Unix octal permission value from a permission integer as returned by os/stat "
"to a human readable string, that follows the formatting "
"of unix tools like ls. Returns the string as a 9 character string of r, w, x and - characters. Does not "

View File

@ -8,7 +8,8 @@
(defn assert
"Override's the default assert with some nice error handling."
[x e]
[x &opt e]
(default e "assert error")
(++ num-tests-run)
(when x (++ num-tests-passed))
(if x

View File

@ -194,4 +194,18 @@
(assert (deep= @[] (accumulate2 + [])) "accumulate2 2")
(assert (deep= @[] (accumulate 0 + [])) "accumulate 2")
# Perm strings
(assert (= (os/perm-int "rwxrwxrwx") 8r777) "perm 1")
(assert (= (os/perm-int "rwxr-xr-x") 8r755) "perm 2")
(assert (= (os/perm-int "rw-r--r--") 8r644) "perm 3")
(assert (= (band (os/perm-int "rwxrwxrwx") 8r077) 8r077) "perm 4")
(assert (= (band (os/perm-int "rwxr-xr-x") 8r077) 8r055) "perm 5")
(assert (= (band (os/perm-int "rw-r--r--") 8r077) 8r044) "perm 6")
(assert (= (os/perm-string 8r777) "rwxrwxrwx") "perm 7")
(assert (= (os/perm-string 8r755) "rwxr-xr-x") "perm 8")
(assert (= (os/perm-string 8r644) "rw-r--r--") "perm 9")
(end-suite)