summaryrefslogtreecommitdiff
path: root/spec/ruby/library/stringio/shared/codepoints.rb
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-20 20:18:52 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-20 20:18:52 +0000
commit1d15d5f08032acf1b7bceacbb450d617ff6e0931 (patch)
treea3785a79899302bc149e4a6e72f624ac27dc1f10 /spec/ruby/library/stringio/shared/codepoints.rb
parent75bfc6440d595bf339007f4fb280fd4d743e89c1 (diff)
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory. [Misc #13792] [ruby-core:82287] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/library/stringio/shared/codepoints.rb')
-rw-r--r--spec/ruby/library/stringio/shared/codepoints.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/spec/ruby/library/stringio/shared/codepoints.rb b/spec/ruby/library/stringio/shared/codepoints.rb
new file mode 100644
index 0000000000..c8ca03329f
--- /dev/null
+++ b/spec/ruby/library/stringio/shared/codepoints.rb
@@ -0,0 +1,45 @@
+# -*- encoding: utf-8 -*-
+describe :stringio_codepoints, shared: true do
+ before :each do
+ @io = StringIO.new("∂φ/∂x = gaîté")
+ @enum = @io.send(@method)
+ end
+
+ it "returns an Enumerator" do
+ @enum.should be_an_instance_of(Enumerator)
+ end
+
+ it "yields each codepoint code in turn" do
+ @enum.to_a.should == [8706, 966, 47, 8706, 120, 32, 61, 32, 103, 97, 238, 116, 233]
+ end
+
+ it "yields each codepoint starting from the current position" do
+ @io.pos = 15
+ @enum.to_a.should == [238, 116, 233]
+ end
+
+ it "raises an error if reading invalid sequence" do
+ @io.pos = 1 # inside of a multibyte sequence
+ lambda { @enum.first }.should raise_error(ArgumentError)
+ end
+
+ it "raises an IOError if not readable" do
+ @io.close_read
+ lambda { @enum.to_a }.should raise_error(IOError)
+
+ io = StringIO.new("xyz", "w")
+ lambda { io.send(@method).to_a }.should raise_error(IOError)
+ end
+
+
+ it "calls the given block" do
+ r = []
+ @io.send(@method){|c| r << c }
+ r.should == [8706, 966, 47, 8706, 120, 32, 61, 32, 103, 97, 238, 116, 233]
+ end
+
+ it "returns self" do
+ @io.send(@method) {|l| l }.should equal(@io)
+ end
+
+end