rubysl-iconv 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +25 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/ext/rubysl/iconv/extconf.rb +51 -0
- data/ext/rubysl/iconv/iconv.c +927 -0
- data/lib/iconv.rb +1 -0
- data/lib/rubysl/iconv.rb +2 -0
- data/lib/rubysl/iconv/version.rb +5 -0
- data/rubysl-iconv.gemspec +23 -0
- data/spec/charset_map_spec.rb +20 -0
- data/spec/close_spec.rb +24 -0
- data/spec/conv_spec.rb +32 -0
- data/spec/failure/failed_spec.rb +53 -0
- data/spec/failure/inspect_spec.rb +22 -0
- data/spec/failure/success_spec.rb +51 -0
- data/spec/failure_spec.rb +30 -0
- data/spec/fixtures/classes.rb +11 -0
- data/spec/iconv_spec.rb +211 -0
- data/spec/new_spec.rb +8 -0
- data/spec/open_spec.rb +29 -0
- data/spec/shared/initialize_exceptions.rb +13 -0
- data/spec/shared/new.rb +33 -0
- metadata +125 -0
data/lib/iconv.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "rubysl/iconv"
|
data/lib/rubysl/iconv.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require './lib/rubysl/iconv/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "rubysl-iconv"
|
6
|
+
spec.version = RubySL::Iconv::VERSION
|
7
|
+
spec.authors = ["Brian Shirai"]
|
8
|
+
spec.email = ["brixen@gmail.com"]
|
9
|
+
spec.description = %q{Ruby standard library iconv.}
|
10
|
+
spec.summary = %q{Ruby standard library iconv.}
|
11
|
+
spec.homepage = "https://github.com/rubysl/rubysl-iconv"
|
12
|
+
spec.license = "BSD"
|
13
|
+
|
14
|
+
spec.files = `git ls-files`.split($/)
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.extensions = ["ext/rubysl/iconv/extconf.rb"]
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "mspec", "~> 1.5"
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path('../fixtures/classes.rb', __FILE__)
|
2
|
+
|
3
|
+
ruby_version_is ''...'2.0' do
|
4
|
+
describe "Iconv.charset_map" do
|
5
|
+
it "acts as a map" do
|
6
|
+
Iconv.charset_map.respond_to?(:[]).should be_true
|
7
|
+
Iconv.charset_map.respond_to?(:include?).should be_true
|
8
|
+
Iconv.charset_map.respond_to?(:to_hash).should be_true
|
9
|
+
|
10
|
+
Iconv.charset_map.include?("x-nonexistent-encoding").should be_false
|
11
|
+
end
|
12
|
+
|
13
|
+
# it "maps from canonical name to system dependent name" do
|
14
|
+
# end
|
15
|
+
|
16
|
+
it "returns nil when given an unknown encoding name" do
|
17
|
+
Iconv.charset_map["x-nonexistent-encoding"].should be_nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/spec/close_spec.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path('../fixtures/classes.rb', __FILE__)
|
2
|
+
|
3
|
+
ruby_version_is ''...'2.0' do
|
4
|
+
describe "Iconv#close" do
|
5
|
+
it "ignores multiple calls" do
|
6
|
+
conv1 = Iconv.new("us-ascii", "us-ascii")
|
7
|
+
conv1.close.should == ""
|
8
|
+
conv1.close.should be_nil
|
9
|
+
end
|
10
|
+
|
11
|
+
it "does not raise an exception if called inside an .open block" do
|
12
|
+
Iconv.open "us-ascii", "us-ascii" do |conv2|
|
13
|
+
conv2.close.should == ""
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns a string containing the byte sequence to change the output buffer to its initial shift state" do
|
18
|
+
Iconv.open "ISO-2022-JP", "UTF-8" do |cd|
|
19
|
+
cd.iconv("\343\201\262")
|
20
|
+
cd.close.should == encode("\e(B", "iso-2022-jp")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/conv_spec.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path('../shared/initialize_exceptions', __FILE__)
|
2
|
+
require File.expand_path('../fixtures/classes.rb', __FILE__)
|
3
|
+
|
4
|
+
ruby_version_is ''...'2.0' do
|
5
|
+
describe "Iconv.conv" do
|
6
|
+
it_behaves_like :iconv_initialize_exceptions, :conv, "test"
|
7
|
+
|
8
|
+
it "acts exactly as if opening a converter and invoking #iconv once" do
|
9
|
+
Iconv.conv("utf-8", "iso-8859-1", "expos\xe9").should == encode("expos\xc3\xa9", "utf-8")
|
10
|
+
|
11
|
+
str = mock("string-like")
|
12
|
+
str.should_receive(:to_str).and_return("cacha\xc3\xa7a")
|
13
|
+
Iconv.conv("iso-8859-1", "utf-8", str).should == encode("cacha\xe7a", "iso-8859-1")
|
14
|
+
|
15
|
+
Iconv.conv("utf-16", "us-ascii", "a").should equal_utf16("\xfe\xff\0a")
|
16
|
+
# each call is completely independent; never retain context!
|
17
|
+
Iconv.conv("utf-16", "us-ascii", "b").should equal_utf16("\xfe\xff\0b")
|
18
|
+
|
19
|
+
Iconv.conv("us-ascii", "iso-8859-1", nil).should == ""
|
20
|
+
|
21
|
+
Iconv.conv("utf-16", "utf-8", "").should == ""
|
22
|
+
|
23
|
+
lambda do
|
24
|
+
Iconv.conv("utf-8", "utf-8", "test\xff")
|
25
|
+
end.should raise_error(Iconv::IllegalSequence)
|
26
|
+
|
27
|
+
lambda do
|
28
|
+
Iconv.conv("utf-8", "utf-8", "euro \xe2")
|
29
|
+
end.should raise_error(Iconv::InvalidCharacter)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.expand_path('../../fixtures/classes.rb', __FILE__)
|
2
|
+
|
3
|
+
ruby_version_is ''...'2.0' do
|
4
|
+
describe "Iconv::Failure#failed" do
|
5
|
+
it "returns a substring of the original string passed to Iconv that starts at the character which caused the exception" do
|
6
|
+
lambda {
|
7
|
+
begin
|
8
|
+
Iconv.open "utf-8", "utf-8" do |conv|
|
9
|
+
conv.iconv "test \xff test \xff"
|
10
|
+
end
|
11
|
+
rescue Iconv::Failure => e
|
12
|
+
@ex = e
|
13
|
+
raise e
|
14
|
+
end
|
15
|
+
}.should raise_error(Iconv::Failure)
|
16
|
+
@ex.failed.should == "\xff test \xff"
|
17
|
+
|
18
|
+
lambda {
|
19
|
+
begin
|
20
|
+
Iconv.open "utf-8", "utf-8" do |conv|
|
21
|
+
conv.iconv "test \xe2\x82"
|
22
|
+
end
|
23
|
+
rescue Iconv::Failure => e
|
24
|
+
@ex = e
|
25
|
+
raise e
|
26
|
+
end
|
27
|
+
}.should raise_error(Iconv::Failure)
|
28
|
+
@ex.failed.should == "\xe2\x82"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "for Iconv.iconv and Iconv.conv returns an array containing a single element when instantiated" do
|
32
|
+
lambda {
|
33
|
+
begin
|
34
|
+
Iconv.iconv("utf-8", "utf-8", "test \xff test")
|
35
|
+
rescue Iconv::Failure => e
|
36
|
+
@ex = e
|
37
|
+
raise e
|
38
|
+
end
|
39
|
+
}.should raise_error(Iconv::Failure)
|
40
|
+
@ex.failed.should == ["\xff test"]
|
41
|
+
|
42
|
+
lambda {
|
43
|
+
begin
|
44
|
+
Iconv.conv("utf-8", "utf-8", "test \xff test")
|
45
|
+
rescue Iconv::Failure => e
|
46
|
+
@ex = e
|
47
|
+
raise e
|
48
|
+
end
|
49
|
+
}.should raise_error(Iconv::Failure)
|
50
|
+
@ex.failed.should == ["\xff test"]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path('../../fixtures/classes.rb', __FILE__)
|
2
|
+
|
3
|
+
ruby_version_is ''...'2.0' do
|
4
|
+
describe "Iconv::Failure#inspect" do
|
5
|
+
it "includes information on the exception class name, #succes and #failed" do
|
6
|
+
lambda {
|
7
|
+
begin
|
8
|
+
Iconv.open "utf-8", "utf-8" do |conv|
|
9
|
+
conv.iconv "testing string \x80 until an error occurred"
|
10
|
+
end
|
11
|
+
rescue Iconv::Failure => e
|
12
|
+
@ex = e
|
13
|
+
raise e
|
14
|
+
end
|
15
|
+
}.should raise_error(Iconv::Failure)
|
16
|
+
inspection = @ex.inspect
|
17
|
+
inspection.should include(@ex.class.to_s)
|
18
|
+
inspection.should include(@ex.success.inspect)
|
19
|
+
inspection.should include(@ex.failed.inspect)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.expand_path('../../fixtures/classes.rb', __FILE__)
|
2
|
+
|
3
|
+
ruby_version_is ''...'2.0' do
|
4
|
+
describe "Iconv::Failure#success" do
|
5
|
+
it "for Iconv#iconv and Iconv.conv returns the substring of the original string passed which was translated successfully until the exception ocurred" do
|
6
|
+
lambda {
|
7
|
+
begin
|
8
|
+
Iconv.open "utf-8", "utf-8" do |conv|
|
9
|
+
conv.iconv "test \xff test \xff"
|
10
|
+
end
|
11
|
+
rescue Iconv::Failure => e
|
12
|
+
@ex = e
|
13
|
+
raise e
|
14
|
+
end
|
15
|
+
}.should raise_error(Iconv::Failure)
|
16
|
+
@ex.success.should == "test "
|
17
|
+
|
18
|
+
lambda {
|
19
|
+
begin
|
20
|
+
Iconv.conv "utf-8", "utf-8", "\xe2\x82"
|
21
|
+
rescue Iconv::Failure => e
|
22
|
+
@ex = e
|
23
|
+
raise e
|
24
|
+
end
|
25
|
+
}.should raise_error(Iconv::Failure)
|
26
|
+
@ex.success.should == ""
|
27
|
+
end
|
28
|
+
|
29
|
+
it "for Iconv.iconv returns an array containing all the strings that were translated successfully until the exception ocurred, in order" do
|
30
|
+
lambda {
|
31
|
+
begin
|
32
|
+
Iconv.iconv("utf-8", "utf-8", "\xfferror")
|
33
|
+
rescue Iconv::Failure => e
|
34
|
+
@ex = e
|
35
|
+
raise e
|
36
|
+
end
|
37
|
+
}.should raise_error(Iconv::Failure)
|
38
|
+
@ex.success.should == [""]
|
39
|
+
|
40
|
+
lambda {
|
41
|
+
begin
|
42
|
+
Iconv.iconv("utf-8", "utf-8", "test", "testing", "until\xfferror")
|
43
|
+
rescue Iconv::Failure => e
|
44
|
+
@ex = e
|
45
|
+
raise e
|
46
|
+
end
|
47
|
+
}.should raise_error(Iconv::Failure)
|
48
|
+
@ex.success.should == ["test", "testing", "until"]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path('../fixtures/classes.rb', __FILE__)
|
2
|
+
|
3
|
+
ruby_version_is ''...'2.0' do
|
4
|
+
describe "Iconv::Failure" do
|
5
|
+
it "is a module" do
|
6
|
+
Iconv::Failure.should be_kind_of(Module)
|
7
|
+
Iconv::Failure.should_not be_kind_of(Class)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "is included by Iconv::InvalidEncoding" do
|
11
|
+
Iconv::Failure.should be_ancestor_of(Iconv::InvalidEncoding)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "is included by Iconv::IllegalSequence" do
|
15
|
+
Iconv::Failure.should be_ancestor_of(Iconv::IllegalSequence)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "is included by Iconv::InvalidCharacter" do
|
19
|
+
Iconv::Failure.should be_ancestor_of(Iconv::InvalidCharacter)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "is included by Iconv::OutOfRange" do
|
23
|
+
Iconv::Failure.should be_ancestor_of(Iconv::OutOfRange)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "is included by Iconv::BrokenLibrary" do
|
27
|
+
Iconv::Failure.should be_ancestor_of(Iconv::BrokenLibrary)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/spec/iconv_spec.rb
ADDED
@@ -0,0 +1,211 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../shared/initialize_exceptions', __FILE__)
|
3
|
+
require File.expand_path('../fixtures/classes.rb', __FILE__)
|
4
|
+
|
5
|
+
# These specs assume the Iconv implementation supports at least
|
6
|
+
# the following encodings:
|
7
|
+
# us-ascii, utf-8, utf-16, utf-16be, utf-16le, iso-8859-1
|
8
|
+
|
9
|
+
ruby_version_is ''...'2.0' do
|
10
|
+
describe "Iconv#iconv" do
|
11
|
+
it "raises an ArgumentError when called on a closed converter" do
|
12
|
+
conv = Iconv.new("us-ascii", "us-ascii")
|
13
|
+
conv.close
|
14
|
+
lambda { conv.iconv("test") }.should raise_error(ArgumentError)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "when given a string or string-like parameter returns a converted version of it" do
|
18
|
+
Iconv.open "utf-8", "iso-8859-1" do |conv|
|
19
|
+
conv.iconv("expos\xe9").should == "expos\xc3\xa9"
|
20
|
+
|
21
|
+
stringlike = mock("string-like")
|
22
|
+
stringlike.should_receive(:to_str).and_return("r\xe9sum\xe9")
|
23
|
+
conv.iconv(stringlike).should == "r\xc3\xa9sum\xc3\xa9"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "keeps context between calls" do
|
28
|
+
Iconv.open "utf-16", "us-ascii" do |conv|
|
29
|
+
# BOM for first call of utf-16
|
30
|
+
conv.iconv("a").should equal_utf16("\xfe\xff\0a")
|
31
|
+
# no BOM for consecutive calls
|
32
|
+
conv.iconv("a").should equal_utf16("\0a")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "when given a start and end position returns the substring" do
|
37
|
+
Iconv.open "us-ascii", "us-ascii" do |conv|
|
38
|
+
conv.iconv("testing", 1, 4).should == "esti"
|
39
|
+
conv.iconv("testing", 2, 1).should == "s"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it "when given a negative start position counts from the end of string" do
|
44
|
+
Iconv.open "us-ascii", "us-ascii" do |conv|
|
45
|
+
conv.iconv("testing", -7, 4).should == "test"
|
46
|
+
conv.iconv("testing", -3, 7).should == "ing"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it "when the end parameter is omitted or nil goes until the end of the string" do
|
51
|
+
Iconv.open "us-ascii", "us-ascii" do |conv|
|
52
|
+
conv.iconv("testing", 0).should == "testing"
|
53
|
+
conv.iconv("testing", 4).should == "ing"
|
54
|
+
conv.iconv("testing", 4, nil).should == "ing"
|
55
|
+
conv.iconv("testing", -3).should == "ing"
|
56
|
+
conv.iconv("testing", -4, nil).should == "ting"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
ruby_bug "[ruby-core:17092]", "1.8.6.258" do
|
61
|
+
it "when given a positive length" do
|
62
|
+
Iconv.open "us-ascii", "us-ascii" do |conv|
|
63
|
+
conv.iconv("testing", 0, 4).should == "test"
|
64
|
+
conv.iconv("testing", 4, 6).should == "ing"
|
65
|
+
conv.iconv("substring", -6, 6).should == "string"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it "when given a negative length" do
|
70
|
+
Iconv.open "us-ascii", "us-ascii" do |conv|
|
71
|
+
conv.iconv("testing", 0, -1).should == "testing"
|
72
|
+
conv.iconv("testing", 2, -4).should == "sting"
|
73
|
+
conv.iconv("substring", -6, -4).should == "string"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it "raises Iconv::IllegalSequence when faced with an invalid byte for the source encoding" do
|
79
|
+
Iconv.open "utf-8", "utf-8" do |conv|
|
80
|
+
lambda { conv.iconv("test\x80") }.should raise_error(Iconv::IllegalSequence)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
platform_is :linux, :darwin, :freebsd do
|
85
|
+
# glibc iconv and GNU libiconv wrongly raises EILSEQ.
|
86
|
+
# Linux, Darwin, and FreeBSD usually use them.
|
87
|
+
# NetBSD's libc iconv, Citrus iconv, correctly behaves as POSIX,
|
88
|
+
# but on NetBSD users may install GNU libiconv and use it.
|
89
|
+
it "raises Iconv::IllegalSequence when a character cannot be represented on the target encoding" do
|
90
|
+
Iconv.open "us-ascii", "utf-8" do |conv|
|
91
|
+
lambda { conv.iconv("euro \xe2\x82\xac") }.should raise_error(Iconv::IllegalSequence)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it "raises Iconv::InvalidCharacter when an incomplete character or shift sequence happens at the end of the input buffer" do
|
97
|
+
Iconv.open "utf-8", "utf-8" do |conv|
|
98
|
+
lambda { conv.iconv("euro \xe2") }.should raise_error(Iconv::InvalidCharacter)
|
99
|
+
lambda { conv.iconv("euro \xe2\x82") }.should raise_error(Iconv::InvalidCharacter)
|
100
|
+
end
|
101
|
+
Iconv.open "utf-16be", "utf-16be" do |conv|
|
102
|
+
lambda { conv.iconv("a") }.should raise_error(Iconv::InvalidCharacter)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
ruby_bug "#17910", "1.8.6.114" do
|
107
|
+
it "sanitizes invalid upper bounds" do
|
108
|
+
Iconv.open "us-ascii", "us-ascii" do |conv|
|
109
|
+
conv.iconv("testing", 0, 99).should == "testing"
|
110
|
+
conv.iconv("testing", 10, 12).should == ""
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
it "returns a blank string on invalid lower bounds" do
|
116
|
+
Iconv.open "us-ascii", "us-ascii" do |conv|
|
117
|
+
conv.iconv("testing", -10, -8).should == ""
|
118
|
+
conv.iconv("testing", -8).should == ""
|
119
|
+
conv.iconv("testing", -9, 5).should == ""
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe "Iconv.iconv" do
|
125
|
+
it "converts a series of strings with a single converter" do
|
126
|
+
ary = [encode("\0a\0b\0c", "utf-16be"), encode("\0d\0e", "utf-16be")]
|
127
|
+
Iconv.iconv("utf-16be", "us-ascii", "abc", "de").should == ary
|
128
|
+
# BOM only on first string
|
129
|
+
Iconv.iconv("utf-16", "utf-8", "abc", "de").should equal_utf16(["\xfe\xff\0a\0b\0c", "\0d\0e"])
|
130
|
+
end
|
131
|
+
|
132
|
+
it "returns an empty array when given no strings to convert" do
|
133
|
+
Iconv.iconv("us-ascii", "utf-8").should == []
|
134
|
+
end
|
135
|
+
|
136
|
+
it_behaves_like :iconv_initialize_exceptions, :iconv, "test"
|
137
|
+
|
138
|
+
platform_is :linux, :darwin, :freebsd do
|
139
|
+
# //ignore is glibc iconv and GNU libiconv specific behavior, not POSIX
|
140
|
+
describe "using the ignore option" do
|
141
|
+
# This spec exists because some implementions of libiconv return
|
142
|
+
# an error for this sequence even though they consume all of the
|
143
|
+
# input and write the proper output. We want to be sure that those
|
144
|
+
# platforms ignore the error and give us the data back.
|
145
|
+
#
|
146
|
+
it "causes unknown bytes to be ignored" do
|
147
|
+
str = "f\303\266\303\266 bar" # this is foo bar, with umlate o's
|
148
|
+
Iconv.iconv('ascii//ignore', 'utf-8', str)[0].should == "f bar"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "The 'utf-8' encoder" do
|
155
|
+
it "emits proper representations for characters outside the Basic Multilingual Plane" do
|
156
|
+
Iconv.iconv("utf-8", "utf-16be", "\xd8\x40\xdc\x00").should == ["\xf0\xa0\x80\x80"]
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "The 'utf-16' encoder" do
|
161
|
+
|
162
|
+
ruby_version_is "".."1.8.6p230" do
|
163
|
+
it "emits an empty string when the source input is empty" do
|
164
|
+
Iconv.iconv("utf-16", "us-ascii", "", "").should == ["", ""]
|
165
|
+
Iconv.open "utf-16", "utf-8" do |conv|
|
166
|
+
conv.iconv("").should == ""
|
167
|
+
conv.iconv("test", 1, 1).should == ""
|
168
|
+
conv.iconv("test", 3, -3).should == ""
|
169
|
+
conv.iconv("test", 1, -4).should == ""
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
ruby_version_is "1.8.6p238".."1.9" do
|
175
|
+
it "emits an empty string when the source input is empty" do
|
176
|
+
Iconv.iconv("utf-16", "us-ascii", "", "").should == ["", ""]
|
177
|
+
Iconv.open "utf-16", "utf-8" do |conv|
|
178
|
+
conv.iconv("").should == ""
|
179
|
+
conv.iconv("test", 1, 0).should == ""
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
it "emits a byte-order mark on first non-empty output" do
|
185
|
+
Iconv.iconv("utf-16", "us-ascii", "a").should equal_utf16(["\xfe\xff\0a"])
|
186
|
+
Iconv.iconv("utf-16", "utf-16", "\x80\x80", "\x81\x81").should equal_utf16(["\xfe\xff\x80\x80", "\x81\x81"])
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe "The 'utf-16be' decoder" do
|
191
|
+
it "does not emit a byte-order mark" do
|
192
|
+
Iconv.iconv("utf-16be", "utf-8", "ab").should == [encode("\0a\0b", "utf-16be")]
|
193
|
+
end
|
194
|
+
|
195
|
+
it "treats possible byte-order marks as regular characters" do
|
196
|
+
Iconv.iconv("utf-8", "utf-16be", "\xfe\xff\0a").should == ["\xef\xbb\xbfa"]
|
197
|
+
Iconv.iconv("utf-8", "utf-16be", "\xff\xfe\0a").should == ["\xef\xbf\xbea"]
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
describe "The 'utf-16le' decoder" do
|
202
|
+
it "does not emit a byte-order mark" do
|
203
|
+
Iconv.iconv("utf-16le", "utf-8", "ab").should == [encode("a\0b\0", "utf-16le")]
|
204
|
+
end
|
205
|
+
|
206
|
+
it "treats possible byte-order marks as regular characters" do
|
207
|
+
Iconv.iconv("utf-8", "utf-16le", "\xfe\xff\0a").should == ["\xef\xbf\xbe\xe6\x84\x80"]
|
208
|
+
Iconv.iconv("utf-8", "utf-16le", "\xff\xfe\0a").should == ["\xef\xbb\xbf\xe6\x84\x80"]
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|