aboutsummaryrefslogtreecommitdiffstats
path: root/spec/rubyspec/core/encoding/converter/search_convpath_spec.rb
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-07 12:04:49 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-07 12:04:49 +0000
commita3736e97a6ca517c2cd7d3d93a8f2ef86e39e5b5 (patch)
tree9eef7f720314ebaff56845a74e203770e62284e4 /spec/rubyspec/core/encoding/converter/search_convpath_spec.rb
parent52df1d0d3370919711c0577aaa42d1a864709885 (diff)
downloadruby-a3736e97a6ca517c2cd7d3d93a8f2ef86e39e5b5.tar.gz
Add in-tree mspec and ruby/spec
* For easier modifications of ruby/spec by MRI developers. * .gitignore: track changes under spec. * spec/mspec, spec/rubyspec: add in-tree mspec and ruby/spec. These files can therefore be updated like any other file in MRI. Instructions are provided in spec/README. [Feature #13156] [ruby-core:79246] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/rubyspec/core/encoding/converter/search_convpath_spec.rb')
-rw-r--r--spec/rubyspec/core/encoding/converter/search_convpath_spec.rb73
1 files changed, 73 insertions, 0 deletions
diff --git a/spec/rubyspec/core/encoding/converter/search_convpath_spec.rb b/spec/rubyspec/core/encoding/converter/search_convpath_spec.rb
new file mode 100644
index 0000000000..c04eeb98ad
--- /dev/null
+++ b/spec/rubyspec/core/encoding/converter/search_convpath_spec.rb
@@ -0,0 +1,73 @@
+require File.expand_path('../../../../spec_helper', __FILE__)
+
+with_feature :encoding do
+ describe "Encoding::Converter.search_convpath" do
+ before :all do
+ @perms = Encoding.name_list.permutation(2).map do |pair|
+ Encoding::Converter.search_convpath(pair.first, pair.last) rescue []
+ end
+ end
+
+ it "returns an Array" do
+ Encoding::Converter.search_convpath('ASCII', 'EUC-JP').\
+ should be_an_instance_of(Array)
+ end
+
+ it "returns each encoding pair as a sub-Array" do
+ cp = Encoding::Converter.search_convpath('ASCII', 'EUC-JP')
+ cp.first.should be_an_instance_of(Array)
+ cp.first.size.should == 2
+ end
+
+ it "returns each encoding as an Encoding object" do
+ cp = Encoding::Converter.search_convpath('ASCII', 'EUC-JP')
+ cp.first.first.should be_an_instance_of(Encoding)
+ cp.first.last.should be_an_instance_of(Encoding)
+ end
+
+ it "returns multiple encoding pairs when direct conversion is impossible" do
+ cp = Encoding::Converter.search_convpath('ascii','Big5')
+ cp.size.should == 2
+ cp.first.should == [Encoding::US_ASCII, Encoding::UTF_8]
+ cp.last.should == [Encoding::UTF_8, Encoding::Big5]
+ end
+
+ it "sets the last element of each pair to the first element of the next" do
+ @perms.each do |convpath|
+ next if convpath.size == 1
+ convpath.each_with_index do |pair, idx|
+ break if idx == convpath.size - 1
+ pair.last.should == convpath[idx+1].first
+ end
+ end
+ end
+
+ it "only lists a source encoding once" do
+ @perms.each do |convpath|
+ next if convpath.size < 2
+ seen = Hash.new(false)
+ convpath.each_with_index do |pair, idx|
+ seen.key?(pair.first).should be_false if idx > 0
+ seen[pair.first] = true
+ end
+ end
+ end
+
+ it "indicates if crlf_newline conversion would occur" do
+ cp = Encoding::Converter.search_convpath(
+ "ISo-8859-1", "EUC-JP", {crlf_newline: true})
+ cp.last.should == "crlf_newline"
+
+ cp = Encoding::Converter.search_convpath(
+ "ASCII", "UTF-8", {crlf_newline: false})
+ cp.last.should_not == "crlf_newline"
+ end
+
+ it "raises an Encoding::ConverterNotFoundError if no conversion path exists" do
+ lambda do
+ Encoding::Converter.search_convpath(
+ Encoding::ASCII_8BIT, Encoding::Emacs_Mule)
+ end.should raise_error(Encoding::ConverterNotFoundError)
+ end
+ end
+end