forked from myst-lang/myst
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[stdlib,spec] Add basic specs for
File
, temporary workaround for `I…
…O#gets` issue. The explicit return in `IO#gets` caused issues with the value of `self` (see myst-lang#155), so `raise/rescue` is used as a temporary workaround. Also, the specs for File are a bit light, because there currently isn't a great way of mocking FileDescriptor input, nor accessing the Interpreter's `fd_pool` to check for opening/closing of files.
- Loading branch information
1 parent
d2b83bc
commit fb447f8
Showing
6 changed files
with
49 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require "stdlib/spec.mt" | ||
|
||
|
||
describe("File#open") do | ||
it("returns a new File instance for the given file") do | ||
file = File.open("spec/support/misc/fixed_size_file.txt", "r") | ||
|
||
assert(file.type.to_s == "File") | ||
end | ||
|
||
it("defaults to 'read' mode if no mode is given") do | ||
file = File.open("spec/support/misc/fixed_size_file.txt") | ||
assert(file.mode == "r") | ||
end | ||
end | ||
|
||
describe("File#close") do | ||
# TODO: test that the file descriptor is properly closed. | ||
end | ||
|
||
describe("File#size") do | ||
it("returns an Integer of the number of bytes the file contains") do | ||
# `fixed_size_file.txt` should always be 63 bytes in size. | ||
file = %File{"spec/support/misc/fixed_size_file.txt", "r"} | ||
|
||
assert(file.size == 63) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This file has a fixed size of 63 bytes. Do not edit this file! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,6 @@ deftype File | |
defstatic open(name : String, mode) | ||
%File{name, mode} | ||
end | ||
|
||
def mode; @mode; end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters