Project

General

Profile

Bug #13675 ยป io-ungetc-nil-13675.patch

jeremyevans0 (Jeremy Evans), 08/25/2019 06:28 PM

View differences:

io.c
4314 4314

  
4315 4315
    GetOpenFile(io, fptr);
4316 4316
    rb_io_check_char_readable(fptr);
4317
    if (NIL_P(c)) return Qnil;
4318 4317
    if (FIXNUM_P(c)) {
4319 4318
	c = rb_enc_uint_chr(FIX2UINT(c), io_read_encoding(fptr));
4320 4319
    }
spec/ruby/core/io/ungetc_spec.rb
103 103
    -> { @io.sysread(1) }.should raise_error(IOError)
104 104
  end
105 105

  
106
  it "does not affect the stream and returns nil when passed nil" do
107
    @io.getc.should == ?V
108
    @io.ungetc(nil)
109
    @io.getc.should == ?o
106
  ruby_version_is "0"..."2.7" do
107
    it "does not affect the stream and returns nil when passed nil" do
108
      @io.getc.should == ?V
109
      @io.ungetc(nil)
110
      @io.getc.should == ?o
111
    end
112
  end
113

  
114
  ruby_version_is "2.7" do
115
    it "raises TypeError if passed nil" do
116
      @io.getc.should == ?V
117
      proc{@io.ungetc(nil)}.should raise_error(TypeError)
118
    end
110 119
  end
111 120

  
112 121
  it "puts one or more characters back in the stream" do
113
-