ffi-icu 0.1.10 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
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,41 +94,54 @@ 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
 
95
107
  describe 'display' do
108
+ let(:locale_ids) { Locale.available.map(&:id) }
109
+
96
110
  context 'in a specific locale' do
97
111
  it 'returns the country' do
98
- Locale.new('de_DE').display_country('en').should == 'Germany'
99
- 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')
100
114
  end
101
115
 
102
116
  it 'returns the language' do
103
- Locale.new('fr_FR').display_language('de').should == 'Französisch'
104
- 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')
105
119
  end
106
120
 
107
121
  it 'returns the name' do
108
- Locale.new('en_US').display_name('de').should == 'Englisch (Vereinigte Staaten)'
109
- 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)')
110
124
  end
111
125
 
112
126
  it 'returns the script' do
113
- Locale.new('ja_Hira_JP').display_script('en').should == 'Hiragana'
114
- 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('хирагана')
115
129
  end
116
130
 
117
131
  it 'returns the variant' do
118
- Locale.new('be_BY_TARASK').display_variant('de').should == 'Taraskievica-Orthographie'
119
- 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')
134
+ end
135
+
136
+ # If memory set for 'read_uchar_buffer' is set too low it will throw an out
137
+ # of bounds memory error, which results in a Segmentation fault error.
138
+ it 'insures memory sizes is set correctly' do
139
+ # Currently, testing the longest known locales. May need to be update in the future.
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
120
145
  end
121
146
  end
122
147
 
@@ -124,23 +149,23 @@ module ICU
124
149
  let(:locale) { Locale.new('de_DE') }
125
150
 
126
151
  it 'returns the country' do
127
- locale.display_country.should == locale.display_country(Locale.default)
152
+ expect(locale.display_country).to eq(locale.display_country(Locale.default))
128
153
  end
129
154
 
130
155
  it 'returns the language' do
131
- locale.display_language.should == locale.display_language(Locale.default)
156
+ expect(locale.display_language).to eq(locale.display_language(Locale.default))
132
157
  end
133
158
 
134
159
  it 'returns the name' do
135
- locale.display_name.should == locale.display_name(Locale.default)
160
+ expect(locale.display_name).to eq(locale.display_name(Locale.default))
136
161
  end
137
162
 
138
163
  it 'returns the script' do
139
- locale.display_script.should == locale.display_script(Locale.default)
164
+ expect(locale.display_script).to eq(locale.display_script(Locale.default))
140
165
  end
141
166
 
142
167
  it 'returns the variant' do
143
- locale.display_variant.should == locale.display_variant(Locale.default)
168
+ expect(locale.display_variant).to eq(locale.display_variant(Locale.default))
144
169
  end
145
170
  end
146
171
  end
@@ -148,26 +173,26 @@ module ICU
148
173
  describe 'formatting' do
149
174
  let(:locale) { Locale.new('de-de.utf8@collation = phonebook') }
150
175
 
151
- it('is formatted') { locale.name.should == 'de_DE.utf8@collation=phonebook' }
152
- it('is formatted without keywords') { locale.base_name.should == 'de_DE.utf8' }
153
- 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') }
154
179
  end
155
180
 
156
181
  it 'truncates a properly formatted locale, returning the "parent"' do
157
- Locale.new('es-mx').parent.should == ''
158
- Locale.new('es_MX').parent.should == 'es'
159
- 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')
160
185
  end
161
186
 
162
187
  describe 'ISO codes' do
163
188
  it 'returns the ISO 3166 alpha-3 country code' do
164
- Locale.new('en_US').iso_country.should == 'USA'
165
- 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')
166
191
  end
167
192
 
168
193
  it 'returns the ISO 639 three-letter language code' do
169
- Locale.new('en_US').iso_language.should == 'eng'
170
- 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')
171
196
  end
172
197
  end
173
198
 
@@ -184,64 +209,64 @@ module ICU
184
209
  let(:locale) { Locale.new('de_DE@currency=EUR') }
185
210
 
186
211
  it 'returns the list of keywords' do
187
- locale.keywords.should == ['currency']
212
+ expect(locale.keywords).to eq(['currency'])
188
213
  end
189
214
  end
190
215
 
191
216
  it 'can be read' do
192
- Locale.new('en_US@calendar=chinese').keyword('calendar').should == 'chinese'
193
- Locale.new('en_US@calendar=chinese').keyword(:calendar).should == 'chinese'
194
- 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('')
195
220
  end
196
221
 
197
222
  it 'can be added' do
198
- Locale.new('de_DE').with_keyword('currency', 'EUR').should == Locale.new('de_DE@currency=EUR')
199
- 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'))
200
225
  end
201
226
 
202
227
  it 'can be added using hash' do
203
- 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'))
204
229
  end
205
230
 
206
231
  it 'can be removed' do
207
- Locale.new('en_US@some=thing').with_keyword(:some, nil).should == Locale.new('en_US')
208
- 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'))
209
234
  end
210
235
  end
211
236
 
212
237
  describe 'orientation' do
213
238
  it 'returns the character orientation' do
214
- Locale.new('ar').character_orientation.should == :rtl
215
- Locale.new('en').character_orientation.should == :ltr
216
- 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)
217
242
  end
218
243
 
219
244
  it 'returns the line orientation' do
220
- Locale.new('ar').line_orientation.should == :ttb
221
- Locale.new('en').line_orientation.should == :ttb
222
- 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)
223
248
  end
224
249
  end
225
250
 
226
251
  describe 'subtags' do
227
252
  let(:locale) { Locale.new('zh-hans-ch-pinyin') }
228
253
 
229
- it('returns the country code') { locale.country.should == 'CH' }
230
- it('returns the language code') { locale.language.should == 'zh' }
231
- it('returns the script code') { locale.script.should == 'Hans' }
232
- 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') }
233
258
 
234
259
  describe 'likely subtags according to UTS #35' do
235
260
  it 'adds likely subtags' do
236
- Locale.new('en').with_likely_subtags.should == Locale.new('en_Latn_US')
237
- Locale.new('sr').with_likely_subtags.should == Locale.new('sr_Cyrl_RS')
238
- 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'))
239
264
  end
240
265
 
241
266
  it 'removes likely subtags' do
242
- Locale.new('en_US').with_minimized_subtags.should == Locale.new('en')
243
- Locale.new('sr_RS').with_minimized_subtags.should == Locale.new('sr')
244
- 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'))
245
270
  end
246
271
  end
247
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,68 +1,71 @@
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