From 632378a9b8447bb2b7d35600ef2f6813acd4ab11 Mon Sep 17 00:00:00 2001 From: Herwin Date: Sun, 3 Aug 2025 20:06:54 +0200 Subject: [PATCH] Add "reads after ungetc with multibyte characters in the buffer" spec to StringIO#readpartial This one was missing in #1278, I got it to work with the `encoding: binary` directive. The StringIO code was fine, the spec was just incomplete. --- library/stringio/readpartial_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/library/stringio/readpartial_spec.rb b/library/stringio/readpartial_spec.rb index 988c55223..645f983d8 100644 --- a/library/stringio/readpartial_spec.rb +++ b/library/stringio/readpartial_spec.rb @@ -1,3 +1,4 @@ +# encoding: binary require_relative '../../spec_helper' require_relative 'fixtures/classes' @@ -24,6 +25,14 @@ @string.readpartial(3).should == ", l" end + it "reads after ungetc with multibyte characters in the buffer" do + @string = StringIO.new(+"∂φ/∂x = gaîté") + c = @string.getc + @string.ungetc(c) + @string.readpartial(3).should == "\xE2\x88\x82" + @string.readpartial(3).should == "\xCF\x86/" + end + it "reads after ungetc without data in the buffer" do @string = StringIO.new @string.write("f").should == 1