Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
2229a2aa
Commit
2229a2aa
authored
Sep 30, 2016
by
Tomoyuki Sahara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reimplement #eof. fixes #66.
parent
51cf6b60
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
26 deletions
+26
-26
mrblib/io.rb
mrblib/io.rb
+6
-21
test/io.rb
test/io.rb
+20
-5
No files found.
mrblib/io.rb
View file @
2229a2aa
...
@@ -133,20 +133,12 @@ class IO
...
@@ -133,20 +133,12 @@ class IO
end
end
def
eof?
def
eof?
return
true
if
@buf
&&
@buf
.
size
>
0
ret
=
false
char
=
''
begin
begin
char
=
sysread
(
1
)
buf
=
_read_buf
rescue
EOFError
=>
e
return
buf
.
size
==
0
ret
=
true
rescue
EOFError
ensure
return
true
_ungets
(
char
)
end
end
ret
end
end
alias_method
:eof
,
:eof?
alias_method
:eof
,
:eof?
...
@@ -176,24 +168,17 @@ class IO
...
@@ -176,24 +168,17 @@ class IO
@buf
=
sysread
(
BUF_SIZE
)
@buf
=
sysread
(
BUF_SIZE
)
end
end
def
_ungets
(
substr
)
def
ungetc
(
substr
)
raise
TypeError
.
new
"expect String, got
#{
substr
.
class
}
"
unless
substr
.
is_a?
(
String
)
raise
TypeError
.
new
"expect String, got
#{
substr
.
class
}
"
unless
substr
.
is_a?
(
String
)
raise
IOError
if
@pos
==
0
||
@pos
.
nil?
@pos
-=
substr
.
size
@pos
-=
substr
.
size
if
@buf
.
empty?
if
@buf
.
empty?
@buf
=
substr
@buf
=
substr
.
dup
else
else
@buf
=
substr
+
@buf
@buf
=
substr
+
@buf
end
end
nil
nil
end
end
def
ungetc
(
char
)
raise
IOError
if
@pos
==
0
||
@pos
.
nil?
_ungets
(
char
)
nil
end
def
read
(
length
=
nil
)
def
read
(
length
=
nil
)
unless
length
.
nil?
unless
length
.
nil?
unless
length
.
is_a?
Fixnum
unless
length
.
is_a?
Fixnum
...
...
test/io.rb
View file @
2229a2aa
...
@@ -70,14 +70,29 @@ end
...
@@ -70,14 +70,29 @@ end
#assert('IO#each_line', '15.2.20.5.5') do
#assert('IO#each_line', '15.2.20.5.5') do
assert
(
'IO#eof?'
,
'15.2.20.5.6'
)
do
assert
(
'IO#eof?'
,
'15.2.20.5.6'
)
do
if
false
# XXX: not implemented yet
io
=
IO
.
new
(
IO
.
sysopen
(
$mrbtest_io_wfname
,
'w'
),
'w'
)
assert_raise
(
IOError
)
do
io
.
eof?
end
end
# empty file
io
=
IO
.
open
(
IO
.
sysopen
(
$mrbtest_io_wfname
,
'w'
),
'w'
)
io
.
close
io
=
IO
.
open
(
IO
.
sysopen
(
$mrbtest_io_wfname
,
'r'
),
'r'
)
assert_true
io
.
eof?
io
.
close
# nonempty file
io
=
IO
.
new
(
IO
.
sysopen
(
$mrbtest_io_rfname
))
io
=
IO
.
new
(
IO
.
sysopen
(
$mrbtest_io_rfname
))
$mrbtest_io_msg
.
each_char
{
|
ch
|
assert_false
io
.
eof?
# XXX
io
.
readchar
#assert_false io.eof?
assert_false
io
.
eof?
io
.
getc
io
.
read
}
assert_true
io
.
eof?
assert_true
io
.
eof?
io
.
close
io
.
close
true
true
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment