[macruby-changes] [4884] MacRuby/trunk/io.c

source_changes at macosforge.org source_changes at macosforge.org
Thu Nov 4 21:09:56 PDT 2010


Revision: 4884
          http://trac.macosforge.org/projects/ruby/changeset/4884
Author:   watson1978 at gmail.com
Date:     2010-11-04 21:09:54 -0700 (Thu, 04 Nov 2010)
Log Message:
-----------
fixed the bug of IO.readlines which does not push last element to Array.

Test Script:
{{{
require 'tempfile'
require 'test/unit/assertions.rb'
include Test::Unit::Assertions

t = Tempfile.new("foo")
t.puts "foo"
t.puts "bar"
t.puts "baz"
t.close

assert_equal(["foo\n", "bar\n", "baz\n"], IO.readlines(t.path))
assert_equal(["foo\nb", "ar\nb", "az\n"], IO.readlines(t.path, "b"))
assert_equal(["foo\nbar\nbaz\n"],         IO.readlines(t.path, ':'))
t = Tempfile.new("foo")
t.puts "foobar"
t.close

assert_equal(["foobar\n"],  IO.readlines(t.path))
t = Tempfile.new("foo")
t.close

assert_equal([], IO.readlines(t.path, "b"))

puts :ok
}}}

Modified Paths:
--------------
    MacRuby/trunk/io.c

Modified: MacRuby/trunk/io.c
===================================================================
--- MacRuby/trunk/io.c	2010-11-05 02:07:19 UTC (rev 4883)
+++ MacRuby/trunk/io.c	2010-11-05 04:09:54 UTC (rev 4884)
@@ -4038,6 +4038,9 @@
 	    rb_ary_push(ary, rb_str_new((char *)&bytes[pos], s));
 	    pos += s; 
 	}
+	if (pos < length) {
+	    rb_ary_push(ary, rb_str_new((char *)&bytes[pos], length - pos));
+	}
     }
     else {
 	// TODO
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101104/fc1f71ec/attachment.html>


More information about the macruby-changes mailing list