ffi-icu 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.rspec +2 -0
- data/.travis.yml +9 -3
- data/README.md +5 -6
- data/ffi-icu.gemspec +2 -3
- data/lib/ffi-icu.rb +0 -9
- data/lib/ffi-icu/lib.rb +6 -1
- data/lib/ffi-icu/version.rb +1 -1
- data/spec/break_iterator_spec.rb +20 -19
- data/spec/chardet_spec.rb +10 -12
- data/spec/collation_spec.rb +19 -22
- data/spec/lib/version_info_spec.rb +11 -6
- data/spec/lib_spec.rb +11 -11
- data/spec/locale_spec.rb +97 -85
- data/spec/normalization_spec.rb +2 -4
- data/spec/normalizer_spec.rb +24 -26
- data/spec/number_formatting_spec.rb +28 -25
- data/spec/time_spec.rb +34 -37
- data/spec/transliteration_spec.rb +5 -6
- data/spec/uchar_spec.rb +8 -10
- metadata +12 -20
- data/spec/spec.opts +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3e1817bf83d85197ea62937c274ff98c71984ef4a432a6f76fc3cca764bf45dc
|
4
|
+
data.tar.gz: 2a21f2177dc151831fe89782be8cfe53d2f13a6d1038961eb1efe5c3970a27a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fb2d659678226632c485ea24de6e79f7d20ccf7b80b03833f680bb295ae07736957f3a9037ac1d3639b432f6974c279b580767d08315ad005c57cc6be79ed8b
|
7
|
+
data.tar.gz: 9c49ddef23ae27f88d4eaffbaf0cf42b670e7f07939b7c19b6255a4ac157faae25e8eb5bc973764e767b3b32d40226c4b1cc95772c629fbe4b678d4cff5ebccb
|
data/.rspec
ADDED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
ffi-icu
|
1
|
+
ffi-icu [](https://travis-ci.org/erickguan/ffi-icu)
|
2
2
|
=======
|
3
3
|
|
4
4
|
Simple FFI wrappers for ICU. Checkout the renovated [ICU gem](https://github.com/fantasticfears/icu4r) instead which supports various of encoding and distributed with packaged source. FFI-ICU needs some love with ICU gem's transcoding method.
|
@@ -47,7 +47,6 @@ or
|
|
47
47
|
Why not just use rchardet?
|
48
48
|
|
49
49
|
* speed
|
50
|
-
* 1.9 support
|
51
50
|
|
52
51
|
Locale Sensitive Collation
|
53
52
|
--------------------------
|
@@ -130,15 +129,15 @@ Platforms:
|
|
130
129
|
|
131
130
|
Rubies:
|
132
131
|
|
133
|
-
- 2.
|
134
|
-
- 2.
|
135
|
-
- 2.
|
132
|
+
- 2.5
|
133
|
+
- 2.6
|
134
|
+
- 2.7
|
136
135
|
- ruby-head
|
137
136
|
|
138
137
|
TODO:
|
139
138
|
=====
|
140
139
|
|
141
|
-
* Any other useful part of ICU?
|
140
|
+
* Any other useful part of ICU?
|
142
141
|
* Windows?!
|
143
142
|
|
144
143
|
Note on Patches/Pull Requests
|
data/ffi-icu.gemspec
CHANGED
@@ -21,7 +21,6 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.summary = %q{Simple Ruby FFI wrappers for things I need from ICU.}
|
22
22
|
|
23
23
|
s.add_runtime_dependency "ffi", "~> 1.0", ">= 1.0.9"
|
24
|
-
s.add_development_dependency 'rspec', '~>
|
25
|
-
s.add_development_dependency "rake", ["
|
24
|
+
s.add_development_dependency 'rspec', '~> 3.9'
|
25
|
+
s.add_development_dependency "rake", [">= 12.3.3"]
|
26
26
|
end
|
27
|
-
|
data/lib/ffi-icu.rb
CHANGED
data/lib/ffi-icu/lib.rb
CHANGED
@@ -39,7 +39,12 @@ module ICU
|
|
39
39
|
[find_lib("libicui18n.#{FFI::Platform::LIBSUFFIX}.??"),
|
40
40
|
find_lib("libicutu.#{FFI::Platform::LIBSUFFIX}.??")]
|
41
41
|
when :osx
|
42
|
-
|
42
|
+
# See https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11_0_1-release-notes (62986286)
|
43
|
+
if Gem::Version.new(`sw_vers -productVersion`) >= Gem::Version.new('11')
|
44
|
+
["libicucore.#{FFI::Platform::LIBSUFFIX}"]
|
45
|
+
else
|
46
|
+
[find_lib("libicucore.#{FFI::Platform::LIBSUFFIX}")]
|
47
|
+
end
|
43
48
|
when :linux
|
44
49
|
[find_lib("libicui18n.#{FFI::Platform::LIBSUFFIX}.??"),
|
45
50
|
find_lib("libicutu.#{FFI::Platform::LIBSUFFIX}.??")]
|
data/lib/ffi-icu/version.rb
CHANGED
data/spec/break_iterator_spec.rb
CHANGED
@@ -1,75 +1,76 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
3
|
module ICU
|
6
4
|
describe BreakIterator do
|
7
5
|
|
8
6
|
it "should return available locales" do
|
9
7
|
locales = ICU::BreakIterator.available_locales
|
10
|
-
locales.
|
11
|
-
locales.
|
12
|
-
locales.
|
8
|
+
expect(locales).to be_an(Array)
|
9
|
+
expect(locales).to_not be_empty
|
10
|
+
expect(locales).to include("en_US")
|
13
11
|
end
|
14
12
|
|
15
13
|
it "finds all word boundaries in an English string" do
|
16
14
|
iterator = BreakIterator.new :word, "en_US"
|
17
15
|
iterator.text = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
|
18
|
-
iterator.to_a.
|
16
|
+
expect(iterator.to_a).to eq(
|
17
|
+
[0, 5, 6, 11, 12, 17, 18, 21, 22, 26, 27, 28, 39, 40, 51, 52, 56, 57, 58, 61, 62, 64, 65, 72, 73, 79, 80, 90, 91, 93, 94, 100, 101, 103, 104, 110, 111, 116, 117, 123, 124]
|
18
|
+
)
|
19
19
|
end
|
20
20
|
|
21
21
|
it "returns each substring" do
|
22
22
|
iterator = BreakIterator.new :word, "en_US"
|
23
23
|
iterator.text = "Lorem ipsum dolor sit amet."
|
24
24
|
|
25
|
-
iterator.substrings.
|
25
|
+
expect(iterator.substrings).to eq(["Lorem", " ", "ipsum", " ", "dolor", " ", "sit", " ", "amet", "."])
|
26
26
|
end
|
27
27
|
|
28
28
|
it "returns the substrings of a non-ASCII string" do
|
29
29
|
iterator = BreakIterator.new :word, "th_TH"
|
30
30
|
iterator.text = "รู้อะไรไม่สู้รู้วิชา รู้รักษาตัวรอดเป็นยอดดี"
|
31
31
|
|
32
|
-
iterator.substrings.
|
32
|
+
expect(iterator.substrings).to eq(
|
33
|
+
["รู้", "อะไร", "ไม่สู้", "รู้", "วิชา", " ", "รู้", "รักษา", "ตัว", "รอด", "เป็น", "ยอดดี"]
|
34
|
+
)
|
33
35
|
end
|
34
36
|
|
35
37
|
it "finds all word boundaries in a non-ASCII string" do
|
36
38
|
iterator = BreakIterator.new :word, "th_TH"
|
37
39
|
iterator.text = "การทดลอง"
|
38
|
-
iterator.to_a.
|
40
|
+
expect(iterator.to_a).to eq([0, 3, 8])
|
39
41
|
end
|
40
42
|
|
41
43
|
it "finds all sentence boundaries in an English string" do
|
42
44
|
iterator = BreakIterator.new :sentence, "en_US"
|
43
45
|
iterator.text = "This is a sentence. This is another sentence, with a comma in it."
|
44
|
-
iterator.to_a.
|
46
|
+
expect(iterator.to_a).to eq([0, 20, 65])
|
45
47
|
end
|
46
48
|
|
47
49
|
it "can navigate back and forward" do
|
48
50
|
iterator = BreakIterator.new :word, "en_US"
|
49
51
|
iterator.text = "Lorem ipsum dolor sit amet."
|
50
52
|
|
51
|
-
iterator.first.
|
53
|
+
expect(iterator.first).to eq(0)
|
52
54
|
iterator.next
|
53
|
-
iterator.current.
|
54
|
-
iterator.last.
|
55
|
+
expect(iterator.current).to eq(5)
|
56
|
+
expect(iterator.last).to eq(27)
|
55
57
|
end
|
56
58
|
|
57
59
|
it "fetches info about given offset" do
|
58
60
|
iterator = BreakIterator.new :word, "en_US"
|
59
61
|
iterator.text = "Lorem ipsum dolor sit amet."
|
60
62
|
|
61
|
-
iterator.following(3).
|
62
|
-
iterator.preceding(6).
|
63
|
+
expect(iterator.following(3)).to eq(5)
|
64
|
+
expect(iterator.preceding(6)).to eq(5)
|
63
65
|
|
64
|
-
iterator.
|
65
|
-
iterator.
|
66
|
+
expect(iterator).to be_boundary(5)
|
67
|
+
expect(iterator).to_not be_boundary(10)
|
66
68
|
end
|
67
69
|
|
68
70
|
it "returns an Enumerator if no block was given" do
|
69
71
|
iterator = BreakIterator.new :word, "nb"
|
70
|
-
expected = ICU.ruby19? ? Enumerator : Enumerable::Enumerator
|
71
72
|
|
72
|
-
iterator.each.
|
73
|
+
expect(iterator.each).to be_kind_of(Enumerator)
|
73
74
|
end
|
74
75
|
|
75
76
|
end # BreakIterator
|
data/spec/chardet_spec.rb
CHANGED
@@ -1,29 +1,27 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
describe ICU::CharDet::Detector do
|
6
4
|
|
7
5
|
let(:detector) { ICU::CharDet::Detector.new }
|
8
6
|
|
9
7
|
it "should recognize UTF-8" do
|
10
8
|
m = detector.detect("æåø")
|
11
|
-
m.name.
|
12
|
-
m.language.
|
9
|
+
expect(m.name).to eq("UTF-8")
|
10
|
+
expect(m.language).to be_a(String)
|
13
11
|
end
|
14
12
|
|
15
13
|
it "has a list of detectable charsets" do
|
16
14
|
cs = detector.detectable_charsets
|
17
|
-
cs.
|
18
|
-
cs.
|
15
|
+
expect(cs).to be_an(Array)
|
16
|
+
expect(cs).to_not be_empty
|
19
17
|
|
20
|
-
cs.first.
|
18
|
+
expect(cs.first).to be_a(String)
|
21
19
|
end
|
22
20
|
|
23
21
|
it "should disable / enable the input filter" do
|
24
|
-
detector.input_filter_enabled
|
22
|
+
expect(detector.input_filter_enabled?).to be_falsey
|
25
23
|
detector.input_filter_enabled = true
|
26
|
-
detector.input_filter_enabled
|
24
|
+
expect(detector.input_filter_enabled?).to be_truthy
|
27
25
|
end
|
28
26
|
|
29
27
|
it "should should set declared encoding" do
|
@@ -31,14 +29,14 @@ describe ICU::CharDet::Detector do
|
|
31
29
|
end
|
32
30
|
|
33
31
|
it "should detect several matching encodings" do
|
34
|
-
detector.detect_all("foo bar").
|
32
|
+
expect(detector.detect_all("foo bar")).to be_an(Array)
|
35
33
|
end
|
36
34
|
|
37
35
|
it "should support null bytes" do
|
38
36
|
# Create a utf-16 string and then force it to binary (ascii) to mimic data from net/http
|
39
37
|
string = "foo".encode("UTF-16").force_encoding("binary")
|
40
38
|
m = detector.detect(string)
|
41
|
-
m.name.
|
42
|
-
m.language.
|
39
|
+
expect(m.name).to eq("UTF-16BE")
|
40
|
+
expect(m.language).to be_a(String)
|
43
41
|
end
|
44
42
|
end
|
data/spec/collation_spec.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
module ICU
|
6
4
|
module Collation
|
7
5
|
describe "Collation" do
|
8
6
|
it "should collate an array of strings" do
|
9
|
-
Collation.collate("nb", %w[æ å ø]).
|
7
|
+
expect(Collation.collate("nb", %w[æ å ø])).to eq(%w[æ ø å])
|
10
8
|
end
|
11
9
|
end
|
12
10
|
|
@@ -14,51 +12,50 @@ module ICU
|
|
14
12
|
let(:collator) { Collator.new("nb") }
|
15
13
|
|
16
14
|
it "should collate an array of strings" do
|
17
|
-
collator.collate(%w[å ø æ]).
|
15
|
+
expect(collator.collate(%w[å ø æ])).to eq(%w[æ ø å])
|
18
16
|
end
|
19
17
|
|
20
18
|
it "raises an error if argument does not respond to :sort" do
|
21
|
-
|
19
|
+
expect { collator.collate(1) }.to raise_error(ArgumentError)
|
22
20
|
end
|
23
21
|
|
24
22
|
it "should return available locales" do
|
25
23
|
locales = ICU::Collation.available_locales
|
26
|
-
locales.
|
27
|
-
locales.
|
28
|
-
locales.
|
24
|
+
expect(locales).to be_an(Array)
|
25
|
+
expect(locales).to_not be_empty
|
26
|
+
expect(locales).to include("nb")
|
29
27
|
end
|
30
28
|
|
31
29
|
it "should return the locale of the collator" do
|
32
|
-
|
33
|
-
l.should == "nb"
|
30
|
+
expect(collator.locale).to eq('nb')
|
34
31
|
end
|
35
32
|
|
36
33
|
it "should compare two strings" do
|
37
|
-
collator.compare("blåbærsyltetøy", "blah").
|
38
|
-
collator.compare("blah", "blah").
|
39
|
-
collator.compare("ba", "bl").
|
34
|
+
expect(collator.compare("blåbærsyltetøy", "blah")).to eq(1)
|
35
|
+
expect(collator.compare("blah", "blah")).to eq(0)
|
36
|
+
expect(collator.compare("ba", "bl")).to eq(-1)
|
40
37
|
end
|
41
38
|
|
42
39
|
it "should know if a string is greater than another" do
|
43
|
-
collator.
|
44
|
-
collator.
|
40
|
+
expect(collator).to be_greater("z", "a")
|
41
|
+
expect(collator).to_not be_greater("a", "z")
|
45
42
|
end
|
46
43
|
|
47
44
|
it "should know if a string is greater or equal to another" do
|
48
|
-
collator.
|
49
|
-
collator.
|
50
|
-
collator.
|
45
|
+
expect(collator).to be_greater_or_equal("z", "a")
|
46
|
+
expect(collator).to be_greater_or_equal("z", "z")
|
47
|
+
expect(collator).to_not be_greater_or_equal("a", "z")
|
51
48
|
end
|
52
49
|
|
53
50
|
it "should know if a string is equal to another" do
|
54
|
-
collator.
|
55
|
-
collator.
|
51
|
+
expect(collator).to be_equal("a", "a")
|
52
|
+
expect(collator).to_not be_equal("a", "b")
|
56
53
|
end
|
57
54
|
|
58
55
|
it "should return rules" do
|
59
|
-
collator.rules.
|
56
|
+
expect(collator.rules).to_not be_empty
|
60
57
|
# ö sorts before Ö
|
61
|
-
collator.rules.include
|
58
|
+
expect(collator.rules).to include('ö<<<Ö')
|
62
59
|
end
|
63
60
|
|
64
61
|
end
|
@@ -1,14 +1,19 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
module ICU
|
6
4
|
module Lib
|
7
5
|
describe VersionInfo do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
describe '.to_a' do
|
7
|
+
subject { described_class.new.to_a }
|
8
|
+
|
9
|
+
it { is_expected.to be_an(Array) }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '.to_s' do
|
13
|
+
subject { described_class.new.to_s }
|
14
|
+
|
15
|
+
it { is_expected.to be_a(String) }
|
16
|
+
it { is_expected.to match(/^[0-9.]+$/) }
|
12
17
|
end
|
13
18
|
end
|
14
19
|
end
|
data/spec/lib_spec.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
module ICU
|
6
4
|
describe Lib do
|
7
5
|
describe 'error checking' do
|
@@ -9,8 +7,8 @@ module ICU
|
|
9
7
|
|
10
8
|
context 'upon success' do
|
11
9
|
it 'returns the block result' do
|
12
|
-
Lib.check_error { |status| return_value }.
|
13
|
-
Lib.check_error { |status| status.write_int(0); return_value }.
|
10
|
+
expect(Lib.check_error { |status| return_value }).to eq(return_value)
|
11
|
+
expect(Lib.check_error { |status| status.write_int(0); return_value }).to eq(return_value)
|
14
12
|
end
|
15
13
|
end
|
16
14
|
|
@@ -28,8 +26,9 @@ module ICU
|
|
28
26
|
before(:each) { $VERBOSE = true }
|
29
27
|
|
30
28
|
it 'prints to STDERR and returns the block result' do
|
31
|
-
$stderr.
|
32
|
-
Lib.check_error { |status| status.write_int(-127); return_value }
|
29
|
+
expect($stderr).to receive(:puts) { |message| expect(message).to match /U_.*_WARNING/ }
|
30
|
+
error_check = Lib.check_error { |status| status.write_int(-127); return_value }
|
31
|
+
expect(error_check).to eq(return_value)
|
33
32
|
end
|
34
33
|
end
|
35
34
|
|
@@ -37,8 +36,9 @@ module ICU
|
|
37
36
|
before(:each) { $VERBOSE = false }
|
38
37
|
|
39
38
|
it 'returns the block result' do
|
40
|
-
$stderr.
|
41
|
-
Lib.check_error { |status| status.write_int(-127); return_value }
|
39
|
+
expect($stderr).to_not receive(:puts)
|
40
|
+
error_check = Lib.check_error { |status| status.write_int(-127); return_value }
|
41
|
+
expect(error_check).to eq(return_value)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -49,15 +49,15 @@ module ICU
|
|
49
49
|
subject { Lib.cldr_version }
|
50
50
|
|
51
51
|
it { should be_a Lib::VersionInfo }
|
52
|
-
it('is populated') { subject.to_a.
|
52
|
+
it('is populated') { expect(subject.to_a).to_not eq([0,0,0,0]) }
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
56
|
describe 'ICU version' do
|
57
57
|
subject { Lib.version }
|
58
58
|
|
59
|
-
it {
|
60
|
-
it('is populated') { subject.to_a.
|
59
|
+
it { is_expected.to be_a Lib::VersionInfo }
|
60
|
+
it('is populated') { expect(subject.to_a).to_not eq([0,0,0,0]) }
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
data/spec/locale_spec.rb
CHANGED
@@ -1,31 +1,38 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
module ICU
|
6
4
|
describe Locale do
|
7
5
|
describe 'the available locales' do
|
8
6
|
subject { Locale.available }
|
9
7
|
|
10
|
-
it {
|
11
|
-
it {
|
12
|
-
|
8
|
+
it { is_expected.to be_an Array }
|
9
|
+
it { is_expected.to_not be_empty }
|
10
|
+
|
11
|
+
it 'should be an array of available Locales' do
|
12
|
+
expect(subject.first).to be_a(Locale)
|
13
|
+
end
|
13
14
|
end
|
14
15
|
|
15
16
|
describe 'the available ISO 639 country codes' do
|
16
17
|
subject { Locale.iso_countries }
|
17
18
|
|
18
|
-
it {
|
19
|
-
it {
|
20
|
-
|
19
|
+
it { is_expected.to be_an Array }
|
20
|
+
it { is_expected.to_not be_empty }
|
21
|
+
|
22
|
+
it 'should be an array of Strings' do
|
23
|
+
expect(subject.first).to be_a(String)
|
24
|
+
end
|
21
25
|
end
|
22
26
|
|
23
27
|
describe 'the available ISO 639 language codes' do
|
24
28
|
subject { Locale.iso_languages }
|
25
29
|
|
26
|
-
it {
|
27
|
-
it {
|
28
|
-
|
30
|
+
it { is_expected.to be_an Array }
|
31
|
+
it { is_expected.to_not be_empty }
|
32
|
+
|
33
|
+
it 'should be an array of Strings' do
|
34
|
+
expect(subject.first).to be_a(String)
|
35
|
+
end
|
29
36
|
end
|
30
37
|
|
31
38
|
describe 'the default' do
|
@@ -37,44 +44,49 @@ module ICU
|
|
37
44
|
locales.respond_to?(:sample) ? locales.sample : locales.choice
|
38
45
|
end
|
39
46
|
|
40
|
-
it {
|
47
|
+
it { is_expected.to be_a Locale }
|
41
48
|
|
42
49
|
it 'can be assigned using Locale' do
|
43
|
-
(Locale.default = locale).
|
44
|
-
Locale.default.
|
50
|
+
expect(Locale.default = locale).to eq(locale)
|
51
|
+
expect(Locale.default).to eq(locale)
|
45
52
|
end
|
46
53
|
|
47
54
|
it 'can be assigned using string' do
|
48
55
|
string = locale.to_s
|
49
56
|
|
50
|
-
(Locale.default = string).
|
51
|
-
Locale.default.
|
57
|
+
expect(Locale.default = string).to eq(string)
|
58
|
+
expect(Locale.default).to eq(Locale.new(string))
|
52
59
|
end
|
53
60
|
|
54
61
|
it 'can be assigned using symbol' do
|
55
62
|
symbol = locale.to_s.to_sym
|
56
63
|
|
57
|
-
(Locale.default = symbol).
|
58
|
-
Locale.default.
|
64
|
+
expect(Locale.default = symbol).to eq(symbol)
|
65
|
+
expect(Locale.default).to eq(Locale.new(symbol))
|
59
66
|
end
|
60
67
|
end
|
61
68
|
|
62
69
|
if Gem::Version.new('4.2') <= Gem::Version.new(Lib.version)
|
63
70
|
describe 'BCP 47 language tags' do
|
64
71
|
it 'converts a language tag to a locale' do
|
65
|
-
Locale.for_language_tag('en-us').
|
66
|
-
Locale.for_language_tag('nan-Hant-tw').
|
72
|
+
expect(Locale.for_language_tag('en-us')).to eq(Locale.new('en_US'))
|
73
|
+
expect(Locale.for_language_tag('nan-Hant-tw')).to eq(Locale.new('nan_Hant_TW'))
|
67
74
|
end
|
68
75
|
|
69
76
|
it 'returns a language tag for a locale' do
|
70
77
|
if Gem::Version.new('4.4') <= Gem::Version.new(Lib.version)
|
71
|
-
Locale.new('en_US').to_language_tag.
|
72
|
-
Locale.new('zh_TW').to_language_tag.
|
73
|
-
|
78
|
+
expect(Locale.new('en_US').to_language_tag).to eq('en-US')
|
79
|
+
expect(Locale.new('zh_TW').to_language_tag).to eq('zh-TW')
|
80
|
+
# Support for this "magic" transform was dropped with https://unicode-org.atlassian.net/browse/ICU-20187, so don't test it
|
81
|
+
if Gem::Version.new(Lib.version) < Gem::Version.new('64')
|
82
|
+
expect(Locale.new('zh_Hans_CH_PINYIN').to_language_tag).to eq('zh-Hans-CH-u-co-pinyin')
|
83
|
+
else
|
84
|
+
expect(Locale.new('zh_Hans_CH@collation=pinyin').to_language_tag).to eq('zh-Hans-CH-u-co-pinyin')
|
85
|
+
end
|
74
86
|
else
|
75
|
-
Locale.new('en_US').to_language_tag.
|
76
|
-
Locale.new('zh_TW').to_language_tag.
|
77
|
-
Locale.new('zh_Hans_CH_PINYIN').to_language_tag.
|
87
|
+
expect(Locale.new('en_US').to_language_tag).to eq('en-us')
|
88
|
+
expect(Locale.new('zh_TW').to_language_tag).to eq('zh-tw')
|
89
|
+
expect(Locale.new('zh_Hans_CH_PINYIN').to_language_tag).to eq('zh-hans-ch-u-co-pinyin')
|
78
90
|
end
|
79
91
|
end
|
80
92
|
end
|
@@ -82,13 +94,13 @@ module ICU
|
|
82
94
|
|
83
95
|
describe 'Win32 locale IDs' do
|
84
96
|
it 'converts an LCID to a locale' do
|
85
|
-
Locale.for_lcid(1033).
|
86
|
-
Locale.for_lcid(1036).
|
97
|
+
expect(Locale.for_lcid(1033)).to eq(Locale.new('en_US'))
|
98
|
+
expect(Locale.for_lcid(1036)).to eq(Locale.new('fr_FR'))
|
87
99
|
end
|
88
100
|
|
89
101
|
it 'returns an LCID for a locale' do
|
90
|
-
Locale.new('en_US').lcid.
|
91
|
-
Locale.new('es_US').lcid.
|
102
|
+
expect(Locale.new('en_US').lcid).to eq(1033)
|
103
|
+
expect(Locale.new('es_US').lcid).to eq(21514)
|
92
104
|
end
|
93
105
|
end
|
94
106
|
|
@@ -97,39 +109,39 @@ module ICU
|
|
97
109
|
|
98
110
|
context 'in a specific locale' do
|
99
111
|
it 'returns the country' do
|
100
|
-
Locale.new('de_DE').display_country('en').
|
101
|
-
Locale.new('en_US').display_country('fr').
|
112
|
+
expect(Locale.new('de_DE').display_country('en')).to eq('Germany')
|
113
|
+
expect(Locale.new('en_US').display_country('fr')).to eq('États-Unis')
|
102
114
|
end
|
103
115
|
|
104
116
|
it 'returns the language' do
|
105
|
-
Locale.new('fr_FR').display_language('de').
|
106
|
-
Locale.new('zh_CH').display_language('en').
|
117
|
+
expect(Locale.new('fr_FR').display_language('de')).to eq('Französisch')
|
118
|
+
expect(Locale.new('zh_CH').display_language('en')).to eq('Chinese')
|
107
119
|
end
|
108
120
|
|
109
121
|
it 'returns the name' do
|
110
|
-
Locale.new('en_US').display_name('de').
|
111
|
-
Locale.new('zh_CH').display_name('fr').
|
122
|
+
expect(Locale.new('en_US').display_name('de')).to eq('Englisch (Vereinigte Staaten)')
|
123
|
+
expect(Locale.new('zh_CH').display_name('fr')).to eq('chinois (Suisse)')
|
112
124
|
end
|
113
125
|
|
114
126
|
it 'returns the script' do
|
115
|
-
Locale.new('ja_Hira_JP').display_script('en').
|
116
|
-
Locale.new('ja_Hira_JP').display_script('ru').
|
127
|
+
expect(Locale.new('ja_Hira_JP').display_script('en')).to eq('Hiragana')
|
128
|
+
expect(Locale.new('ja_Hira_JP').display_script('ru')).to eq('хирагана')
|
117
129
|
end
|
118
130
|
|
119
131
|
it 'returns the variant' do
|
120
|
-
Locale.new('be_BY_TARASK').display_variant('de').
|
121
|
-
Locale.new('zh_CH_POSIX').display_variant('en').
|
132
|
+
expect(Locale.new('be_BY_TARASK').display_variant('de')).to eq('Taraskievica-Orthographie')
|
133
|
+
expect(Locale.new('zh_CH_POSIX').display_variant('en')).to eq('Computer')
|
122
134
|
end
|
123
135
|
|
124
136
|
# If memory set for 'read_uchar_buffer' is set too low it will throw an out
|
125
137
|
# of bounds memory error, which results in a Segmentation fault error.
|
126
138
|
it 'insures memory sizes is set correctly' do
|
127
139
|
# Currently, testing the longest known locales. May need to be update in the future.
|
128
|
-
Locale.new('en_VI').display_country('ccp').
|
129
|
-
Locale.new('yue_Hant').display_language('ccp').
|
130
|
-
Locale.new('en_VI').display_name('ccp').
|
131
|
-
Locale.new('yue_Hant').display_script('ccp').
|
132
|
-
Locale.new('en_US_POSIX').display_variant('sl').
|
140
|
+
expect(Locale.new('en_VI').display_country('ccp')).to_not be_nil
|
141
|
+
expect(Locale.new('yue_Hant').display_language('ccp')).to_not be_nil
|
142
|
+
expect(Locale.new('en_VI').display_name('ccp')).to_not be_nil
|
143
|
+
expect(Locale.new('yue_Hant').display_script('ccp')).to_not be_nil
|
144
|
+
expect(Locale.new('en_US_POSIX').display_variant('sl')).to_not be_nil
|
133
145
|
end
|
134
146
|
end
|
135
147
|
|
@@ -137,23 +149,23 @@ module ICU
|
|
137
149
|
let(:locale) { Locale.new('de_DE') }
|
138
150
|
|
139
151
|
it 'returns the country' do
|
140
|
-
locale.display_country.
|
152
|
+
expect(locale.display_country).to eq(locale.display_country(Locale.default))
|
141
153
|
end
|
142
154
|
|
143
155
|
it 'returns the language' do
|
144
|
-
locale.display_language.
|
156
|
+
expect(locale.display_language).to eq(locale.display_language(Locale.default))
|
145
157
|
end
|
146
158
|
|
147
159
|
it 'returns the name' do
|
148
|
-
locale.display_name.
|
160
|
+
expect(locale.display_name).to eq(locale.display_name(Locale.default))
|
149
161
|
end
|
150
162
|
|
151
163
|
it 'returns the script' do
|
152
|
-
locale.display_script.
|
164
|
+
expect(locale.display_script).to eq(locale.display_script(Locale.default))
|
153
165
|
end
|
154
166
|
|
155
167
|
it 'returns the variant' do
|
156
|
-
locale.display_variant.
|
168
|
+
expect(locale.display_variant).to eq(locale.display_variant(Locale.default))
|
157
169
|
end
|
158
170
|
end
|
159
171
|
end
|
@@ -161,26 +173,26 @@ module ICU
|
|
161
173
|
describe 'formatting' do
|
162
174
|
let(:locale) { Locale.new('de-de.utf8@collation = phonebook') }
|
163
175
|
|
164
|
-
it('is formatted') { locale.name.
|
165
|
-
it('is formatted without keywords') { locale.base_name.
|
166
|
-
it('is formatted for ICU') { locale.canonical.
|
176
|
+
it('is formatted') { expect(locale.name).to eq('de_DE.utf8@collation=phonebook') }
|
177
|
+
it('is formatted without keywords') { expect(locale.base_name).to eq('de_DE.utf8') }
|
178
|
+
it('is formatted for ICU') { expect(locale.canonical).to eq('de_DE@collation=phonebook') }
|
167
179
|
end
|
168
180
|
|
169
181
|
it 'truncates a properly formatted locale, returning the "parent"' do
|
170
|
-
Locale.new('es-mx').parent.
|
171
|
-
Locale.new('es_MX').parent.
|
172
|
-
Locale.new('zh_Hans_CH_PINYIN').parent.
|
182
|
+
expect(Locale.new('es-mx').parent).to eq('')
|
183
|
+
expect(Locale.new('es_MX').parent).to eq('es')
|
184
|
+
expect(Locale.new('zh_Hans_CH_PINYIN').parent).to eq('zh_Hans_CH')
|
173
185
|
end
|
174
186
|
|
175
187
|
describe 'ISO codes' do
|
176
188
|
it 'returns the ISO 3166 alpha-3 country code' do
|
177
|
-
Locale.new('en_US').iso_country.
|
178
|
-
Locale.new('zh_CN').iso_country.
|
189
|
+
expect(Locale.new('en_US').iso_country).to eq('USA')
|
190
|
+
expect(Locale.new('zh_CN').iso_country).to eq('CHN')
|
179
191
|
end
|
180
192
|
|
181
193
|
it 'returns the ISO 639 three-letter language code' do
|
182
|
-
Locale.new('en_US').iso_language.
|
183
|
-
Locale.new('zh_CN').iso_language.
|
194
|
+
expect(Locale.new('en_US').iso_language).to eq('eng')
|
195
|
+
expect(Locale.new('zh_CN').iso_language).to eq('zho')
|
184
196
|
end
|
185
197
|
end
|
186
198
|
|
@@ -197,64 +209,64 @@ module ICU
|
|
197
209
|
let(:locale) { Locale.new('de_DE@currency=EUR') }
|
198
210
|
|
199
211
|
it 'returns the list of keywords' do
|
200
|
-
locale.keywords.
|
212
|
+
expect(locale.keywords).to eq(['currency'])
|
201
213
|
end
|
202
214
|
end
|
203
215
|
|
204
216
|
it 'can be read' do
|
205
|
-
Locale.new('en_US@calendar=chinese').keyword('calendar').
|
206
|
-
Locale.new('en_US@calendar=chinese').keyword(:calendar).
|
207
|
-
Locale.new('en_US@some=thing').keyword('missing').
|
217
|
+
expect(Locale.new('en_US@calendar=chinese').keyword('calendar')).to eq('chinese')
|
218
|
+
expect(Locale.new('en_US@calendar=chinese').keyword(:calendar)).to eq('chinese')
|
219
|
+
expect(Locale.new('en_US@some=thing').keyword('missing')).to eq('')
|
208
220
|
end
|
209
221
|
|
210
222
|
it 'can be added' do
|
211
|
-
Locale.new('de_DE').with_keyword('currency', 'EUR').
|
212
|
-
Locale.new('de_DE').with_keyword(:currency, :EUR).
|
223
|
+
expect(Locale.new('de_DE').with_keyword('currency', 'EUR')).to eq(Locale.new('de_DE@currency=EUR'))
|
224
|
+
expect(Locale.new('de_DE').with_keyword(:currency, :EUR)).to eq(Locale.new('de_DE@currency=EUR'))
|
213
225
|
end
|
214
226
|
|
215
227
|
it 'can be added using hash' do
|
216
|
-
Locale.new('fr').with_keywords(:a => :b, :c => :d).
|
228
|
+
expect(Locale.new('fr').with_keywords(:a => :b, :c => :d)).to eq(Locale.new('fr@a=b;c=d'))
|
217
229
|
end
|
218
230
|
|
219
231
|
it 'can be removed' do
|
220
|
-
Locale.new('en_US@some=thing').with_keyword(:some, nil).
|
221
|
-
Locale.new('en_US@some=thing').with_keyword(:some, '').
|
232
|
+
expect(Locale.new('en_US@some=thing').with_keyword(:some, nil)).to eq(Locale.new('en_US'))
|
233
|
+
expect(Locale.new('en_US@some=thing').with_keyword(:some, '')).to eq(Locale.new('en_US'))
|
222
234
|
end
|
223
235
|
end
|
224
236
|
|
225
237
|
describe 'orientation' do
|
226
238
|
it 'returns the character orientation' do
|
227
|
-
Locale.new('ar').character_orientation.
|
228
|
-
Locale.new('en').character_orientation.
|
229
|
-
Locale.new('fa').character_orientation.
|
239
|
+
expect(Locale.new('ar').character_orientation).to eq(:rtl)
|
240
|
+
expect(Locale.new('en').character_orientation).to eq(:ltr)
|
241
|
+
expect(Locale.new('fa').character_orientation).to eq(:rtl)
|
230
242
|
end
|
231
243
|
|
232
244
|
it 'returns the line orientation' do
|
233
|
-
Locale.new('ar').line_orientation.
|
234
|
-
Locale.new('en').line_orientation.
|
235
|
-
Locale.new('fa').line_orientation.
|
245
|
+
expect(Locale.new('ar').line_orientation).to eq(:ttb)
|
246
|
+
expect(Locale.new('en').line_orientation).to eq(:ttb)
|
247
|
+
expect(Locale.new('fa').line_orientation).to eq(:ttb)
|
236
248
|
end
|
237
249
|
end
|
238
250
|
|
239
251
|
describe 'subtags' do
|
240
252
|
let(:locale) { Locale.new('zh-hans-ch-pinyin') }
|
241
253
|
|
242
|
-
it('returns the country code') { locale.country.
|
243
|
-
it('returns the language code') { locale.language.
|
244
|
-
it('returns the script code') { locale.script.
|
245
|
-
it('returns the variant code') { locale.variant.
|
254
|
+
it('returns the country code') { expect(locale.country).to eq('CH') }
|
255
|
+
it('returns the language code') { expect(locale.language).to eq('zh') }
|
256
|
+
it('returns the script code') { expect(locale.script).to eq('Hans') }
|
257
|
+
it('returns the variant code') { expect(locale.variant).to eq('PINYIN') }
|
246
258
|
|
247
259
|
describe 'likely subtags according to UTS #35' do
|
248
260
|
it 'adds likely subtags' do
|
249
|
-
Locale.new('en').with_likely_subtags.
|
250
|
-
Locale.new('sr').with_likely_subtags.
|
251
|
-
Locale.new('zh_TW').with_likely_subtags.
|
261
|
+
expect(Locale.new('en').with_likely_subtags).to eq(Locale.new('en_Latn_US'))
|
262
|
+
expect(Locale.new('sr').with_likely_subtags).to eq(Locale.new('sr_Cyrl_RS'))
|
263
|
+
expect(Locale.new('zh_TW').with_likely_subtags).to eq(Locale.new('zh_Hant_TW'))
|
252
264
|
end
|
253
265
|
|
254
266
|
it 'removes likely subtags' do
|
255
|
-
Locale.new('en_US').with_minimized_subtags.
|
256
|
-
Locale.new('sr_RS').with_minimized_subtags.
|
257
|
-
Locale.new('zh_Hant_TW').with_minimized_subtags.
|
267
|
+
expect(Locale.new('en_US').with_minimized_subtags).to eq(Locale.new('en'))
|
268
|
+
expect(Locale.new('sr_RS').with_minimized_subtags).to eq(Locale.new('sr'))
|
269
|
+
expect(Locale.new('zh_Hant_TW').with_minimized_subtags).to eq(Locale.new('zh_TW'))
|
258
270
|
end
|
259
271
|
end
|
260
272
|
end
|