Repository navigation
io: StringIO/IO reader & writer conformance to MRI 4.0.6 - #536
Merged
Merged
Conversation
StringIO.new now honours its mode argument (r/r+/w/w+/a/a+, integer flags,
and mode:) — read-only rejects writes, write-only rejects reads, "w"/"w+"
truncate, "a"/"a+" append every write at end-of-buffer, and a frozen backing
string opens read-only. File.open enforces the same access half.
gets/readline/readlines/each_line coerce a non-String separator via #to_str
and a non-Integer limit via #to_int exactly once per call, default the
separator to $/, and treat a lone #to_int-only argument as the byte limit.
Paragraph mode ("") honours the limit and keeps the whole newline run for
StringIO but only two for a real IO/File, matching MRI's divergence.
read(length) coerces via #to_int, returns an ASCII-8BIT String, and accepts a
#to_str-convertible output buffer. write/<< stringify via #to_s. print writes
$_ with no args and honours $, / $\. puts expands a #to_ary object. #each is
a true alias of #each_line (shared method entry).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ia #write each_line/each_char/each_byte with no block now return an Enumerator (whose #size is nil) instead of crashing, and defer the readable check to iteration so the enumerator is buildable on a closed stream. #each is a real alias of #each_line on IO as well. Paragraph mode honours chomp: (stripping the terminating newline run but not a lone EOF "\n"). IO.readlines/foreach route their separator/limit/chomp/$/ through the same coercion path as the instance methods, so a #to_str separator, a #to_int (or Integer) limit, and the $/ default all work. Kernel#puts and IO#puts emit through the stream's #write method, so a stream that overrides #write (as the puts specs do) captures the output. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ches Fold the single-shot ioGets (ARGF#gets, IRB reader) onto the shared resolveGetsArgs/ioGetsResolved path and delete the now-duplicate parseGetsArgs and the dead checkGetsLimit, so there is one separator/limit/$/-aware parser. Extend io_residuals_test.go to exercise the new branches: StringIO/File modes, read coercions and binary encoding, gets/readlines/each_line separator+limit+$/, paragraph mode (StringIO whole-run vs File two-newline, chomp, leading blanks, EOF), the no-block Enumerator forms, puts via #write with array flattening and recursion, print's $_/$,/$\, IO.readlines/foreach, and File read/write gating. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add a StringIO.gets("") case over a buffer of only blank lines, which the
leading-blank skip consumes to end-of-input, exercising ioGetsParagraph's
end-of-buffer nil return.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add a File.open("/dev/null", "a") case: a non-regular file opens with an empty
buffer and its write reports the byte count, exercising openFileIO's append-mode
notRegular branch.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The character-device subcases open "/dev/null", which does not exist on Windows (its null device is NUL), failing test (windows-latest). Guard the two device cases behind runtime.GOOS != "windows"; the rest of the mode gating still runs on every platform. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tannevaled
added a commit
that referenced
this pull request
Sep 1, 2026
Locks in #535 (String methods: index/casecmp/chomp/gsub/scan/tr/... ~+110), #536 (IO/StringIO reader+writer), #538 (Array#[]= auto-grow + mutators), #539 (Range + Comparable), #540 (Struct + Data), #541 (Time). Measured 17983 passing on the pinned corpus, up from 17654. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Advances MRI-Ruby-4.0.6 conformance for the buffer-backed IO/StringIO reader and
writer paths. All work is in
internal/vm/io.go(plus small call-site edits inio_class.go,io_descriptors.go,argf.go,irb.go) and a newio_residuals_test.go.What changed
StringIO.newhonours its mode (r/r+/w/w+/a/a+,integer flags,
mode:): read-only rejects writes, write-only rejects reads,w/w+truncate,a/a+append every write at end-of-buffer, a frozen backingstring opens read-only.
File.openenforces the same access half.separator/limit parser: a non-String separator coerces via
#to_str, anon-Integer limit via
#to_int(each exactly once), the default separatorfollows
$/, and a lone#to_int-only argument is the byte limit. Paragraphmode (
"") honours the limit andchomp:, and keeps the whole newline run forStringIO but only two for a real IO/File — matching MRI's divergence.
read(length)coerces via#to_int, returns an ASCII-8BIT String, andaccepts a
#to_stroutput buffer;readwith no length stays UTF-8; nil-vs-""at EOF preserved.
<</ print / puts. write/<<stringify via#to_s; print writes$_with no args and honours$,/$\; puts expands a#to_aryobject and nowemits through the stream's
#write(so an overridden#writecaptures output).each_line/each_char/each_bytewith no block return anEnumerator (size nil) instead of crashing;
#eachis a true alias of#each_lineon both IO and StringIO.Conformance deltas (rubyspec, pass count)
StringIO: gets 24→30, readline 24→30, readlines 14→17, print 7→11, puts 15→19,
read 15→18, each_char/byte/line and append all green. Core IO: readlines 30→46,
puts 3→14, each_line 19→28, each_char 3→8, gets 26→32, print 2→5.
Verification
go test ./internal/vm/andgo test ./...green;GOOS=wasip1 GOARCH=wasm go build ./...OK; gofmt clean on changed files; merged coverage total 100.0%.
Out of scope (reported, not fixed): encoding transcoding on read/gets/write,
|commandsubprocess pipes, C off_t RangeError,newline:CRLF translation.🤖 Generated with Claude Code