[macruby-changes] [2156] MacRuby/branches/experimental/spec/frozen/library/stringio

source_changes at macosforge.org source_changes at macosforge.org
Mon Aug 3 01:51:21 PDT 2009


Revision: 2156
          http://trac.macosforge.org/projects/ruby/changeset/2156
Author:   mattaimonetti at gmail.com
Date:     2009-08-03 01:51:19 -0700 (Mon, 03 Aug 2009)
Log Message:
-----------
finally made all the stringio specs run on ruby 1.8 and 1.9

Modified Paths:
--------------
    MacRuby/branches/experimental/spec/frozen/library/stringio/getbyte_spec.rb
    MacRuby/branches/experimental/spec/frozen/library/stringio/print_spec.rb
    MacRuby/branches/experimental/spec/frozen/library/stringio/putc_spec.rb
    MacRuby/branches/experimental/spec/frozen/library/stringio/readbyte_spec.rb
    MacRuby/branches/experimental/spec/frozen/library/stringio/shared/getc.rb
    MacRuby/branches/experimental/spec/frozen/library/stringio/shared/readchar.rb
    MacRuby/branches/experimental/spec/frozen/library/stringio/ungetc_spec.rb

Added Paths:
-----------
    MacRuby/branches/experimental/spec/frozen/library/stringio/shared/getbyte.rb
    MacRuby/branches/experimental/spec/frozen/library/stringio/shared/readbyte.rb

Modified: MacRuby/branches/experimental/spec/frozen/library/stringio/getbyte_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/stringio/getbyte_spec.rb	2009-08-03 04:21:42 UTC (rev 2155)
+++ MacRuby/branches/experimental/spec/frozen/library/stringio/getbyte_spec.rb	2009-08-03 08:51:19 UTC (rev 2156)
@@ -1,13 +1,14 @@
 require File.dirname(__FILE__) + '/../../spec_helper'
 require 'stringio'
-require File.dirname(__FILE__) + '/shared/getc'
+require File.dirname(__FILE__) + '/shared/getbyte'
 
+
 ruby_version_is "1.8.7" do
   describe "StringIO#getbyte" do
-    it_behaves_like :stringio_getc, :getbyte
+    it_behaves_like :stringio_getbyte, :getbyte
   end
 
   describe "StringIO#getbyte when self is not readable" do
-    it_behaves_like :stringio_getc_not_readable, :getbyte
+    it_behaves_like :stringio_getbyte_not_readable, :getbyte
   end
 end

Modified: MacRuby/branches/experimental/spec/frozen/library/stringio/print_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/stringio/print_spec.rb	2009-08-03 04:21:42 UTC (rev 2155)
+++ MacRuby/branches/experimental/spec/frozen/library/stringio/print_spec.rb	2009-08-03 08:51:19 UTC (rev 2156)
@@ -5,15 +5,29 @@
   before(:each) do
     @io = StringIO.new('example')
   end
+  
+  ruby_version_is "" ... "1.9" do  
+    it "prints $_ when passed no arguments and stringify nil if $_ is nil" do
+      $_ = nil
+      @io.print
+      @io.string.should == "nilmple"
 
-  it "prints $_ when passed no arguments" do
-    $_ = nil
-    @io.print
-    @io.string.should == "nilmple"
+      $_ = "blah"
+      @io.print
+      @io.string.should == "nilblah"
+    end  
+  end 
+  
+  ruby_version_is "1.9" do  
+    it "prints $_ when passed no arguments and return self if $_ is nil" do
+      $_ = nil
+      @io.print
+      @io.string.should == "example"
 
-    $_ = "blah"
-    @io.print
-    @io.string.should == "nilblah"
+      $_ = "blah"
+      @io.print
+      @io.string.should == "blahple"
+    end  
   end
 
   it "prints the passed arguments to self" do

Modified: MacRuby/branches/experimental/spec/frozen/library/stringio/putc_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/stringio/putc_spec.rb	2009-08-03 04:21:42 UTC (rev 2155)
+++ MacRuby/branches/experimental/spec/frozen/library/stringio/putc_spec.rb	2009-08-03 08:51:19 UTC (rev 2156)
@@ -55,12 +55,23 @@
     @io.putc(?A)
     @io.string.should == "example\000\000\000A"
   end
-
-  it "tries to convert the passed argument to an Integer using #to_int" do
-    obj = mock('to_int')
-    obj.should_receive(:to_int).and_return(?t)
-    @io.putc(obj)
-    @io.string.should == "txample"
+  
+  ruby_version_is "" ... "1.9" do
+    it "tries to convert the passed argument to an Integer using #to_int" do
+      obj = mock('to_int')
+      obj.should_receive(:to_int).and_return(?t)
+      @io.putc(obj)
+      @io.string.should == "txample"
+    end
+  end 
+  
+  ruby_version_is "1.9" do
+    it "tries to convert the passed argument to an Integer using #to_int" do
+      obj = mock('to_int')
+      obj.should_receive(:to_int).and_return(90)
+      @io.putc(obj)
+      @io.string.should == "Zxample"
+    end
   end
 
   it "raises a TypeError when the passed argument can't be coerced to Integer" do

Modified: MacRuby/branches/experimental/spec/frozen/library/stringio/readbyte_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/stringio/readbyte_spec.rb	2009-08-03 04:21:42 UTC (rev 2155)
+++ MacRuby/branches/experimental/spec/frozen/library/stringio/readbyte_spec.rb	2009-08-03 08:51:19 UTC (rev 2156)
@@ -1,13 +1,15 @@
 require File.dirname(__FILE__) + '/../../spec_helper'
 require 'stringio'
-require File.dirname(__FILE__) + "/shared/readchar"
+require File.dirname(__FILE__) + "/shared/readbyte"
 
+
 ruby_version_is "1.8.7" do
+  
   describe "StringIO#readbyte" do
-    it_behaves_like :stringio_readchar, :readbyte
+    it_behaves_like :stringio_readbyte, :readbyte
   end
 
   describe "StringIO#readbyte when self is not readable" do
-    it_behaves_like :stringio_readchar_not_readable, :readbyte
+    it_behaves_like :stringio_readbyte_not_readable, :readbyte
   end
 end
\ No newline at end of file

Added: MacRuby/branches/experimental/spec/frozen/library/stringio/shared/getbyte.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/stringio/shared/getbyte.rb	                        (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/library/stringio/shared/getbyte.rb	2009-08-03 08:51:19 UTC (rev 2156)
@@ -0,0 +1,58 @@
+describe :stringio_getbyte, :shared => true do
+  before(:each) do
+    @io = StringIO.new("example")
+  end
+
+  it "increases self's position by one" do
+    @io.send(@method)
+    @io.pos.should eql(1)
+
+    @io.send(@method)
+    @io.pos.should eql(2)
+
+    @io.send(@method)
+    @io.pos.should eql(3)
+  end
+  
+  ruby_version_is "" ... "1.9" do    
+    it "returns the 8-bit byte at the current position" do
+      @io.send(@method).should == ?e
+      @io.send(@method).should == ?x
+      @io.send(@method).should == ?a
+    end
+  end
+  ruby_version_is "1.9" do  
+    it "returns the 8-bit byte at the current position" do
+      @io.send(@method).should == 101
+      @io.send(@method).should == 120
+      @io.send(@method).should == 97
+    end
+  end 
+
+  it "returns nil when called at the end of self" do
+    @io.pos = 7
+    @io.send(@method).should be_nil
+    @io.send(@method).should be_nil
+    @io.send(@method).should be_nil
+  end
+
+  it "does not increase self's position when called at the end of file" do
+    @io.pos = 7
+    @io.send(@method)
+    @io.pos.should eql(7)
+
+    @io.send(@method)
+    @io.pos.should eql(7)
+  end
+end
+
+describe :stringio_getbyte_not_readable, :shared => true do
+  it "raises an IOError" do
+    io = StringIO.new("xyz", "w")
+    lambda { io.send(@method) }.should raise_error(IOError)
+
+    io = StringIO.new("xyz")
+    io.close_read
+    lambda { io.send(@method) }.should raise_error(IOError)
+  end
+end

Modified: MacRuby/branches/experimental/spec/frozen/library/stringio/shared/getc.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/stringio/shared/getc.rb	2009-08-03 04:21:42 UTC (rev 2155)
+++ MacRuby/branches/experimental/spec/frozen/library/stringio/shared/getc.rb	2009-08-03 08:51:19 UTC (rev 2156)
@@ -13,12 +13,12 @@
     @io.send(@method)
     @io.pos.should eql(3)
   end
-
+  
   it "returns the 8-bit byte at the current position" do
     @io.send(@method).should == ?e
     @io.send(@method).should == ?x
     @io.send(@method).should == ?a
-  end
+  end   
 
   it "returns nil when called at the end of self" do
     @io.pos = 7

Added: MacRuby/branches/experimental/spec/frozen/library/stringio/shared/readbyte.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/stringio/shared/readbyte.rb	                        (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/library/stringio/shared/readbyte.rb	2009-08-03 08:51:19 UTC (rev 2156)
@@ -0,0 +1,48 @@
+describe :stringio_readbyte, :shared => true do
+  before(:each) do
+    @io = StringIO.new("example")
+  end
+  
+  ruby_version_is "" ... "1.9" do
+    it "reads the next 8-bit byte from self's current position" do
+      @io.send(@method).should == ?e
+
+      @io.pos = 4
+      @io.send(@method).should == ?p
+    end
+  end
+  
+  ruby_version_is "1.9" do
+    it "reads the next character from self's current position" do      
+      @io.send(@method).should == 101
+
+      @io.pos = 4
+      @io.send(@method).should == 112
+    end
+    
+    it "correctly updates the current position" do
+      @io.send(@method)
+      @io.pos.should == 1
+
+      @io.send(@method)
+      @io.pos.should == 2
+    end
+
+    it "raises an EOFError when self is at the end" do
+      @io.pos = 7
+      lambda { @io.send(@method) }.should raise_error(EOFError)
+    end
+    
+  end 
+end  
+
+describe :stringio_readbyte_not_readable, :shared => true do
+  it "raises an IOError" do
+    io = StringIO.new("a b c d e", "w")
+    lambda { io.send(@method) }.should raise_error(IOError)
+
+    io = StringIO.new("a b c d e")
+    io.close_read
+    lambda { io.send(@method) }.should raise_error(IOError)
+  end
+end

Modified: MacRuby/branches/experimental/spec/frozen/library/stringio/shared/readchar.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/stringio/shared/readchar.rb	2009-08-03 04:21:42 UTC (rev 2155)
+++ MacRuby/branches/experimental/spec/frozen/library/stringio/shared/readchar.rb	2009-08-03 08:51:19 UTC (rev 2156)
@@ -2,13 +2,13 @@
   before(:each) do
     @io = StringIO.new("example")
   end
-
+  
   it "reads the next 8-bit byte from self's current position" do
     @io.send(@method).should == ?e
 
     @io.pos = 4
     @io.send(@method).should == ?p
-  end
+  end 
 
   it "correctly updates the current position" do
     @io.send(@method)

Modified: MacRuby/branches/experimental/spec/frozen/library/stringio/ungetc_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/library/stringio/ungetc_spec.rb	2009-08-03 04:21:42 UTC (rev 2155)
+++ MacRuby/branches/experimental/spec/frozen/library/stringio/ungetc_spec.rb	2009-08-03 08:51:19 UTC (rev 2156)
@@ -22,27 +22,42 @@
     @io.ungetc(?A)
     @io.pos.should eql(1)
   end
+  
+  ruby_version_is "" ... "1.9" do
+    it "pads with \\000 when the current position is after the end" do
+      @io.pos = 15
+      @io.ungetc(?A)
+      @io.string.should == "1234\000\000\000\000\000\000\000\000\000\000A"
+    end
+  end 
 
-  it "pads with \\000 when the current position is after the end" do
-    @io.pos = 15
-    @io.ungetc(?A)
-    @io.string.should == "1234\000\000\000\000\000\000\000\000\000\000A"
-  end
-
   ruby_version_is "1.8.6" .. "1.8.6.367" do
     it "does nothing when at the beginning of self" do
       @io.ungetc(65)
       @io.string.should == '1234'
     end
   end
+  
+  ruby_version_is "" ... "1.9" do
+    it "tries to convert the passed length to an Integer using #to_int" do
+      obj = mock("to_int")
+      obj.should_receive(:to_int).and_return(?A)
 
-  it "tries to convert the passed length to an Integer using #to_int" do
-    obj = mock("to_int")
-    obj.should_receive(:to_int).and_return(?A)
+      @io.pos = 1
+      @io.ungetc(obj)
+      @io.string.should == "A234"
+    end 
+  end
+  
+  ruby_version_is "1.9" do
+    it "tries to convert the passed argument to a String using #to_str if the argument isn't an Integer" do
+      obj = mock("to_str")
+      obj.should_receive(:to_str).and_return(?A) 
 
-    @io.pos = 1
-    @io.ungetc(obj)
-    @io.string.should == "A234"
+      @io.pos = 1
+      @io.ungetc(obj)
+      @io.string.should == "A234"
+    end
   end
   
   ruby_version_is "" ... "1.9" do
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090803/1236c50c/attachment-0001.html>


More information about the macruby-changes mailing list