ffi-icu 0.2.0 → 0.4.1

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.
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 { should be_an Array }
11
- it { should_not be_empty }
12
- its(:first) { should be_a Locale }
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 { should be_an Array }
19
- it { should_not be_empty }
20
- its(:first) { should be_a String }
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 { should be_an Array }
27
- it { should_not be_empty }
28
- its(:first) { should be_a String }
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 { should be_a Locale }
47
+ it { is_expected.to be_a Locale }
41
48
 
42
49
  it 'can be assigned using Locale' do
43
- (Locale.default = locale).should == locale
44
- Locale.default.should == locale
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).should == string
51
- Locale.default.should == Locale.new(string)
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).should == symbol
58
- Locale.default.should == Locale.new(symbol)
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').should == Locale.new('en_US')
66
- Locale.for_language_tag('nan-Hant-tw').should == Locale.new('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.should == 'en-US'
72
- Locale.new('zh_TW').to_language_tag.should == 'zh-TW'
73
- Locale.new('zh_Hans_CH_PINYIN').to_language_tag.should == 'zh-Hans-CH-u-co-pinyin'
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.should == 'en-us'
76
- Locale.new('zh_TW').to_language_tag.should == 'zh-tw'
77
- Locale.new('zh_Hans_CH_PINYIN').to_language_tag.should == 'zh-hans-ch-u-co-pinyin'
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).should == Locale.new('en_US')
86
- Locale.for_lcid(1036).should == Locale.new('fr_FR')
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.should == 1033
91
- Locale.new('es_US').lcid.should == 21514
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').should == 'Germany'
101
- Locale.new('en_US').display_country('fr').should == 'États-Unis'
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').should == 'Französisch'
106
- Locale.new('zh_CH').display_language('en').should == 'Chinese'
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').should == 'Englisch (Vereinigte Staaten)'
111
- Locale.new('zh_CH').display_name('fr').should == 'chinois (Suisse)'
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').should == 'Hiragana'
116
- Locale.new('ja_Hira_JP').display_script('ru').should == 'хирагана'
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').should == 'Taraskievica-Orthographie'
121
- Locale.new('zh_CH_POSIX').display_variant('en').should == 'Computer'
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').should_not be_nil
129
- Locale.new('yue_Hant').display_language('ccp').should_not be_nil
130
- Locale.new('en_VI').display_name('ccp').should_not be_nil
131
- Locale.new('yue_Hant').display_script('ccp').should_not be_nil
132
- Locale.new('en_US_POSIX').display_variant('sl').should_not be_nil
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.should == locale.display_country(Locale.default)
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.should == locale.display_language(Locale.default)
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.should == locale.display_name(Locale.default)
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.should == locale.display_script(Locale.default)
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.should == locale.display_variant(Locale.default)
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.should == 'de_DE.utf8@collation=phonebook' }
165
- it('is formatted without keywords') { locale.base_name.should == 'de_DE.utf8' }
166
- it('is formatted for ICU') { locale.canonical.should == 'de_DE@collation=phonebook' }
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.should == ''
171
- Locale.new('es_MX').parent.should == 'es'
172
- Locale.new('zh_Hans_CH_PINYIN').parent.should == 'zh_Hans_CH'
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.should == 'USA'
178
- Locale.new('zh_CN').iso_country.should == 'CHN'
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.should == 'eng'
183
- Locale.new('zh_CN').iso_language.should == 'zho'
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.should == ['currency']
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').should == 'chinese'
206
- Locale.new('en_US@calendar=chinese').keyword(:calendar).should == 'chinese'
207
- Locale.new('en_US@some=thing').keyword('missing').should == ''
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').should == Locale.new('de_DE@currency=EUR')
212
- Locale.new('de_DE').with_keyword(:currency, :EUR).should == Locale.new('de_DE@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).should == Locale.new('fr@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).should == Locale.new('en_US')
221
- Locale.new('en_US@some=thing').with_keyword(:some, '').should == Locale.new('en_US')
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.should == :rtl
228
- Locale.new('en').character_orientation.should == :ltr
229
- Locale.new('fa').character_orientation.should == :rtl
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.should == :ttb
234
- Locale.new('en').line_orientation.should == :ttb
235
- Locale.new('fa').line_orientation.should == :ttb
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.should == 'CH' }
243
- it('returns the language code') { locale.language.should == 'zh' }
244
- it('returns the script code') { locale.script.should == 'Hans' }
245
- it('returns the variant code') { locale.variant.should == 'PINYIN' }
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.should == Locale.new('en_Latn_US')
250
- Locale.new('sr').with_likely_subtags.should == Locale.new('sr_Cyrl_RS')
251
- Locale.new('zh_TW').with_likely_subtags.should == Locale.new('zh_Hant_TW')
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.should == Locale.new('en')
256
- Locale.new('sr_RS').with_minimized_subtags.should == Locale.new('sr')
257
- Locale.new('zh_Hant_TW').with_minimized_subtags.should == Locale.new('zh_TW')
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
@@ -1,7 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'spec_helper'
4
-
5
3
  module ICU
6
4
  module Normalization
7
5
  # http://bugs.icu-project.org/trac/browser/icu/trunk/source/test/cintltst/cnormtst.c
@@ -9,11 +7,11 @@ module ICU
9
7
  describe "Normalization" do
10
8
 
11
9
  it "should normalize a string - decomposed" do
12
- ICU::Normalization.normalize("Å", :nfd).unpack("U*").should == [65, 778]
10
+ expect(ICU::Normalization.normalize("Å", :nfd).unpack("U*")).to eq([65, 778])
13
11
  end
14
12
 
15
13
  it "should normalize a string - composed" do
16
- ICU::Normalization.normalize("Å", :nfc).unpack("U*").should == [197]
14
+ expect(ICU::Normalization.normalize("Å", :nfc).unpack("U*")).to eq([197])
17
15
  end
18
16
 
19
17
  # TODO: add more normalization tests
@@ -1,21 +1,19 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'spec_helper'
4
-
5
3
  module ICU
6
4
  describe Normalizer do
7
5
  describe 'NFD: nfc decompose' do
8
6
  let(:normalizer) { ICU::Normalizer.new(nil, 'nfc', :decompose) }
9
7
 
10
8
  it "should normalize a string" do
11
- normalizer.normalize("Å").unpack("U*").should == [65, 778]
12
- normalizer.normalize("ô").unpack("U*").should == [111, 770]
13
- normalizer.normalize("a").unpack("U*").should == [97]
14
- normalizer.normalize("中文").unpack("U*").should == [20013, 25991]
15
- normalizer.normalize("Äffin").unpack("U*").should == [65, 776, 102, 102, 105, 110]
16
- normalizer.normalize("Äffin").unpack("U*").should == [65, 776, 64259, 110]
17
- normalizer.normalize("Henry IV").unpack("U*").should == [72, 101, 110, 114, 121, 32, 73, 86]
18
- normalizer.normalize("Henry Ⅳ").unpack("U*").should == [72, 101, 110, 114, 121, 32, 8547]
9
+ expect(normalizer.normalize("Å").unpack("U*")).to eq([65, 778])
10
+ expect(normalizer.normalize("ô").unpack("U*")).to eq([111, 770])
11
+ expect(normalizer.normalize("a").unpack("U*")).to eq([97])
12
+ expect(normalizer.normalize("中文").unpack("U*")).to eq([20013, 25991])
13
+ expect(normalizer.normalize("Äffin").unpack("U*")).to eq([65, 776, 102, 102, 105, 110])
14
+ expect(normalizer.normalize("Äffin").unpack("U*")).to eq([65, 776, 64259, 110])
15
+ expect(normalizer.normalize("Henry IV").unpack("U*")).to eq([72, 101, 110, 114, 121, 32, 73, 86])
16
+ expect(normalizer.normalize("Henry Ⅳ").unpack("U*")).to eq([72, 101, 110, 114, 121, 32, 8547])
19
17
  end
20
18
  end
21
19
 
@@ -23,14 +21,14 @@ module ICU
23
21
  let(:normalizer) { ICU::Normalizer.new(nil, 'nfc', :compose) }
24
22
 
25
23
  it "should normalize a string" do
26
- normalizer.normalize("Å").unpack("U*").should == [197]
27
- normalizer.normalize("ô").unpack("U*").should == [244]
28
- normalizer.normalize("a").unpack("U*").should == [97]
29
- normalizer.normalize("中文").unpack("U*").should == [20013, 25991]
30
- normalizer.normalize("Äffin").unpack("U*").should == [196, 102, 102, 105, 110]
31
- normalizer.normalize("Äffin").unpack("U*").should == [196, 64259, 110]
32
- normalizer.normalize("Henry IV").unpack("U*").should == [72, 101, 110, 114, 121, 32, 73, 86]
33
- normalizer.normalize("Henry Ⅳ").unpack("U*").should == [72, 101, 110, 114, 121, 32, 8547]
24
+ expect(normalizer.normalize("Å").unpack("U*")).to eq([197])
25
+ expect(normalizer.normalize("ô").unpack("U*")).to eq([244])
26
+ expect(normalizer.normalize("a").unpack("U*")).to eq([97])
27
+ expect(normalizer.normalize("中文").unpack("U*")).to eq([20013, 25991])
28
+ expect(normalizer.normalize("Äffin").unpack("U*")).to eq([196, 102, 102, 105, 110])
29
+ expect(normalizer.normalize("Äffin").unpack("U*")).to eq([196, 64259, 110])
30
+ expect(normalizer.normalize("Henry IV").unpack("U*")).to eq([72, 101, 110, 114, 121, 32, 73, 86])
31
+ expect(normalizer.normalize("Henry Ⅳ").unpack("U*")).to eq([72, 101, 110, 114, 121, 32, 8547])
34
32
  end
35
33
  end
36
34
 
@@ -38,10 +36,10 @@ module ICU
38
36
  let(:normalizer) { ICU::Normalizer.new(nil, 'nfkc', :decompose) }
39
37
 
40
38
  it "should normalize a string" do
41
- normalizer.normalize("Äffin").unpack("U*").should == [65, 776, 102, 102, 105, 110]
42
- normalizer.normalize("Äffin").unpack("U*").should == [65, 776, 102, 102, 105, 110]
43
- normalizer.normalize("Henry IV").unpack("U*").should == [72, 101, 110, 114, 121, 32, 73, 86]
44
- normalizer.normalize("Henry Ⅳ").unpack("U*").should == [72, 101, 110, 114, 121, 32, 73, 86]
39
+ expect(normalizer.normalize("Äffin").unpack("U*")).to eq([65, 776, 102, 102, 105, 110])
40
+ expect(normalizer.normalize("Äffin").unpack("U*")).to eq([65, 776, 102, 102, 105, 110])
41
+ expect(normalizer.normalize("Henry IV").unpack("U*")).to eq([72, 101, 110, 114, 121, 32, 73, 86])
42
+ expect(normalizer.normalize("Henry Ⅳ").unpack("U*")).to eq([72, 101, 110, 114, 121, 32, 73, 86])
45
43
  end
46
44
  end
47
45
 
@@ -49,10 +47,10 @@ module ICU
49
47
  let(:normalizer) { ICU::Normalizer.new(nil, 'nfkc', :compose) }
50
48
 
51
49
  it "should normalize a string" do
52
- normalizer.normalize("Äffin").unpack("U*").should == [196, 102, 102, 105, 110]
53
- normalizer.normalize("Äffin").unpack("U*").should == [196, 102, 102, 105, 110]
54
- normalizer.normalize("Henry IV").unpack("U*").should == [72, 101, 110, 114, 121, 32, 73, 86]
55
- normalizer.normalize("Henry Ⅳ").unpack("U*").should == [72, 101, 110, 114, 121, 32, 73, 86]
50
+ expect(normalizer.normalize("Äffin").unpack("U*")).to eq([196, 102, 102, 105, 110])
51
+ expect(normalizer.normalize("Äffin").unpack("U*")).to eq([196, 102, 102, 105, 110])
52
+ expect(normalizer.normalize("Henry IV").unpack("U*")).to eq([72, 101, 110, 114, 121, 32, 73, 86])
53
+ expect(normalizer.normalize("Henry Ⅳ").unpack("U*")).to eq([72, 101, 110, 114, 121, 32, 73, 86])
56
54
  end
57
55
  end
58
56
  end # Normalizer
@@ -1,71 +1,79 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'spec_helper'
4
-
5
3
  module ICU
6
4
  module NumberFormatting
7
5
  describe 'NumberFormatting' do
8
6
  it 'should format a simple integer' do
9
- NumberFormatting.format_number("en", 1).should == "1"
10
- NumberFormatting.format_number("en", 1_000).should == "1,000"
11
- NumberFormatting.format_number("de-DE", 1_000_000).should == "1.000.000"
7
+ expect(NumberFormatting.format_number("en", 1)).to eq("1")
8
+ expect(NumberFormatting.format_number("en", 1_000)).to eq("1,000")
9
+ expect(NumberFormatting.format_number("de-DE", 1_000_000)).to eq("1.000.000")
12
10
  end
13
11
 
14
12
  it 'should format a float' do
15
- NumberFormatting.format_number("en", 1.0).should == "1"
16
- NumberFormatting.format_number("en", 1.123).should == "1.123"
17
- NumberFormatting.format_number("en", 1_000.1238).should == "1,000.124"
18
- NumberFormatting.format_number("en", 1_000.1238, max_fraction_digits: 4).should == "1,000.1238"
13
+ expect(NumberFormatting.format_number("en", 1.0)).to eq("1")
14
+ expect(NumberFormatting.format_number("en", 1.123)).to eq("1.123")
15
+ expect(NumberFormatting.format_number("en", 1_000.1238)).to eq("1,000.124")
16
+ expect(NumberFormatting.format_number("en", 1_000.1238, max_fraction_digits: 4)).to eq("1,000.1238")
19
17
  NumberFormatting.set_default_options(fraction_digits: 5)
20
- NumberFormatting.format_number("en", 1_000.1238).should == "1,000.12380"
18
+ expect(NumberFormatting.format_number("en", 1_000.1238)).to eq("1,000.12380")
21
19
  NumberFormatting.clear_default_options
22
20
  end
23
21
 
24
22
  it 'should format a decimal' do
25
- NumberFormatting.format_number("en", BigDecimal.new("10000.123")).should == "10,000.123"
23
+ expect(NumberFormatting.format_number("en", BigDecimal("10000.123"))).to eq("10,000.123")
26
24
  end
27
25
 
28
26
  it 'should format a currency' do
29
- NumberFormatting.format_currency("en", 123.45, 'USD').should == "$123.45"
30
- NumberFormatting.format_currency("en", 123_123.45, 'USD').should == "$123,123.45"
31
- NumberFormatting.format_currency("de-DE", 123_123.45, 'EUR').should == "123.123,45\u{A0}€"
27
+ expect(NumberFormatting.format_currency("en", 123.45, 'USD')).to eq("$123.45")
28
+ expect(NumberFormatting.format_currency("en", 123_123.45, 'USD')).to eq("$123,123.45")
29
+ expect(NumberFormatting.format_currency("de-DE", 123_123.45, 'EUR')).to eq("123.123,45\u{A0}€")
32
30
  end
33
31
 
34
32
  it 'should format a percent' do
35
- NumberFormatting.format_percent("en", 1.1).should == "110%"
36
- NumberFormatting.format_percent("da", 0.15).should == "15\u{A0}%"
37
- NumberFormatting.format_percent("da", -0.1545, max_fraction_digits: 10).should == "-15,45\u{A0}%"
33
+ expect(NumberFormatting.format_percent("en", 1.1)).to eq("110%")
34
+ expect(NumberFormatting.format_percent("da", 0.15)).to eq("15\u{A0}%")
35
+ expect(NumberFormatting.format_percent("da", -0.1545, max_fraction_digits: 10)).to eq("-15,45\u{A0}%")
38
36
  end
39
37
 
40
38
  it 'should spell numbers' do
41
- NumberFormatting.spell("en_US", 1_000).should == 'one thousand'
42
- NumberFormatting.spell("de-DE", 123.456).should == "ein\u{AD}hundert\u{AD}drei\u{AD}und\u{AD}zwanzig Komma vier fünf sechs"
39
+ expect(NumberFormatting.spell("en_US", 1_000)).to eq('one thousand')
40
+ expect(NumberFormatting.spell("de-DE", 123.456)).to eq("ein\u{AD}hundert\u{AD}drei\u{AD}und\u{AD}zwanzig Komma vier fünf sechs")
43
41
  end
44
42
 
45
43
  it 'should be able to re-use number formatter objects' do
46
44
  numf = NumberFormatting.create('fr-CA')
47
- numf.format(1_000).should == "1\u{A0}000"
48
- numf.format(1_000.123).should == "1\u{A0}000,123"
45
+ expect(numf.format(1_000)).to eq("1\u{A0}000")
46
+ expect(numf.format(1_000.123)).to eq("1\u{A0}000,123")
49
47
  end
50
48
 
51
49
  it 'should be able to re-use currency formatter objects' do
52
50
  curf = NumberFormatting.create('en-US', :currency)
53
- curf.format(1_000.12, 'USD').should == "$1,000.12"
51
+ expect(curf.format(1_000.12, 'USD')).to eq("$1,000.12")
54
52
  end
55
53
 
56
54
  it 'should allow for various styles of currency formatting if the version is new enough' do
57
55
  if ICU::Lib.version.to_a.first >= 53
58
56
  curf = NumberFormatting.create('en-US', :currency, style: :iso)
59
- curf.format(1_000.12, 'USD').should == "USD1,000.12"
57
+ expected = if ICU::Lib.version.to_a.first >= 62
58
+ "USD\u00A01,000.12"
59
+ else
60
+ "USD1,000.12"
61
+ end
62
+ expect(curf.format(1_000.12, 'USD')).to eq(expected)
60
63
  curf = NumberFormatting.create('en-US', :currency, style: :plural)
61
- curf.format(1_000.12, 'USD').should == "1,000.12 US dollars"
64
+ expect(curf.format(1_000.12, 'USD')).to eq("1,000.12 US dollars")
62
65
  expect { NumberFormatting.create('en-US', :currency, style: :fake) }.to raise_error(StandardError)
63
66
  else
64
67
  curf = NumberFormatting.create('en-US', :currency, style: :default)
65
- curf.format(1_000.12, 'USD').should == '$1,000.12'
68
+ expect(curf.format(1_000.12, 'USD')).to eq('$1,000.12')
66
69
  expect { NumberFormatting.create('en-US', :currency, style: :iso) }.to raise_error(StandardError)
67
70
  end
68
71
  end
72
+
73
+ it 'should format a bignum' do
74
+ str = NumberFormatting.format_number("en", 1_000_000_000_000_000_000_000_000_000_000_000_000_000)
75
+ expect(str).to eq('1,000,000,000,000,000,000,000,000,000,000,000,000,000')
76
+ end
69
77
  end
70
78
  end # NumberFormatting
71
79
  end # ICU