Merge branch 'master' into 3236-move-eo-sys

This commit is contained in:
Roman Korostinskiy 2024-08-05 09:57:18 +03:00
commit e227565b94
No known key found for this signature in database
44 changed files with 2392 additions and 147 deletions

View File

@ -40,3 +40,23 @@ exclude_paths:
- "eo-runtime/src/test/java/EOorg/EOeolang/EOsys/DispatchedUnixSyscallTest.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOsys/EOunix.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOsys/CStdLib.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOdir$EOmade$EOmkdir.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOdir$EOtmpfile$EOtouch.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOdir$EOwalk.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOfile$EOdeleted$EOdelete.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOfile$EOexists.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOfile$EOis_directory.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOfile$EOmoved$EOmove.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/package-info.java"
- "eo-runtime/src/test/java/EOorg/EOeolang/EOfs/package-info.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOfile$EOopen$EOfile_stream$EOwrite$EOwritten_bytes.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOfile$EOopen$EOfile_stream$EOread$EOread_bytes.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOfile$EOopen$EOprocess_file.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOfile$EOresolved$EOresolve.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOfile$EOsize.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOfile$EOtouched$EOtouch.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/Files.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOsys/EOgetenv.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOsys/EOos$EOname.java"
- "eo-runtime/src/test/java/EOorg/EOeolang/EOfs/FilesTest.java"
- "eo-runtime/src/test/java/EOorg/EOeolang/EOfs/EOfileTest.java"

2
.github/.typos.toml vendored Normal file
View File

@ -0,0 +1,2 @@
[files]
extend-exclude = ["eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOfile$EOis_directory.java"]

View File

@ -35,3 +35,5 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: crate-ci/typos@master
with:
config: ./.github/.typos.toml

View File

@ -32,7 +32,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: zerocracy/judges-action@0.0.37
- uses: zerocracy/judges-action@0.0.40
with:
token: ${{ secrets.ZEROCRACY_TOKEN }}
options: |
@ -40,7 +40,7 @@ jobs:
vitals_url=https://www.eolang.org/zerocracy/objectionary-vitals.html
repositories=objectionary/*
factbase: objectionary.fb
- uses: zerocracy/pages-action@0.0.26
- uses: zerocracy/pages-action@0.0.33
with:
factbase: objectionary.fb
output: pages

View File

@ -35,7 +35,7 @@ create a file `pom.xml` with this content (it's just a sample):
<plugin>
<groupId>org.eolang</groupId>
<artifactId>eo-maven-plugin</artifactId>
<version>0.38.4</version>
<version>0.39.0</version>
<executions>
<execution>
<goals>
@ -156,7 +156,7 @@ execution within `eo-maven-plugin/pom.xml`:
...
<plugin>
<artifactId>maven-invoker-plugin</artifactId>
<version>0.38.4</version>
<version>0.39.0</version>
<configuration>
<skipInstallation>true</skipInstallation>
<skipInvocation>true</skipInvocation>

View File

@ -0,0 +1,112 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 Objectionary.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
+alias org.eolang.txt.sprintf
+architect yegor256@gmail.com
+home https://github.com/objectionary/eo
+package org.eolang.fs
+rt jvm org.eolang:eo-runtime:0.0.0
+rt node eo2js-runtime:0.0.0
+version 0.0.0
# Directory in the file system.
# Apparently every directory is a file.
[file] > dir
$.file > @
true > is-directory
# Makes a directory together with all required
# parent directories and returns the created directory.
[] > made
if. > @
^.exists
^
seq
*
mkdir
^
# Makes a directory together with all required
# parent directories.
#
# Attention! The object is for internal usage only, please
# don't use it programmatically outside of `dir` object.
[] > mkdir /true
# Goes though all files in the directory, recursively
# finding them with the `glob` provided.
# Returns `tuple` of all files in the directory.
[glob] > walk /tuple
# Deletes directory and all files in it, recursively.
# Returns the deleted directory.
[] > deleted
(^.walk "**").at.^ > walked
walked.length > len!
if. > @
^.exists
seq
*
rec-delete walked 0
^
^
# Deletes files and directories in current directory recursively.
# Returns `true`.
#
# Attention! The object is for internal usage only, please
# don't use the object programmatically outside of `dir` object.
[tup index] > rec-delete
if. > @
^.len.eq index
true
seq
*
tup.tail.deleted.exists
^.rec-delete
tup.head
index.plus 1
# Creates an empty temporary file in the current directory.
[] > tmpfile
if. > @
^.exists
QQ.fs.file touch.as-bytes.as-string
error
sprintf
"Directory %s does not exist, can't create temporary file"
* ^.path
# Creates an empty temporary file in the current directory and
# returns absolute path to it as `string`.
#
# Attention! The object is for internal usage only, please
# don't use the object programmatically outside of the `dir` object.
[] > touch /string
# Opens the file for I/O operations.
# Since current file is a directory - returns an `error`.
[mode scope] > open
error > @
sprintf
"The file %s is a directory, can't open for I/O operations"
* ^.path

View File

@ -0,0 +1,291 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 Objectionary.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
+alias org.eolang.sys.os
+alias org.eolang.txt.sprintf
+architect yegor256@gmail.com
+home https://github.com/objectionary/eo
+package org.eolang.fs
+rt jvm org.eolang:eo-runtime:0.0.0
+rt node eo2js-runtime:0.0.0
+version 0.0.0
# A file on the filesystem.
[path] > file
path > @
# Returns `true` if current file is a directory, returns `false` otherwise.
[] > is-directory /bool
# The system-dependent default name-separator character.
# On UNIX systems the value of this field is "/";
# on Microsoft Windows systems it is "\\".
[] > separator
string > @
as-bytes.
if.
os.is-windows
"\\"
"/"
# Resolves `other` path against `path` and returns as new `file` from it.
[other] > resolved
QQ.fs.file resolve.as-bytes.as-string > @
# Resolves `other` path against `^.path` and returns as `string`.
#
# Attention! The object is for internal usage only, please
# don't use the object programmatically outside of `file` object.
[] > resolve /string
# Returns `true` if file with current `path` exists in filesystem.
[] > exists /bool
# If current file exists - returns the file.
# If current file does not exist - create an empty file
# in filesystem and returns it.
[] > touched
if. > @
^.exists
^
seq
*
touch
^
# Creates new empty file.
#
# Attention! The object is for internal usage only, please
# don't use the object programmatically outside of `file` object.
[] > touch /true
# If current file exists - deletes it and returns it.
# If current file does not exist - just returns it.
[] > deleted
if. > @
^.exists
seq
*
delete
^
^
# Deletes the file and and returns `true`.
#
# Attention! The object is for internal usage only, please
# don't use the object programmatically outside of `file` object.
[] > delete /true
# Get file size in bytes.
[] > size /number
# Move current file to `target`, making and returning a new `file` from it.
[target] > moved
QQ.fs.file move.as-bytes.as-string > @
# Tries to move file from `^.path` to `target`
# and returns path of moved file as `string`.
# Returns `error` is failed to move the file.
#
# Attention! The object is for internal usage only, please
# don't use the object programmatically outside of `file` object.
[] > move /string
# Opens the file.
#
# The first argument `mode` defines the operations that are allowed on the file
# and how these operations are performed.
#
# The access mode can be:
# |------|-------------|----------------------|-------------------|----------------------|
# | Mode | Description | File Existence | Init pointer pos | Content Handling |
# |======|=============|======================|===================|======================|
# | "r" | Read only | Must exist | Beginning | No changes |
# |------|-------------|----------------------|-------------------|----------------------|
# | "w" | Write only | Created if not exist | Beginning | Truncated if exists, |
# | | | | | created if not |
# |------|-------------|----------------------|-------------------|----------------------|
# | "a" | Append only | Created if not exist | End | No truncation, |
# | | | | | created if not |
# |------|-------------|----------------------|-------------------|----------------------|
# | "r+" | Read/Write | Must exist | Beginning | No changes |
# |------|-------------|----------------------|-------------------|----------------------|
# | "w+" | Write/Read | Created if not exist | Beginning | Truncated if exists, |
# | | | | | created if not |
# |------|-------------|----------------------|-------------------|----------------------|
# | "a+" | Read/Append | Created if not exist | End (for writing) | No truncation, |
# | | | | | created if not |
# |------|-------------|----------------------|-------------------|----------------------|
#
# The second argument `scope` is the scope where file is available as input
# (the `read` object is available) or output (the `write` object is available).
#
# When `file.open` is dataized - it opens file stream, dataizes the `scope`,
# closes the file stream and returns an original file object.
[mode scope] > open
mode > access!
access.eq "r" > read
access.eq "w" > write
access.eq "a" > append
access.eq "r+" > read-write
access.eq "w+" > write-read
access.eq "a+" > read-append
as-bool. > can-read
or.
read.or read-write
write-read.or read-append
as-bool. > can-write
or.
or.
write.or read-write
write-read.or read-append
append
as-bool. > must-exists
read.or read-write
as-bool. > truncate
write.or write-read
if. > @
can-read.not.and can-write.not
error "Wrong access mod. Only next modes are available: 'r', 'w', 'a', 'r+', 'w+', 'a+'"
if.
^.exists.not
if.
must-exists
error
sprintf
"File must exist for given access mod: '%s'"
* access
seq
*
^.touched.touch
process-file
^
if.
truncate
seq
*
^.deleted.delete
^.touched.touch
process-file
^
seq
*
process-file
^
# Process current file in the provided scope.
#
# Here file stream is open, then the stream is passed to `scope`,
# then given `scope` is dataized and stream is closed.
# Returns `true` if there are no errors occurred while `scope`
# dataization, returns `error` otherwise.
#
# The object is stream-safe, which means that stream is closed anyway,
# even if errors are occurred while `scope` dataization.
#
# Attention! The object is for internal usage only, please
# don't use the object programmatically outside of the `file` object.
[] > process-file /true
# File stream.
# The objects provides an API for using file as input or output.
[] > file-stream
# Read `size` amount of bytes from file input stream.
# Returns new instance of `input-block` with `buffer` read from file, or
# returns `error` if access mode does not allow reading operations.
[size] > read
((input-block --).read size).self > @
# File input block
#
# Attention! The object is for internal usage only, please
# don't use the object programmatically outside of `file` object.
[buffer] > input-block
$ > self
buffer > @
# Read `size` amount of bytes from file input stream.
# Returns new instance of `input-block` with `buffer` read from file, or
# returns `error` if provided access mode does not allow reading operations.
[size] > read
^.^.read-bytes size > read-bytes!
self. > @
if.
^.^.^.^.can-read.not
[] >>
$ > self
error > @
sprintf
"Can't read from file with provided access mode '%s'"
* ^.^.^.^.^.access
seq
*
read-bytes
^.^.input-block read-bytes
# Bytes read from file input stream
#
# Attention! The object is for internal usage only, please
# don't use the object programmatically outside of `file` object.
[size] > read-bytes /bytes
# Write given `buffer` to file output stream.
# Here `buffer` is either sequence of bytes or and object that can be
# dataized via `as-bytes` object.
# Returns new instance of `output-block` ready to write again, or
# returns an error if provided access mode does not allow writing operations.
[buffer] > write
(output-block.write buffer).self > @
# File output block.
#
# Attention! The object is for internal usage only, please
# don't use the object programmatically outside of `file` object.
[] > output-block
$ > self
true > @
# Write given `buffer` to file output stream.
# Here `buffer` is either sequence of bytes or and object that can be
# dataized via `as-bytes` object.
# Returns new instance of `output-block` ready to write again, or
# returns an error if provided access mode does not allow writing operations.
[buffer] > write
self. > @
if.
^.^.^.^.can-write.not
[] >>
$ > self
error > @
sprintf
"Can't write to file with provided access mode '%s'"
* ^.^.^.^.^.access
seq
*
^.^.written-bytes buffer
^.^.output-block
# Bytes written to file output stream.
#
# Attention! The object is for internal usage only, please
# don't use the object programmatically outside of `file` object.
[buffer] > written-bytes /true

View File

@ -0,0 +1,76 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 Objectionary.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
+alias org.eolang.fs.dir
+alias org.eolang.fs.file
+alias org.eolang.sys.getenv
+alias org.eolang.sys.os
+architect yegor256@gmail.com
+home https://github.com/objectionary/eo
+package org.eolang.fs
+rt jvm org.eolang:eo-runtime:0.0.0
+rt node eo2js-runtime:0.0.0
+version 0.0.0
# Temporary directory.
# For Unix/MacOS uses the path supplied by the first environment variable
# found in the list TMPDIR, TMP, TEMP, TEMPDIR.
# If none of these are found, "/tmp" is used.
#
# For Windows uses the path reported by the Windows "GetTempPath" API function which
# takes the first environment variable in the list TMP, TEMP, USERPROFILE.
# If none of these are found, it returns the Windows directory (C:\Windows).
[] > tmpdir
dir > @
file
string
[] > os-tmp-dir!
getenv "TMPDIR" > tmpdir!
getenv "TMP" > tmp!
getenv "TEMP" > temp!
getenv "TEMPDIR" > tempdir!
getenv "USERPROFILE" > userprofile!
if. > @
os.is-windows
if.
tmp.eq ""
if.
temp.eq ""
if.
userprofile.eq ""
"C:\\Windows"
userprofile
temp
tmp
if.
tmpdir.eq ""
if.
tmp.eq ""
if.
temp.eq ""
if.
tempdir.eq ""
"/tmp"
tempdir
temp
tmp
tmpdir

View File

@ -96,9 +96,9 @@
# Write given `buffer` to console.
# Here `buffer` is either sequence of bytes or and object that can be
# dataized via `as-bytes` object.
# Returns new instance of `output-block` ready to write again.
[buffer] > write
self. > @
output-block.write buffer
(output-block.write buffer).self > @
# Console output block.
#
@ -111,10 +111,11 @@
# Writes bytes contained in `buffer` to operation system console.
# Returns new instance of `output-block` ready to write again.
[buffer] > write
seq > @
*
^.^.written-bytes buffer
^.^.output-block
self. > @
seq
*
^.^.written-bytes buffer
^.^.output-block
# Bytes written to operation system console.
#

View File

@ -0,0 +1,34 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 Objectionary.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
+architect yegor256@gmail.com
+home https://github.com/objectionary/eo
+package org.eolang.sys
+rt jvm org.eolang:eo-runtime:0.0.0
+rt node eo2js-runtime:0.0.0
+version 0.0.0
# Get environment variable as `string`.
# If return `string` is empty - the variable does not exist.
#
# See https://man7.org/linux/man-pages/man3/getenv.3.html
[name] > getenv /string

View File

@ -20,7 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
+alias org.eolang.sys.uname
+alias org.eolang.sys.os
+architect yegor256@gmail.com
+home https://github.com/objectionary/eo
+package org.eolang.sys
@ -32,7 +32,9 @@
# On UNIX systems, it returns "\n";
# on Microsoft Windows systems it returns "\r\n".
[] > line-separator
if. > @
uname.is-windows
"\r\n"
"\n"
string > @
as-bytes.
if.
os.is-windows
"\r\n"
"\n"

View File

@ -28,10 +28,11 @@
+rt node eo2js-runtime:0.0.0
+version 0.0.0
# Represents the name of the operation system.
# See https://man7.org/linux/man-pages/man2/uname.2.html.
[] > uname
[] > @ /string
((regex "/^Windows.+$/").matches @).as-bool > is-windows
((regex "/linux/i").matches @).as-bool > is-linux
((regex "/mac/i").matches @).as-bool > is-macos
# Represents the name of the operating system.
[] > os
name > @
((regex "/^Windows.+$/").matches name).as-bool > is-windows
((regex "/linux/i").matches name).as-bool > is-linux
((regex "/mac/i").matches name).as-bool > is-macos
[] > name /string

View File

@ -0,0 +1,57 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* @checkstyle PackageNameCheck (4 lines)
*/
package EOorg.EOeolang.EOfs;
import java.nio.file.Paths;
import org.eolang.Atom;
import org.eolang.Attr;
import org.eolang.Data;
import org.eolang.Dataized;
import org.eolang.PhDefault;
import org.eolang.Phi;
import org.eolang.XmirObject;
/**
* Dir.made.mkdir.
*
* @since 0.40
* @checkstyle TypeNameCheck (100 lines)
*/
@XmirObject(oname = "dir.made.mkdir")
public final class EOdir$EOmade$EOmkdir extends PhDefault implements Atom {
@Override
public Phi lambda() throws Exception {
return new Data.ToPhi(
Paths.get(
new Dataized(
this.take(Attr.RHO).take(Attr.RHO).take("file").take("path")
).asString()
).toFile().mkdirs()
);
}
}

View File

@ -0,0 +1,60 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* @checkstyle PackageNameCheck (4 lines)
*/
package EOorg.EOeolang.EOfs;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.eolang.Atom;
import org.eolang.Attr;
import org.eolang.Data;
import org.eolang.Dataized;
import org.eolang.PhDefault;
import org.eolang.Phi;
import org.eolang.XmirObject;
/**
* Dir.tmpfile.touch.
*
* @since 0.40
* @checkstyle TypeNameCheck (100 lines)
*/
@XmirObject(oname = "dir.tmpfile.touch")
public final class EOdir$EOtmpfile$EOtouch extends PhDefault implements Atom {
@Override
public Phi lambda() throws Exception {
final Path home = Paths.get(
new Dataized(
this.take(Attr.RHO).take(Attr.RHO).take("path")
).asString()
);
final Path path = Files.createTempFile(home, null, null);
path.toFile().deleteOnExit();
return new Data.ToPhi(path.toAbsolutePath().toString());
}
}

View File

@ -0,0 +1,87 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* @checkstyle PackageNameCheck (4 lines)
*/
package EOorg.EOeolang.EOfs;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.Paths;
import org.eolang.AtVoid;
import org.eolang.Atom;
import org.eolang.Attr;
import org.eolang.Data;
import org.eolang.Dataized;
import org.eolang.PhDefault;
import org.eolang.Phi;
import org.eolang.XmirObject;
/**
* Dir.walk.
*
* @since 0.40
* @checkstyle TypeNameCheck (100 lines)
*/
@XmirObject(oname = "dir.walk")
public final class EOdir$EOwalk extends PhDefault implements Atom {
/**
* Ctor.
*/
public EOdir$EOwalk() {
this.add("glob", new AtVoid("glob"));
}
@Override
public Phi lambda() throws Exception {
final Path path = Paths.get(
new Dataized(
this.take(Attr.RHO).take("file").take("path")
).asString()
).toAbsolutePath();
final String glob = new Dataized(
this.take("glob")
).asString();
final PathMatcher matcher = FileSystems.getDefault().getPathMatcher(
String.format("glob:%s", glob)
);
return new Data.ToPhi(
Files.walk(path)
.map(p -> p.toAbsolutePath().toString())
.map(p -> p.substring(p.indexOf(path.toString())))
.filter(p -> matcher.matches(Paths.get(p)))
.map(
p -> {
final Phi file = Phi.Φ.take("org.eolang.fs.file").copy();
file.put(0, new ToPhi(p));
return file;
}
)
.toArray(Phi[]::new)
);
}
}

View File

@ -0,0 +1,59 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* @checkstyle PackageNameCheck (4 lines)
*/
package EOorg.EOeolang.EOfs;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.eolang.Atom;
import org.eolang.Attr;
import org.eolang.Data;
import org.eolang.Dataized;
import org.eolang.PhDefault;
import org.eolang.Phi;
import org.eolang.XmirObject;
/**
* File.deleted.delete.
*
* @since 0.40
* @checkstyle TypeNameCheck (100 lines)
*/
@XmirObject(oname = "file.deleted.delete")
public final class EOfile$EOdeleted$EOdelete extends PhDefault implements Atom {
@Override
public Phi lambda() throws Exception {
Files.delete(
Paths.get(
new Dataized(
this.take(Attr.RHO).take(Attr.RHO).take("path")
).asString()
)
);
return new Data.ToPhi(true);
}
}

View File

@ -0,0 +1,60 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* @checkstyle PackageNameCheck (4 lines)
*/
package EOorg.EOeolang.EOfs;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.eolang.Atom;
import org.eolang.Attr;
import org.eolang.Data;
import org.eolang.Dataized;
import org.eolang.PhDefault;
import org.eolang.Phi;
import org.eolang.XmirObject;
/**
* File.exists.
*
* @since 0.40
* @checkstyle TypeNameCheck (100 lines)
*/
@XmirObject(oname = "file.exists")
public final class EOfile$EOexists extends PhDefault implements Atom {
@Override
public Phi lambda() throws Exception {
return new Data.ToPhi(
Files.exists(
Paths.get(
new Dataized(
this.take(Attr.RHO).take("path")
).asString()
)
)
);
}
}

View File

@ -0,0 +1,57 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* @checkstyle PackageNameCheck (4 lines)
*/
package EOorg.EOeolang.EOfs;
import java.nio.file.Paths;
import org.eolang.Atom;
import org.eolang.Attr;
import org.eolang.Data;
import org.eolang.Dataized;
import org.eolang.PhDefault;
import org.eolang.Phi;
import org.eolang.XmirObject;
/**
* File.is-directory.
*
* @since 0.40
* @checkstyle TypeNameCheck (100 lines)
*/
@XmirObject(oname = "file.is-directory")
public final class EOfile$EOis_directory extends PhDefault implements Atom {
@Override
public Phi lambda() throws Exception {
return new Data.ToPhi(
Paths.get(
new Dataized(
this.take(Attr.RHO).take("path")
).asString()
).toFile().isDirectory()
);
}
}

View File

@ -0,0 +1,61 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* @checkstyle PackageNameCheck (4 lines)
*/
package EOorg.EOeolang.EOfs;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.eolang.Atom;
import org.eolang.Attr;
import org.eolang.Data;
import org.eolang.Dataized;
import org.eolang.PhDefault;
import org.eolang.Phi;
import org.eolang.XmirObject;
/**
* File.moved.move.
*
* @since 0.40
* @checkstyle TypeNameCheck (100 lines)
*/
@XmirObject(oname = "file.moved.move")
public final class EOfile$EOmoved$EOmove extends PhDefault implements Atom {
@Override
public Phi lambda() throws Exception {
final Phi rho = this.take(Attr.RHO);
final Path target = Paths.get(
new Dataized(rho.take("target")).asString()
);
Files.move(
Paths.get(new Dataized(rho.take(Attr.RHO).take("path")).asString()),
target
);
return new Data.ToPhi(target.toString());
}
}

View File

@ -0,0 +1,75 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* @checkstyle PackageNameCheck (4 lines)
*/
package EOorg.EOeolang.EOfs;
import java.nio.file.Paths;
import org.eolang.AtVoid;
import org.eolang.Atom;
import org.eolang.Attr;
import org.eolang.Data;
import org.eolang.Dataized;
import org.eolang.PhDefault;
import org.eolang.Phi;
import org.eolang.XmirObject;
/**
* File.open.file-stream.read.read-bytes.
*
* @since 0.40
* @checkstyle TypeNameCheck (100 lines)
*/
@XmirObject(oname = "file.open.file-stream.read.read-bytes")
public final class EOfile$EOopen$EOfile_stream$EOread$EOread_bytes
extends PhDefault
implements Atom {
/**
* Ctor.
*/
public EOfile$EOopen$EOfile_stream$EOread$EOread_bytes() {
this.add("size", new AtVoid("size"));
}
@Override
public Phi lambda() throws Exception {
return new Data.ToPhi(
Files.INSTANCE.read(
Paths.get(
new Dataized(
this.take(Attr.RHO)
.take(Attr.RHO)
.take(Attr.RHO)
.take(Attr.RHO)
.take("path")
).asString()
).toString(),
new Dataized(this.take("size")).asNumber().intValue()
)
);
}
}

View File

@ -0,0 +1,74 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* @checkstyle PackageNameCheck (4 lines)
*/
package EOorg.EOeolang.EOfs;
import java.nio.file.Paths;
import org.eolang.AtVoid;
import org.eolang.Atom;
import org.eolang.Attr;
import org.eolang.Data;
import org.eolang.Dataized;
import org.eolang.PhDefault;
import org.eolang.Phi;
import org.eolang.XmirObject;
/**
* File.open.file-stream.write.written-bytes.
*
* @since 0.40
* @checkstyle TypeNameCheck (100 lines)
*/
@XmirObject(oname = "file.open.file-stream.write.written-bytes")
public final class EOfile$EOopen$EOfile_stream$EOwrite$EOwritten_bytes
extends PhDefault
implements Atom {
/**
* Ctor.
*/
public EOfile$EOopen$EOfile_stream$EOwrite$EOwritten_bytes() {
this.add("buffer", new AtVoid("buffer"));
}
@Override
public Phi lambda() throws Exception {
Files.INSTANCE.write(
Paths.get(
new Dataized(
this.take(Attr.RHO)
.take(Attr.RHO)
.take(Attr.RHO)
.take(Attr.RHO)
.take("path")
).asString()
).toString(),
new Dataized(this.take("buffer")).take()
);
return new Data.ToPhi(true);
}
}

View File

@ -0,0 +1,63 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* @checkstyle PackageNameCheck (4 lines)
*/
package EOorg.EOeolang.EOfs;
import java.nio.file.Paths;
import org.eolang.Atom;
import org.eolang.Attr;
import org.eolang.Data;
import org.eolang.Dataized;
import org.eolang.PhDefault;
import org.eolang.Phi;
import org.eolang.XmirObject;
/**
* File.open.process-file.
*
* @since 0.40
* @checkstyle TypeNameCheck (100 lines)
*/
@XmirObject(oname = "file.open.process-file")
public final class EOfile$EOopen$EOprocess_file extends PhDefault implements Atom {
@Override
public Phi lambda() throws Exception {
final Phi open = this.take(Attr.RHO);
final String name = Paths.get(
new Dataized(open.take(Attr.RHO).take("path")).asString()
).toString();
Files.INSTANCE.open(name);
try {
final Phi scope = open.take("scope").copy();
scope.put(0, open.take("file-stream"));
new Dataized(scope).take();
} finally {
Files.INSTANCE.close(name);
}
return new Data.ToPhi(true);
}
}

View File

@ -0,0 +1,58 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* @checkstyle PackageNameCheck (4 lines)
*/
package EOorg.EOeolang.EOfs;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import org.eolang.Atom;
import org.eolang.Attr;
import org.eolang.Data;
import org.eolang.Dataized;
import org.eolang.PhDefault;
import org.eolang.Phi;
import org.eolang.XmirObject;
/**
* File.resolved.resolve.
*
* @since 0.40
* @checkstyle TypeNameCheck (100 lines)
*/
@XmirObject(oname = "file.resolved.resolve")
public final class EOfile$EOresolved$EOresolve extends PhDefault implements Atom {
@Override
public Phi lambda() throws Exception {
final Phi rho = this.take(Attr.RHO);
return new Data.ToPhi(
Paths.get(new Dataized(rho.take(Attr.RHO).take("path")).asString())
.resolve(new Dataized(rho.take("other")).asString())
.toString()
);
}
}

View File

@ -0,0 +1,55 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* @checkstyle PackageNameCheck (4 lines)
*/
package EOorg.EOeolang.EOfs;
import java.io.File;
import org.eolang.Atom;
import org.eolang.Attr;
import org.eolang.Data;
import org.eolang.Dataized;
import org.eolang.PhDefault;
import org.eolang.Phi;
import org.eolang.XmirObject;
/**
* File.size.
*
* @since 0.40
* @checkstyle TypeNameCheck (100 lines)
*/
@XmirObject(oname = "file.size")
public final class EOfile$EOsize extends PhDefault implements Atom {
@Override
public Phi lambda() throws Exception {
return new Data.ToPhi(
new File(
new Dataized(this.take(Attr.RHO).take("path")).asString()
).length()
);
}
}

View File

@ -0,0 +1,55 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* @checkstyle PackageNameCheck (4 lines)
*/
package EOorg.EOeolang.EOfs;
import java.nio.file.Paths;
import org.eolang.Atom;
import org.eolang.Attr;
import org.eolang.Data;
import org.eolang.Dataized;
import org.eolang.PhDefault;
import org.eolang.Phi;
import org.eolang.XmirObject;
/**
* File.touched.touch.
*
* @since 0.40
* @checkstyle TypeNameCheck (100 lines)
*/
@XmirObject(oname = "file.touched.touch")
public final class EOfile$EOtouched$EOtouch extends PhDefault implements Atom {
@Override
public Phi lambda() throws Exception {
return new Data.ToPhi(
Paths.get(
new Dataized(this.take(Attr.RHO).take(Attr.RHO).take("path")).asString()
).toFile().createNewFile()
);
}
}

View File

@ -0,0 +1,142 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* @checkstyle PackageNameCheck (4 lines)
*/
package EOorg.EOeolang.EOfs;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.concurrent.ConcurrentHashMap;
import org.eolang.ExFailure;
import org.eolang.Versionized;
/**
* File streams.
* @since 0.40
*/
@Versionized
final class Files {
/**
* Files instance.
*/
static final Files INSTANCE = new Files();
/**
* File input streams for reading.
*/
private final ConcurrentHashMap<String, Object[]> streams = new ConcurrentHashMap<>(0);
/**
* Ctor.
*/
private Files() {
// singleton :(
}
/**
* Open file for reading and writing.
* @param name Name of the file
* @throws FileNotFoundException If can't open file
*/
void open(final String name) throws FileNotFoundException {
this.streams.putIfAbsent(
name,
new Object[] {
new FileInputStream(name),
new FileOutputStream(name, true),
}
);
}
/**
* Read given amount of bytes from file.
* @param name Name of file
* @param size Amount of bytes to read
* @return Read bytes
* @throws IOException If fails to read
*/
byte[] read(final String name, final int size) throws IOException {
synchronized (this.streams) {
if (!this.streams.containsKey(name)) {
throw new ExFailure(
"File input stream with name %s is absent, can't read",
name
);
}
final byte[] read = new byte[size];
int character;
int processed = 0;
final InputStream input = (InputStream) this.streams.get(name)[0];
while (processed < size && (character = input.read()) != -1) {
read[processed] = (byte) character;
++processed;
}
return Arrays.copyOf(read, processed);
}
}
/**
* Write given byte buffer to file.
* @param name Name of the file
* @param buffer Byte buffer to write
* @throws IOException If fails to write
*/
void write(final String name, final byte[] buffer) throws IOException {
synchronized (this.streams) {
if (!this.streams.containsKey(name)) {
throw new ExFailure(
"File output stream with name %s is absent, can't read",
name
);
}
((OutputStream) this.streams.get(name)[1]).write(buffer);
}
}
/**
* Close files streams.
* @param name File name
* @throws IOException If fails to close the streams
*/
void close(final String name) throws IOException {
synchronized (this.streams) {
if (!this.streams.containsKey(name)) {
throw new ExFailure(
"File streams with name %s is absent, can't close",
name
);
}
((InputStream) this.streams.get(name)[0]).close();
((OutputStream) this.streams.get(name)[1]).close();
this.streams.remove(name);
}
}
}

View File

@ -0,0 +1,31 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/**
* EO runtime, FS.
*
* @since 0.40
* @checkstyle PackageNameCheck (4 lines)
*/
package EOorg.EOeolang.EOfs;

View File

@ -0,0 +1,65 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* @checkstyle PackageNameCheck (4 lines)
*/
package EOorg.EOeolang.EOsys;
import org.eolang.AtVoid;
import org.eolang.Atom;
import org.eolang.Data;
import org.eolang.Dataized;
import org.eolang.PhDefault;
import org.eolang.Phi;
import org.eolang.XmirObject;
/**
* Getenv.
* @since 0.40
* @checkstyle TypeNameCheck (5 lines)
*/
@XmirObject(oname = "getenv")
public final class EOgetenv extends PhDefault implements Atom {
/**
* Ctor.
*/
public EOgetenv() {
this.add("name", new AtVoid("name"));
}
@Override
public Phi lambda() throws Exception {
final String env = System.getenv(
new Dataized(this.take("name")).asString()
);
final Phi var;
if (env != null) {
var = new Data.ToPhi(env);
} else {
var = new Data.ToPhi("");
}
return var;
}
}

View File

@ -34,12 +34,12 @@ import org.eolang.Phi;
import org.eolang.XmirObject;
/**
* Uname.@.
* @since 0.39.0
* Os.name.
* @since 0.40
* @checkstyle TypeNameCheck (5 lines)
*/
@XmirObject(oname = "uname.@")
public final class EOuname$EOφ extends PhDefault implements Atom {
@XmirObject(oname = "os.name")
public final class EOos$EOname extends PhDefault implements Atom {
/**
* Operating system name as {@link Phi}.
*/
@ -47,6 +47,6 @@ public final class EOuname$EOφ extends PhDefault implements Atom {
@Override
public Phi lambda() throws Exception {
return EOuname$EOφ.OS_NAME;
return EOos$EOname.OS_NAME;
}
}

View File

@ -173,9 +173,7 @@ public interface Data {
bytes = new BytesOf(((Number) obj).doubleValue()).take();
} else if (obj instanceof String) {
phi = eolang.take("string").copy();
bytes = Data.ToPhi.unescapeJavaString(
(String) obj
).getBytes(StandardCharsets.UTF_8);
bytes = ((String) obj).getBytes(StandardCharsets.UTF_8);
} else {
throw new IllegalArgumentException(
String.format(
@ -190,112 +188,5 @@ public interface Data {
}
return phi;
}
/**
* Unescapes a string that contains standard Java escape sequences.
* <ul>
* <li><strong>&#92;b &#92;f &#92;n &#92;r &#92;t &#92;" &#92;'</strong> :
* BS, FF, NL, CR, TAB, double and single quote.</li>
* <li><strong>&#92;X &#92;XX &#92;XXX</strong> : Octal character
* specification (0 - 377, 0x00 - 0xFF).</li>
* <li><strong>&#92;uXXXX</strong> : Hexadecimal based Unicode character.</li>
* </ul>
* @param str A string optionally containing standard java escape sequences.
* @return The translated string
* @todo #3160:90min This method should be refactored because it has high cognitive
* complexity and other problems. All {@code @checkstyle} warnings suppression and
* {@code SuppressWarnings("PMD.WarningName")} annotations for this method should be
* removed as a result of refactoring.
* @checkstyle CyclomaticComplexityCheck (100 lines)
* @checkstyle JavaNCSSCheck (100 lines)
* @checkstyle NestedIfDepthCheck (100 lines)
* @checkstyle ModifiedControlVariableCheck (100 lines)
*/
@SuppressWarnings({
"PMD.AvoidReassigningLoopVariables",
"PMD.CognitiveComplexity",
"PMD.NPathComplexity"
})
private static String unescapeJavaString(final String str) {
final StringBuilder unescaped = new StringBuilder(str.length());
for (int idx = 0; idx < str.length(); ++idx) {
char chr = str.charAt(idx);
if (chr == '\\') {
final char next;
if (idx == str.length() - 1) {
next = '\\';
} else {
next = str.charAt(idx + 1);
}
if (next >= '0' && next <= '7') {
final StringBuilder code = new StringBuilder(String.valueOf(next));
++idx;
if (idx < str.length() - 1 && str.charAt(idx + 1) >= '0'
&& str.charAt(idx + 1) <= '7') {
code.append(str.charAt(idx + 1));
++idx;
if (idx < str.length() - 1 && str.charAt(idx + 1) >= '0'
&& str.charAt(idx + 1) <= '7') {
code.append(str.charAt(idx + 1));
++idx;
}
}
unescaped.append((char) Integer.parseInt(code.toString(), 8));
continue;
}
switch (next) {
case '\\':
break;
case 'b':
chr = '\b';
break;
case 'f':
chr = '\f';
break;
case 'n':
chr = '\n';
break;
case 'r':
chr = '\r';
break;
case 't':
chr = '\t';
break;
case '\"':
chr = '\"';
break;
case '\'':
chr = '\'';
break;
case 'u':
if (idx >= str.length() - 5) {
chr = 'u';
break;
}
unescaped.append(
Character.toChars(
Integer.parseInt(
String.join(
"",
String.valueOf(str.charAt(idx + 2)),
String.valueOf(str.charAt(idx + 3)),
String.valueOf(str.charAt(idx + 4)),
String.valueOf(str.charAt(idx + 5))
),
16
)
)
);
idx += 5;
continue;
default:
break;
}
++idx;
}
unescaped.append(chr);
}
return unescaped.toString();
}
}
}

View File

@ -0,0 +1,102 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 Objectionary.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
+alias org.eolang.fs.dir
+alias org.eolang.fs.tmpdir
+architect yegor256@gmail.com
+home https://github.com/objectionary/eo
+tests
+package org.eolang.fs
+version 0.0.0
# Test.
[] > bound-tmpfile-does-not-recreates-file
tmpdir.tmpfile > f
f.path.eq f.path > @
# test.
[] > makes-new-directory
made. > d
dir
tmpdir.tmpfile.deleted.resolved "foo-new"
and. > @
d.exists
d.is-directory
# Test.
[] > deletes-empty-directory
dir
tmpdir.tmpfile.deleted.resolved
"bar-empty"
.made
.deleted
.exists
.not > @
# Test.
[] > throws-on-opening-directory
tmpdir.open > @
"w"
true > [d]
# Test.
[] > deletes-directory-with-files-recursively
(dir tmpdir.tmpfile.deleted).made > d
d.tmpfile > first
d.tmpfile > second
and. > @
and.
and.
and.
first.exists
second.exists
d.deleted.exists.not
first.exists.not
second.exists.not
# Test.
[] > deletes-directory-with-file-and-dir
(dir tmpdir.tmpfile.deleted).made > d
(dir d.tmpfile.deleted).made > inner
d.tmpfile > f
and. > @
and.
and.
and.
and.
inner.is-directory
inner.exists
f.exists
d.deleted.exists.not
inner.exists.not
f.exists.not
# Test.
[] > walks-recursively
(dir tmpdir.tmpfile.deleted).made > d
seq > @
*
(dir (d.resolved "foo/bar")).made
(d.resolved "foo/bar/test.txt").touched
(dir (d.resolved "x/y/z")).made
(d.resolved "x/y/z/a.txt").touched
(d.walk "**/*.txt").length.eq 2

View File

@ -0,0 +1,365 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 Objectionary.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
+alias org.eolang.fs.dir
+alias org.eolang.fs.file
+alias org.eolang.fs.tmpdir
+alias org.eolang.txt.sprintf
+alias org.eolang.txt.text
+architect yegor256@gmail.com
+home https://github.com/objectionary/eo
+tests
+package org.eolang.fs
+version 0.0.0
# Test.
[] > check-if-current-directory-is-directory
(file ".").is-directory > @
# Test.
[] > check-if-absent-file-does-not-exist
(file "absent.txt").exists.not > @
# Test.
[] > returns-self-after-deleting
tmpdir.tmpfile > temp
temp.deleted.path.eq temp.path > @
# Test.
[] > returns-self-after-touching
tmpdir.tmpfile > temp
temp.deleted.touched.path.eq temp.path > @
# Test.
[] > checks-file-does-not-exist-after-deleting
tmpdir.tmpfile.deleted.exists.not > @
# Test.
[] > touches-a-file
tmpdir.tmpfile.deleted.touched.exists > @
# Test.
[] > measures-empty-file-after-touching
tmpdir.tmpfile.deleted.touched.size.eq 0 > @
# Test.
[] > does-not-fail-on-double-touching
tmpdir.tmpfile.deleted.touched.touched.exists > @
# Test.
[] > does-not-fail-on-double-deleting
tmpdir.tmpfile.deleted.deleted.exists.not > @
# Test.
[] > throws-an-error-on-touching-temp-file-in-absent-dir
(tmpdir.resolve "foo").tmpfile > @
# Test.
[] > resolves-and-touches
dir (tmpdir.resolved "foo/bar") > resolved
resolved.tmpfile > f
seq > @
*
resolved.deleted.made.path
and.
f.exists
contains.
text f.path
"bar"
# Test.
[] > moves-a-file
tmpdir.tmpfile > temp
sprintf > dest
"%s.dest"
* temp.path
and. > @
(temp.moved dest).exists
temp.exists.not
# Test.
[] > throws-on-opening-with-wrong-mode
tmpdir
.tmpfile
.open > @
"x"
f > [f]
# Test.
[] > throws-on-reading-from-not-existed-file
tmpdir
.tmpfile
.deleted
.open > @
"r"
f > [f]
# Test.
[] > throws-on-reading-or-writing-from-not-existed-file
tmpdir
.tmpfile
.deleted
.open > @
"r+"
f > [f]
# Test
[] > touches-absent-file-on-opening-for-writing
tmpdir
.tmpfile
.deleted
.open
"w"
true > [f]
.exists > @
# Test
[] > touches-absent-file-on-opening-for-appending
tmpdir
.tmpfile
.deleted
.open
"a"
true > [f]
.exists > @
# Test
[] > touches-absent-file-on-opening-for-writing-or-reading
tmpdir
.tmpfile
.deleted
.open
"w+"
true > [f]
.exists > @
# Test
[] > touches-absent-file-on-opening-for-reading-or-appending
tmpdir
.tmpfile
.deleted
.open
"a+"
true > [f]
.exists > @
# Test.
[] > writes-data-to-file
tmpdir
.tmpfile
.open
"w"
f.write "Hello, world" > [f]
.size
.eq 12 > @
# Test.
[] > appending-data-to-file
tmpdir
.tmpfile
.open
"w"
f.write "Hello, world" > [f]
.open
"a"
f.write "!" > [f]
.size
.eq 13 > @
# Test.
[] > truncates-file-opened-for-writing
tmpdir
.tmpfile
.open
"w"
f.write "Hello, world" > [f]
.open
"w"
true > [f]
.size
.eq 0 > @
# Test.
[] > truncates-file-opened-for-writing-or-reading
tmpdir
.tmpfile
.open
"w"
f.write "Hello, world" > [f]
.open
"w+"
true > [f]
.size
.eq 0 > @
# Test.
[] > does-not-truncate-file-opened-for-appending
tmpdir
.tmpfile
.open
"w"
f.write "Hello, world" > [f]
.open
"a"
true > [f]
.size
.eq 12 > @
# Test.
[] > does-not-truncate-file-opened-for-reading-or-appending
tmpdir
.tmpfile
.open
"w"
f.write "Hello, world" > [f]
.open
"a+"
true > [f]
.size
.eq 12 > @
# Test.
[] > does-not-truncate-file-opened-for-reading
tmpdir
.tmpfile
.open
"w"
f.write "Hello, world" > [f]
.open
"r"
true > [f]
.size
.eq 12 > @
# Test.
[] > throws-on-writing-with-wrong-mode
tmpdir
.tmpfile
.open > @
"r"
f.write "Hello" > [f]
# Test.
[] > reads-from-file
malloc
.of
12
[m]
tmpdir
.tmpfile
.open
"w"
f.write "Hello, world" > [f]
.open > @
"r"
[f] >>
m.put > @
f.read 12
.eq "Hello, world" > @
# Test.
[] > throws-on-reading-from-file-with-wrong-mode
tmpdir
.tmpfile
.open > @
"w"
f.read 12 > [f]
# Test.
[] > reads-from-file-from-different-instances
tmpdir.tmpfile > temp
temp.path > src
seq > @
*
temp
.open
"w"
f.write "Shrek is love" > [f]
malloc
.of
13
[m] >>
file
^.src
.open > @
"r"
[f] >>
^.m.put > @
f.read 13
.eq "Shrek is love"
# Test.
[] > writes-to-file-from-different-instances
tmpdir.tmpfile > temp
temp.path > src
seq > @
*
temp
.open
"w"
f.write "Shrek is love" > [f]
malloc
.of
14
[m] >>
file
^.src
.open > @
"a+"
[f] >>
seq > @
*
f.write "!"
^.m.put
f.read 14
.eq "Shrek is love!"
# Test.
[] > reads-from-file-sequentially
malloc
.of
5
[m]
tmpdir
.tmpfile
.open > @
"w+"
[f] >>
f.read 7 > i1
i1.read 5 > i2
seq > @
*
f.write "Hello, world"
^.m.put i2
.eq "world" > @
# Test.
[] > writes-to-file-sequentially
tmpdir
.tmpfile
.open
"a+"
[f]
f.write "Hello, world" > o1
o1.write "!" > @
.size
.eq 13 > @

View File

@ -0,0 +1,49 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 Objectionary.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
+alias org.eolang.fs.tmpdir
+alias org.eolang.io.stdout
+alias org.eolang.txt.sprintf
+architect yegor256@gmail.com
+home https://github.com/objectionary/eo
+tests
+package org.eolang.fs
+version 0.0.0
# Test.
[] > prints-tmpdir
stdout > @
sprintf
"Temp dir is %s\n"
* tmpdir
# Test.
tmpdir.exists > [] > global-temp-dir-exists
# Test.
tmpdir.is-directory > [] > global-temp-dir-is-directory
# Test.
tmpdir.path.eq tmpdir.path > [] > returns-the-same-tmpdir
# Test.
tmpdir.tmpfile.exists > [] > creates-tmpfile

View File

@ -134,6 +134,18 @@
^.func m > @
0
# Test.
[] > unescapes-slashes
eq. > @
"x\\b\\f\\u\\r\\t\\n\\'"
78-5C-62-5C-66-5C-75-5C-72-5C-74-5C-6E-5C-27
# Test.
[] > unescapes-symbols
eq. > @
"\b\f\n\r\t\u27E6"
08-0C-0A-0D-09-E2-9F-A6
# Test.
[] > compiles-correctly-with-long-duplicate-names
[] > long-object-name

View File

@ -20,7 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
+alias org.eolang.sys.uname
+alias org.eolang.sys.os
+architect yegor256@gmail.com
+home https://github.com/objectionary/eo
+tests
@ -31,6 +31,6 @@
[] > checks-os-family
or. > @
or.
uname.is-windows
uname.is-macos
uname.is-linux
os.is-windows
os.is-macos
os.is-linux

View File

@ -41,7 +41,7 @@ import org.junit.jupiter.api.Test;
* Test cases for {@link Cages}.
* @since 0.36.0
*/
class CagesTest {
final class CagesTest {
@Test
void initializesObjectForTheFirstTime() {
final Phi phi = new PhFake();

View File

@ -0,0 +1,61 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* @checkstyle PackageNameCheck (10 lines)
*/
package EOorg.EOeolang.EOfs;
import java.nio.file.Path;
import org.eolang.Data;
import org.eolang.Dataized;
import org.eolang.PhWith;
import org.eolang.Phi;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
/**
* Test case for {@link EOfile}.
* @since 0.40
*/
@SuppressWarnings("JTCOP.RuleAllTestsHaveProductionClass")
final class EOfileTest {
@Test
void resolvesPath(@TempDir final Path temp) {
final Phi resolved = new PhWith(
new EOfile(),
"path", new Data.ToPhi(temp.toAbsolutePath().toString())
).take("resolved").copy();
resolved.put(0, new Data.ToPhi("foo/bar/baz"));
MatcherAssert.assertThat(
"The `file.resolved` object should resolve in a right way",
new Dataized(resolved).asString(),
Matchers.equalTo(
temp.resolve("foo/bar/baz").toAbsolutePath().toString()
)
);
}
}

View File

@ -0,0 +1,131 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* @checkstyle PackageNameCheck (10 lines)
*/
package EOorg.EOeolang.EOfs;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.eolang.ExFailure;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
/**
* Test case for {@link Files}.
* @since 0.40
*/
final class FilesTest {
/**
* Files instance.
*/
private static final Files INSTANCE = Files.INSTANCE;
@Test
void throwsOnReadingWithoutOpening(@TempDir final Path dir) {
Assertions.assertThrows(
ExFailure.class,
() -> FilesTest.INSTANCE.read(
FilesTest.tempFile(dir), 10
),
"File should not allow to read before opening"
);
}
@Test
void throwsOnWritingWithoutOpening(@TempDir final Path dir) {
Assertions.assertThrows(
ExFailure.class,
() -> FilesTest.INSTANCE.write(
FilesTest.tempFile(dir), new byte[]{0x01}
),
"File should not allow to write before opening"
);
}
@Test
void throwsOnClosingWithoutOpening(@TempDir final Path dir) {
Assertions.assertThrows(
ExFailure.class,
() -> FilesTest.INSTANCE.close(
FilesTest.tempFile(dir)
),
"File should not allow to close before opening"
);
}
@Test
void readsFromFile(@TempDir final Path dir) throws IOException {
final String file = FilesTest.tempFile(dir);
final FileWriter writer = new FileWriter(
Paths.get(file).toFile()
);
writer.write("Hello, world");
writer.close();
FilesTest.INSTANCE.open(file);
MatcherAssert.assertThat(
"The string should have been read from file",
FilesTest.INSTANCE.read(file, 12),
Matchers.equalTo("Hello, world".getBytes(StandardCharsets.UTF_8))
);
FilesTest.INSTANCE.close(file);
}
@Test
void writesToFile(@TempDir final Path dir) throws IOException {
final String file = FilesTest.tempFile(dir);
final FileWriter writer = new FileWriter(
Paths.get(file).toFile()
);
writer.write("Hello, world");
writer.close();
FilesTest.INSTANCE.open(file);
FilesTest.INSTANCE.write(file, "!".getBytes(StandardCharsets.UTF_8));
MatcherAssert.assertThat(
"The string should have been read from file",
FilesTest.INSTANCE.read(file, 13),
Matchers.equalTo("Hello, world!".getBytes(StandardCharsets.UTF_8))
);
FilesTest.INSTANCE.close(file);
}
/**
* Creates temporary file in directory.
* @param dir Directory
* @return Absolute path to temp file
* @throws IOException If fails to create temp file
*/
private static String tempFile(final Path dir) throws IOException {
final Path file = java.nio.file.Files.createTempFile(dir, null, null);
file.toFile().deleteOnExit();
return file.toAbsolutePath().toString();
}
}

View File

@ -0,0 +1,34 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* @checkstyle PackageNameCheck (20 lines)
*/
/**
* EO-fs, tests.
*
* @since 0.40
*/
package EOorg.EOeolang.EOfs;

View File

@ -47,7 +47,7 @@ import org.junit.jupiter.api.Test;
* @since 0.1
*/
@SuppressWarnings("JTCOP.RuleAllTestsHaveProductionClass")
public final class EOmallocTest {
final class EOmallocTest {
@Test
void freesMemory() {
final Dummy dummy = new Dummy();

View File

@ -53,7 +53,7 @@ import org.junit.jupiter.params.provider.CsvSource;
* @checkstyle TypeNameCheck (4 lines)
*/
@SuppressWarnings("JTCOP.RuleAllTestsHaveProductionClass")
public final class EOnumberTest {
final class EOnumberTest {
@Test
void hasDifferentHashes() {

View File

@ -46,7 +46,7 @@ import org.junit.jupiter.api.Test;
*
* @since 0.19
*/
public final class EOtryTest {
final class EOtryTest {
@Test
public void catchesException() {

View File

@ -41,7 +41,7 @@ import org.junit.jupiter.api.Test;
*
* @since 0.19
*/
public final class HeapsTest {
final class HeapsTest {
/**
* Heaps.
*/

View File

@ -95,7 +95,7 @@ SOFTWARE.
<sonar.projectKey>com.objectionary:${project.name}</sonar.projectKey>
<sonar.organization>objectionary</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<antlr.version>4.13.1</antlr.version>
<antlr.version>4.13.2</antlr.version>
</properties>
<dependencyManagement>
<dependencies>