summaryrefslogtreecommitdiff
path: root/spec/ruby/core/encoding
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-09-25 10:41:16 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-09-25 10:41:16 +0000
commite87fb88be844f0fae736768846954b6f6f7dc7c3 (patch)
treecbe2ab069e40b5b7f3217ce95b793426b303a305 /spec/ruby/core/encoding
parente59bf54b3a88d0465cca021afae7dc05b6db57a7 (diff)
Update to ruby/spec@241f9e7
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64831 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/encoding')
-rw-r--r--spec/ruby/core/encoding/converter/convpath_spec.rb55
-rw-r--r--spec/ruby/core/encoding/converter/search_convpath_spec.rb68
2 files changed, 17 insertions, 106 deletions
diff --git a/spec/ruby/core/encoding/converter/convpath_spec.rb b/spec/ruby/core/encoding/converter/convpath_spec.rb
index 5e8aa8c2a2..e41a6c4205 100644
--- a/spec/ruby/core/encoding/converter/convpath_spec.rb
+++ b/spec/ruby/core/encoding/converter/convpath_spec.rb
@@ -2,56 +2,17 @@ require_relative '../../../spec_helper'
with_feature :encoding do
describe "Encoding::Converter#convpath" do
- before :all do
- @perms = Encoding.name_list.permutation(2).map do |pair|
- Encoding::Converter.new(pair.first, pair.last) rescue nil
- end.compact.map{|ec| ec.convpath}
- end
-
- it "returns an Array" do
- ec = Encoding::Converter.new('ASCII', 'EUC-JP')
- ec.convpath.should be_an_instance_of(Array)
- end
-
- it "returns each encoding pair as a sub-Array" do
- ec = Encoding::Converter.new('ASCII', 'EUC-JP')
- ec.convpath.first.should be_an_instance_of(Array)
- ec.convpath.first.size.should == 2
- end
-
- it "returns each encoding as an Encoding object" do
- ec = Encoding::Converter.new('ASCII', 'EUC-JP')
- ec.convpath.first.first.should be_an_instance_of(Encoding)
- ec.convpath.first.last.should be_an_instance_of(Encoding)
+ it "returns an Array with a single element if there is a direct converter" do
+ cp = Encoding::Converter.new('ASCII', 'UTF-8').convpath
+ cp.should == [[Encoding::US_ASCII, Encoding::UTF_8]]
end
it "returns multiple encoding pairs when direct conversion is impossible" do
- ec = Encoding::Converter.new('ascii','Big5')
- ec.convpath.size.should == 2
- ec.convpath.first.first.should == Encoding::US_ASCII
- ec.convpath.first.last.should == ec.convpath.last.first
- ec.convpath.last.last.should == 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
+ cp = Encoding::Converter.new('ascii','Big5').convpath
+ cp.should == [
+ [Encoding::US_ASCII, Encoding::UTF_8],
+ [Encoding::UTF_8, Encoding::Big5]
+ ]
end
it "indicates if crlf_newline conversion would occur" do
diff --git a/spec/ruby/core/encoding/converter/search_convpath_spec.rb b/spec/ruby/core/encoding/converter/search_convpath_spec.rb
index 0e305a1236..9e924da023 100644
--- a/spec/ruby/core/encoding/converter/search_convpath_spec.rb
+++ b/spec/ruby/core/encoding/converter/search_convpath_spec.rb
@@ -1,70 +1,23 @@
-# frozen_string_literal: true
-
require_relative '../../../spec_helper'
with_feature :encoding do
describe "Encoding::Converter.search_convpath" do
- before :all do
- t = []
- temp = ''.dup
-# Encoding.list.reject { |e| e.dummy? }.map { |e| e.to_s }.permutation(2).each { |a| t << a if Array === a }
-# Encoding.list.map { |e| e.to_s }.permutation(2).each { |a| t << a if Array === a }
-# Encoding.name_list.permutation(2).each { |a| t << a if Array === a }
- Encoding.name_list.permutation(2).each { |a| t << a if Array === a }
- @perms = t.map do |a, b|
- temp << "#{a.ljust(15)} #{b}"
- Encoding::Converter.search_convpath(a, b) rescue nil
- end.compact
- 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)
+ it "returns an Array with a single element if there is a direct converter" do
+ cp = Encoding::Converter.search_convpath('ASCII', 'UTF-8')
+ cp.should == [[Encoding::US_ASCII, Encoding::UTF_8]]
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
+ cp.should == [
+ [Encoding::US_ASCII, Encoding::UTF_8],
+ [Encoding::UTF_8, Encoding::Big5]
+ ]
end
it "indicates if crlf_newline conversion would occur" do
cp = Encoding::Converter.search_convpath(
- "ISo-8859-1", "EUC-JP", {crlf_newline: true})
+ "ISO-8859-1", "EUC-JP", {crlf_newline: true})
cp.last.should == "crlf_newline"
cp = Encoding::Converter.search_convpath(
@@ -78,13 +31,10 @@ with_feature :encoding do
# Encoding::ASCII_8BIT, Encoding::Emacs_Mule)
# end.should raise_error(Encoding::ConverterNotFoundError)
begin
- Encoding::Converter.search_convpath(Encoding::ASCII_8BIT.to_s, Encoding::Emacs_Mule)
+ Encoding::Converter.search_convpath(Encoding::ASCII_8BIT, Encoding::Emacs_Mule)
rescue => e
e.class.should == Encoding::ConverterNotFoundError
- else
- e.class.should == Encoding::ConverterNotFoundError
end
-
end
end
end