twitter_cldr 3.0.1 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -2
- data/History.txt +4 -0
- data/README.md +17 -6
- data/lib/twitter_cldr/resources/postal_codes_importer.rb +12 -1
- data/lib/twitter_cldr/resources/regexp_ast_generator.rb +41 -0
- data/lib/twitter_cldr/resources.rb +1 -0
- data/lib/twitter_cldr/shared/postal_code_generator.rb +50 -0
- data/lib/twitter_cldr/shared/postal_codes.rb +48 -9
- data/lib/twitter_cldr/shared.rb +15 -14
- data/lib/twitter_cldr/utils/regexp_ast.rb +115 -0
- data/lib/twitter_cldr/utils/regexp_sampler.rb +149 -0
- data/lib/twitter_cldr/utils.rb +5 -3
- data/lib/twitter_cldr/version.rb +1 -1
- data/resources/shared/postal_codes.yml +1442 -159
- data/spec/bidi/bidi_spec.rb +1 -1
- data/spec/collation/collation_spec.rb +1 -1
- data/spec/collation/collator_spec.rb +31 -31
- data/spec/collation/implicit_collation_elements_spec.rb +6 -6
- data/spec/collation/sort_key_builder_spec.rb +28 -26
- data/spec/collation/tailoring_spec.rb +1 -1
- data/spec/collation/trie_builder_spec.rb +16 -16
- data/spec/collation/trie_dumps_spec.rb +2 -2
- data/spec/collation/trie_loader_spec.rb +8 -8
- data/spec/collation/trie_spec.rb +61 -61
- data/spec/collation/trie_with_fallback_spec.rb +5 -5
- data/spec/core_ext_spec.rb +1 -1
- data/spec/data_readers/additional_date_format_selector_spec.rb +38 -38
- data/spec/data_readers/date_time_data_reader_spec.rb +2 -2
- data/spec/data_readers/number_data_reader_spec.rb +1 -1
- data/spec/formatters/calendars/datetime_formatter_spec.rb +218 -218
- data/spec/formatters/list_formatter_spec.rb +8 -8
- data/spec/formatters/numbers/abbreviated/abbreviated_number_formatter_spec.rb +14 -14
- data/spec/formatters/numbers/abbreviated/long_decimal_formatter_spec.rb +4 -4
- data/spec/formatters/numbers/abbreviated/short_decimal_formatter_spec.rb +4 -4
- data/spec/formatters/numbers/currency_formatter_spec.rb +11 -11
- data/spec/formatters/numbers/decimal_formatter_spec.rb +3 -3
- data/spec/formatters/numbers/helpers/fraction_spec.rb +3 -3
- data/spec/formatters/numbers/helpers/integer_spec.rb +16 -16
- data/spec/formatters/numbers/number_formatter_spec.rb +21 -21
- data/spec/formatters/numbers/percent_formatter_spec.rb +3 -3
- data/spec/formatters/numbers/rbnf/rbnf_spec.rb +2 -2
- data/spec/formatters/plurals/plural_formatter_spec.rb +41 -41
- data/spec/formatters/plurals/rules_spec.rb +13 -13
- data/spec/localized/localized_array_spec.rb +12 -12
- data/spec/localized/localized_date_spec.rb +33 -33
- data/spec/localized/localized_datetime_spec.rb +11 -11
- data/spec/localized/localized_hash_spec.rb +4 -4
- data/spec/localized/localized_number_spec.rb +36 -36
- data/spec/localized/localized_object_spec.rb +8 -8
- data/spec/localized/localized_string_spec.rb +53 -53
- data/spec/localized/localized_symbol_spec.rb +9 -9
- data/spec/localized/localized_time_spec.rb +10 -10
- data/spec/localized/localized_timespan_spec.rb +8 -8
- data/spec/normalization_spec.rb +6 -6
- data/spec/parsers/number_parser_spec.rb +36 -36
- data/spec/parsers/parser_spec.rb +5 -5
- data/spec/parsers/segmentation_parser_spec.rb +19 -19
- data/spec/parsers/symbol_table_spec.rb +4 -4
- data/spec/parsers/unicode_regex/character_class_spec.rb +19 -19
- data/spec/parsers/unicode_regex/character_range_spec.rb +1 -1
- data/spec/parsers/unicode_regex/character_set_spec.rb +8 -8
- data/spec/parsers/unicode_regex/literal_spec.rb +5 -5
- data/spec/parsers/unicode_regex/unicode_string_spec.rb +2 -2
- data/spec/parsers/unicode_regex_parser_spec.rb +28 -28
- data/spec/resources/loader_spec.rb +32 -32
- data/spec/shared/break_iterator_spec.rb +13 -13
- data/spec/shared/calendar_spec.rb +59 -59
- data/spec/shared/casefolder_spec.rb +5 -5
- data/spec/shared/code_point_spec.rb +46 -46
- data/spec/shared/currencies_spec.rb +7 -7
- data/spec/shared/language_codes_spec.rb +34 -34
- data/spec/shared/languages_spec.rb +30 -30
- data/spec/shared/numbering_system_spec.rb +7 -7
- data/spec/shared/numbers_spec.rb +4 -4
- data/spec/shared/phone_codes_spec.rb +7 -7
- data/spec/shared/postal_code_generator_spec.rb +76 -0
- data/spec/shared/postal_codes_spec.rb +35 -29
- data/spec/shared/territories_spec.rb +40 -40
- data/spec/shared/unicode_regex_spec.rb +71 -71
- data/spec/spec_helper.rb +2 -2
- data/spec/tokenizers/calendars/date_tokenizer_spec.rb +1 -1
- data/spec/tokenizers/calendars/timespan_tokenizer_spec.rb +6 -6
- data/spec/tokenizers/composite_token_spec.rb +3 -3
- data/spec/tokenizers/token_spec.rb +3 -3
- data/spec/twitter_cldr_spec.rb +72 -72
- data/spec/utils/code_points_spec.rb +10 -10
- data/spec/utils/interpolation_spec.rb +32 -32
- data/spec/utils/range_set_spec.rb +36 -36
- data/spec/utils/regexp_ast_spec.rb +44 -0
- data/spec/utils/regexp_sampler_spec.rb +182 -0
- data/spec/utils/yaml/yaml_spec.rb +23 -23
- data/spec/utils_spec.rb +19 -19
- metadata +263 -258
@@ -10,13 +10,13 @@ include TwitterCldr::Shared
|
|
10
10
|
describe Casefolder do
|
11
11
|
describe "#casefold" do
|
12
12
|
it "should casefold a few canonical examples" do
|
13
|
-
Casefolder.casefold("Weißrussland").
|
14
|
-
Casefolder.casefold("Hello, World").
|
13
|
+
expect(Casefolder.casefold("Weißrussland")).to eq("weissrussland")
|
14
|
+
expect(Casefolder.casefold("Hello, World")).to eq("hello, world")
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should correctly casefold the Turkic i character" do
|
18
|
-
Casefolder.casefold("Istanbul", true).
|
19
|
-
Casefolder.casefold("İstanbul", true).
|
18
|
+
expect(Casefolder.casefold("Istanbul", true)).to eq("ıstanbul")
|
19
|
+
expect(Casefolder.casefold("İstanbul", true)).to eq("istanbul")
|
20
20
|
end
|
21
21
|
|
22
22
|
# the files used in this test come from the unicode_utils gem
|
@@ -24,7 +24,7 @@ describe Casefolder do
|
|
24
24
|
base_path = File.dirname(__FILE__)
|
25
25
|
text = File.read(File.join(base_path, "casefolding.txt"))
|
26
26
|
expected = File.read(File.join(base_path, "casefolding_expected.txt"))
|
27
|
-
Casefolder.casefold(text).
|
27
|
+
expect(Casefolder.casefold(text)).to eq(expected)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -26,15 +26,15 @@ describe CodePoint do
|
|
26
26
|
let(:decomposition) { '0028 007A 0029' }
|
27
27
|
|
28
28
|
it 'parses decomposition mapping' do
|
29
|
-
code_point.decomposition.
|
29
|
+
expect(code_point.decomposition).to eq([0x28, 0x7A, 0x29])
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'initializes compatibility tag as nil' do
|
33
|
-
code_point.compatibility_decomposition_tag.
|
33
|
+
expect(code_point.compatibility_decomposition_tag).to be_nil
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'returns false from compatibility_decomposition?' do
|
37
|
-
code_point.
|
37
|
+
expect(code_point).not_to be_compatibility_decomposition
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -42,15 +42,15 @@ describe CodePoint do
|
|
42
42
|
let(:decomposition) { '<font> 0028 007A 0029' }
|
43
43
|
|
44
44
|
it 'parses decomposition mapping' do
|
45
|
-
code_point.decomposition.
|
45
|
+
expect(code_point.decomposition).to eq([0x28, 0x7A, 0x29])
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'initializes compatibility decomposition tag' do
|
49
|
-
code_point.compatibility_decomposition_tag.
|
49
|
+
expect(code_point.compatibility_decomposition_tag).to eq('font')
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'returns true from compatibility_decomposition?' do
|
53
|
-
code_point.
|
53
|
+
expect(code_point).to be_compatibility_decomposition
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -58,15 +58,15 @@ describe CodePoint do
|
|
58
58
|
let(:decomposition) { '' }
|
59
59
|
|
60
60
|
it 'parses decomposition mapping' do
|
61
|
-
code_point.decomposition.
|
61
|
+
expect(code_point.decomposition).to be_nil
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'initializes compatibility tag as nil' do
|
65
|
-
code_point.compatibility_decomposition_tag.
|
65
|
+
expect(code_point.compatibility_decomposition_tag).to be_nil
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'returns false from compatibility_decomposition?' do
|
69
|
-
code_point.
|
69
|
+
expect(code_point).not_to be_compatibility_decomposition
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
@@ -74,12 +74,12 @@ describe CodePoint do
|
|
74
74
|
describe "#find" do
|
75
75
|
it "retrieves information for any valid code point" do
|
76
76
|
data = CodePoint.find(0x301)
|
77
|
-
data.
|
78
|
-
data.fields.length.
|
77
|
+
expect(data).to be_a(CodePoint)
|
78
|
+
expect(data.fields.length).to eq(15)
|
79
79
|
end
|
80
80
|
|
81
81
|
it "returns nil if the information is not found" do
|
82
|
-
CodePoint.find(0xFFFFFFF).
|
82
|
+
expect(CodePoint.find(0xFFFFFFF)).to be_nil
|
83
83
|
end
|
84
84
|
|
85
85
|
it "fetches valid information for the specified code point" do
|
@@ -106,9 +106,9 @@ describe CodePoint do
|
|
106
106
|
test_data.each do |code_point, data|
|
107
107
|
cp_data = CodePoint.find(code_point)
|
108
108
|
|
109
|
-
cp_data.
|
109
|
+
expect(cp_data).not_to be_nil
|
110
110
|
|
111
|
-
[:code_point, :name, :category, :combining_class].map { |msg| cp_data.send(msg) }.
|
111
|
+
expect([:code_point, :name, :category, :combining_class].map { |msg| cp_data.send(msg) }).to eq(data[0..3])
|
112
112
|
end
|
113
113
|
end
|
114
114
|
end
|
@@ -116,32 +116,32 @@ describe CodePoint do
|
|
116
116
|
describe "#code_points_for{index}" do
|
117
117
|
it "returns code points for the given general unicode property name" do
|
118
118
|
cps = CodePoint.code_points_for_category(:Cc)
|
119
|
-
cps.
|
120
|
-
cps.first.
|
119
|
+
expect(cps).to be_a(Array)
|
120
|
+
expect(cps.first).to eq(0..31)
|
121
121
|
|
122
122
|
cps = CodePoint.code_points_for_bidi_class(:BN)
|
123
|
-
cps.
|
124
|
-
cps.first.
|
123
|
+
expect(cps).to be_a(Array)
|
124
|
+
expect(cps.first).to eq(0..8)
|
125
125
|
|
126
126
|
cps = CodePoint.code_points_for_bidi_mirrored(:N)
|
127
|
-
cps.
|
128
|
-
cps.first.
|
127
|
+
expect(cps).to be_a(Array)
|
128
|
+
expect(cps.first).to eq(0..39)
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
132
|
describe "#code_points_for_property_value" do
|
133
133
|
it "returns code points for the given unicode property and value" do
|
134
134
|
cps = CodePoint.code_points_for_line_break(:CM)
|
135
|
-
cps.
|
136
|
-
cps.first.
|
135
|
+
expect(cps).to be_a(Array)
|
136
|
+
expect(cps.first).to eq(0..8)
|
137
137
|
|
138
138
|
cps = CodePoint.code_points_for_sentence_break(:Extend)
|
139
|
-
cps.
|
140
|
-
cps.first.
|
139
|
+
expect(cps).to be_a(Array)
|
140
|
+
expect(cps.first).to eq(768..879)
|
141
141
|
|
142
142
|
cps = CodePoint.code_points_for_word_break(:Hebrew_Letter)
|
143
|
-
cps.
|
144
|
-
cps.first.
|
143
|
+
expect(cps).to be_a(Array)
|
144
|
+
expect(cps.first).to eq(1488..1514)
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
@@ -158,18 +158,18 @@ describe CodePoint do
|
|
158
158
|
end
|
159
159
|
|
160
160
|
it "should return a code point with the correct value" do
|
161
|
-
CodePoint.for_canonical_decomposition([123, 456]).
|
161
|
+
expect(CodePoint.for_canonical_decomposition([123, 456])).to eq("I'm code point 789")
|
162
162
|
end
|
163
163
|
|
164
164
|
it "should return nil if no decomposition mapping exists" do
|
165
|
-
CodePoint.for_canonical_decomposition([987]).
|
165
|
+
expect(CodePoint.for_canonical_decomposition([987])).to be_nil
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
169
169
|
it "should cache the decomposition map" do
|
170
170
|
mock(TwitterCldr).get_resource(:unicode_data, :canonical_compositions) { canonical_compositions }.once
|
171
|
-
CodePoint.for_canonical_decomposition([0xA0]).
|
172
|
-
CodePoint.for_canonical_decomposition([0xA0]).
|
171
|
+
expect(CodePoint.for_canonical_decomposition([0xA0])).to be_nil
|
172
|
+
expect(CodePoint.for_canonical_decomposition([0xA0])).to be_nil
|
173
173
|
end
|
174
174
|
end
|
175
175
|
|
@@ -186,29 +186,29 @@ describe CodePoint do
|
|
186
186
|
end
|
187
187
|
|
188
188
|
it "returns nil if not part of a hangul block" do
|
189
|
-
CodePoint.hangul_type(100).
|
189
|
+
expect(CodePoint.hangul_type(100)).to eq(nil)
|
190
190
|
end
|
191
191
|
|
192
192
|
it "returns the correct part (i.e. lpart, vpart, or tpart) before composition or decomposition" do
|
193
|
-
CodePoint.hangul_type(5).
|
194
|
-
CodePoint.hangul_type(30).
|
195
|
-
CodePoint.hangul_type(41).
|
193
|
+
expect(CodePoint.hangul_type(5)).to eq(:lparts)
|
194
|
+
expect(CodePoint.hangul_type(30)).to eq(:vparts)
|
195
|
+
expect(CodePoint.hangul_type(41)).to eq(:tparts)
|
196
196
|
end
|
197
197
|
|
198
198
|
it "returns composition if no part can be found" do
|
199
|
-
CodePoint.hangul_type(11).
|
199
|
+
expect(CodePoint.hangul_type(11)).to eq(:compositions)
|
200
200
|
end
|
201
201
|
end
|
202
202
|
|
203
203
|
describe "#excluded_from_composition?" do
|
204
204
|
it "excludes anything in the list of ranges" do
|
205
205
|
stub(CodePoint).composition_exclusions { [10..10, 13..14, 20..30] }
|
206
|
-
CodePoint.excluded_from_composition?(10).
|
207
|
-
CodePoint.excluded_from_composition?(13).
|
208
|
-
CodePoint.excluded_from_composition?(14).
|
209
|
-
CodePoint.excluded_from_composition?(15).
|
210
|
-
CodePoint.excluded_from_composition?(19).
|
211
|
-
CodePoint.excluded_from_composition?(100).
|
206
|
+
expect(CodePoint.excluded_from_composition?(10)).to be_true
|
207
|
+
expect(CodePoint.excluded_from_composition?(13)).to be_true
|
208
|
+
expect(CodePoint.excluded_from_composition?(14)).to be_true
|
209
|
+
expect(CodePoint.excluded_from_composition?(15)).to be_false
|
210
|
+
expect(CodePoint.excluded_from_composition?(19)).to be_false
|
211
|
+
expect(CodePoint.excluded_from_composition?(100)).to be_false
|
212
212
|
end
|
213
213
|
end
|
214
214
|
|
@@ -219,21 +219,21 @@ describe CodePoint do
|
|
219
219
|
|
220
220
|
it "finds the block that corresponds to the code point" do
|
221
221
|
stub(TwitterCldr).get_resource(:unicode_data, :blocks) { [[:klingon, 122..307], [:hirogen, 1337..2200]] }
|
222
|
-
CodePoint.send(:get_block, 200).
|
223
|
-
CodePoint.send(:get_block, 2199).
|
224
|
-
CodePoint.send(:get_block, 100).
|
222
|
+
expect(CodePoint.send(:get_block, 200)).to eq([:klingon, 122..307])
|
223
|
+
expect(CodePoint.send(:get_block, 2199)).to eq([:hirogen, 1337..2200])
|
224
|
+
expect(CodePoint.send(:get_block, 100)).to be_nil
|
225
225
|
end
|
226
226
|
end
|
227
227
|
|
228
228
|
describe "#get_range_start" do
|
229
229
|
it "returns the data for a non-explicit range" do
|
230
230
|
block_data = { 0x1337 => [0x1337, "<CJK Ideograph Extension A, First>"] }
|
231
|
-
CodePoint.send(:get_range_start, 0xABC, block_data).
|
231
|
+
expect(CodePoint.send(:get_range_start, 0xABC, block_data)).to eq([0xABC, "<CJK Ideograph Extension A>"])
|
232
232
|
end
|
233
233
|
|
234
234
|
it "returns nil if the block data doesn't contain a non-explicit range" do
|
235
235
|
block_data = { 0x1337 => [0x1337, "<CJK Ideograph Extension A>"] }
|
236
|
-
CodePoint.send(:get_range_start, 0xABC, block_data).
|
236
|
+
expect(CodePoint.send(:get_range_start, 0xABC, block_data)).to eq(nil)
|
237
237
|
end
|
238
238
|
end
|
239
239
|
end
|
@@ -15,16 +15,16 @@ describe Currencies do
|
|
15
15
|
it "should list all supported country codes" do
|
16
16
|
codes = Currencies.currency_codes
|
17
17
|
|
18
|
-
codes.size.
|
19
|
-
codes.
|
18
|
+
expect(codes.size).to eq(297)
|
19
|
+
expect(codes).to include(*TEST_CODES)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
describe "#for_code" do
|
24
24
|
it "should return all information for PEN" do
|
25
25
|
data = Currencies.for_code("PEN")
|
26
|
-
data.
|
27
|
-
data.
|
26
|
+
expect(data).to be_a(Hash)
|
27
|
+
expect(data).to include(
|
28
28
|
:name => "Peruvian nuevo sol",
|
29
29
|
:currency => :PEN,
|
30
30
|
:symbol => "S/.",
|
@@ -34,8 +34,8 @@ describe Currencies do
|
|
34
34
|
|
35
35
|
it "should return all information for CAD, a currency code with multiple possible symbols" do
|
36
36
|
data = Currencies.for_code("CAD")
|
37
|
-
data.
|
38
|
-
data.
|
37
|
+
expect(data).to be_a(Hash)
|
38
|
+
expect(data).to include(
|
39
39
|
:name => "Canadian dollar",
|
40
40
|
:currency => :CAD,
|
41
41
|
:symbol => "$",
|
@@ -46,7 +46,7 @@ describe Currencies do
|
|
46
46
|
it "verifies that all code_points values are equivalent to their corresponding symbols" do
|
47
47
|
Currencies.currency_codes.select do |code|
|
48
48
|
data = Currencies.for_code(code)
|
49
|
-
data[:code_points].pack("U*").
|
49
|
+
expect(data[:code_points].pack("U*")).to eq(data[:symbol])
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -12,79 +12,79 @@ describe LanguageCodes do
|
|
12
12
|
let(:languages) { LanguageCodes.languages }
|
13
13
|
|
14
14
|
it 'returns an array' do
|
15
|
-
languages.
|
15
|
+
expect(languages).to be_instance_of(Array)
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'returns symbols' do
|
19
|
-
languages.each { |language| language.
|
19
|
+
languages.each { |language| expect(language).to be_instance_of(Symbol) }
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'returns supported languages' do
|
23
|
-
languages.
|
23
|
+
expect(languages).to include(:Spanish, :English, :Russian, :Japanese, :Basque)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
describe '#valid_standard?' do
|
28
28
|
it 'returns true if the standard is valid' do
|
29
|
-
LanguageCodes.valid_standard?(:iso_639_2).
|
29
|
+
expect(LanguageCodes.valid_standard?(:iso_639_2)).to be_true
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'returns false if the standard is invalid' do
|
33
|
-
LanguageCodes.valid_standard?(:iso_639).
|
33
|
+
expect(LanguageCodes.valid_standard?(:iso_639)).to be_false
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'accepts a string' do
|
37
|
-
LanguageCodes.valid_standard?('iso_639_2').
|
37
|
+
expect(LanguageCodes.valid_standard?('iso_639_2')).to be_true
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
describe '#valid_code?' do
|
42
42
|
it 'returns true if the code is present in the given standard' do
|
43
|
-
LanguageCodes.valid_code?(:spa, :iso_639_2).
|
43
|
+
expect(LanguageCodes.valid_code?(:spa, :iso_639_2)).to be_true
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'returns false if the code is not present in the given standard' do
|
47
|
-
LanguageCodes.valid_code?(:foo, :iso_639_2).
|
47
|
+
expect(LanguageCodes.valid_code?(:foo, :iso_639_2)).to be_false
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'raises exception if the standard is invalid' do
|
51
|
-
|
51
|
+
expect { LanguageCodes.valid_code?(:es, :foobar) }.to raise_exception(ArgumentError, ':foobar is not a valid standard name')
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'accepts strings' do
|
55
|
-
LanguageCodes.valid_code?('spa', 'iso_639_2').
|
55
|
+
expect(LanguageCodes.valid_code?('spa', 'iso_639_2')).to be_true
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
describe '#convert' do
|
60
60
|
it 'converts codes between different standards' do
|
61
|
-
LanguageCodes.convert(:Spanish, :from => :name, :to => :bcp_47 ).
|
62
|
-
LanguageCodes.convert(:es, :from => :bcp_47, :to => :iso_639_1).
|
63
|
-
LanguageCodes.convert(:es, :from => :iso_639_1, :to => :iso_639_2).
|
64
|
-
LanguageCodes.convert(:spa, :from => :iso_639_2, :to => :iso_639_3).
|
65
|
-
LanguageCodes.convert(:spa, :from => :iso_639_3, :to => :name ).
|
61
|
+
expect(LanguageCodes.convert(:Spanish, :from => :name, :to => :bcp_47 )).to eq(:es)
|
62
|
+
expect(LanguageCodes.convert(:es, :from => :bcp_47, :to => :iso_639_1)).to eq(:es)
|
63
|
+
expect(LanguageCodes.convert(:es, :from => :iso_639_1, :to => :iso_639_2)).to eq(:spa)
|
64
|
+
expect(LanguageCodes.convert(:spa, :from => :iso_639_2, :to => :iso_639_3)).to eq(:spa)
|
65
|
+
expect(LanguageCodes.convert(:spa, :from => :iso_639_3, :to => :name )).to eq(:Spanish)
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'converts from terminology iso_639_2 codes' do
|
69
|
-
LanguageCodes.convert(:hye, :from => :iso_639_2, :to => :bcp_47).
|
69
|
+
expect(LanguageCodes.convert(:hye, :from => :iso_639_2, :to => :bcp_47)).to eq(:hy)
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'converts from alternative bcp_47 codes' do
|
73
|
-
LanguageCodes.convert('ar-adf', :from => :bcp_47, :to => :iso_639_3).
|
73
|
+
expect(LanguageCodes.convert('ar-adf', :from => :bcp_47, :to => :iso_639_3)).to eq(:adf)
|
74
74
|
end
|
75
75
|
|
76
76
|
it 'returns nil if conversion data is missing' do
|
77
|
-
LanguageCodes.convert(:bsq, :from => :bcp_47, :to => :iso_639_1).
|
78
|
-
LanguageCodes.convert(:FooBar, :from => :name, :to => :iso_639_1).
|
77
|
+
expect(LanguageCodes.convert(:bsq, :from => :bcp_47, :to => :iso_639_1)).to be_nil
|
78
|
+
expect(LanguageCodes.convert(:FooBar, :from => :name, :to => :iso_639_1)).to be_nil
|
79
79
|
end
|
80
80
|
|
81
81
|
it 'accepts strings' do
|
82
|
-
LanguageCodes.convert('Spanish', 'from' => 'name', 'to' => 'bcp_47').
|
82
|
+
expect(LanguageCodes.convert('Spanish', 'from' => 'name', 'to' => 'bcp_47')).to eq(:es)
|
83
83
|
end
|
84
84
|
|
85
85
|
it 'raises exception if :from or :to options are missing' do
|
86
86
|
[[:es, { :to => :bcp_47 }], [:es, { :from => :bcp_47 }], [:es]].each do |args|
|
87
|
-
|
87
|
+
expect { LanguageCodes.convert(*args) }.to raise_exception(ArgumentError, "options :from and :to are required")
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
@@ -94,36 +94,36 @@ describe LanguageCodes do
|
|
94
94
|
[:es, { :from => :bcp_47, :to => :foobar }],
|
95
95
|
[:es, { :from => :foobar, :to => :foobar }]
|
96
96
|
].each do |args|
|
97
|
-
|
97
|
+
expect { LanguageCodes.convert(*args) }.to raise_exception(ArgumentError, ':foobar is not a valid standard name')
|
98
98
|
end
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
102
|
describe '#from_language' do
|
103
103
|
it 'returns language code by language name' do
|
104
|
-
LanguageCodes.from_language(:Spanish, :iso_639_2).
|
104
|
+
expect(LanguageCodes.from_language(:Spanish, :iso_639_2)).to eq(:spa)
|
105
105
|
end
|
106
106
|
|
107
107
|
it 'accepts strings' do
|
108
|
-
LanguageCodes.from_language('Spanish', 'iso_639_2').
|
108
|
+
expect(LanguageCodes.from_language('Spanish', 'iso_639_2')).to eq(:spa)
|
109
109
|
end
|
110
110
|
|
111
111
|
it 'raises exception when standard is invalid' do
|
112
|
-
|
112
|
+
expect { LanguageCodes.from_language(:Spanish, :foobar) }.to raise_exception(':foobar is not a valid standard name')
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
116
|
describe '#to_language' do
|
117
117
|
it 'returns language name as a string by language code' do
|
118
|
-
LanguageCodes.to_language(:es, :iso_639_1).
|
118
|
+
expect(LanguageCodes.to_language(:es, :iso_639_1)).to eq('Spanish')
|
119
119
|
end
|
120
120
|
|
121
121
|
it 'accepts strings' do
|
122
|
-
LanguageCodes.to_language('es', 'iso_639_1').
|
122
|
+
expect(LanguageCodes.to_language('es', 'iso_639_1')).to eq('Spanish')
|
123
123
|
end
|
124
124
|
|
125
125
|
it 'raises exception when standard is invalid' do
|
126
|
-
|
126
|
+
expect { LanguageCodes.to_language(:es, :foobar) }.to raise_exception(':foobar is not a valid standard name')
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
@@ -131,15 +131,15 @@ describe LanguageCodes do
|
|
131
131
|
let(:spanish_standards) { [:bcp_47, :iso_639_1, :iso_639_2, :iso_639_3] }
|
132
132
|
|
133
133
|
it 'returns an array of standards that are available for conversion from a given code' do
|
134
|
-
LanguageCodes.standards_for(:es, :bcp_47).
|
134
|
+
expect(LanguageCodes.standards_for(:es, :bcp_47)).to match_array(spanish_standards)
|
135
135
|
end
|
136
136
|
|
137
137
|
it 'accepts string' do
|
138
|
-
LanguageCodes.standards_for('es', 'bcp_47').
|
138
|
+
expect(LanguageCodes.standards_for('es', 'bcp_47')).to match_array(spanish_standards)
|
139
139
|
end
|
140
140
|
|
141
141
|
it 'raises exception when standard is invalid' do
|
142
|
-
|
142
|
+
expect { LanguageCodes.standards_for(:es, :foobar) }.to raise_exception(':foobar is not a valid standard name')
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
@@ -147,15 +147,15 @@ describe LanguageCodes do
|
|
147
147
|
let(:spanish_standards) { [:bcp_47, :iso_639_1, :iso_639_2, :iso_639_3] }
|
148
148
|
|
149
149
|
it 'returns an array of standards that have a code for a given language' do
|
150
|
-
LanguageCodes.standards_for_language(:Spanish).
|
150
|
+
expect(LanguageCodes.standards_for_language(:Spanish)).to match_array(spanish_standards)
|
151
151
|
end
|
152
152
|
|
153
153
|
it 'accepts string' do
|
154
|
-
LanguageCodes.standards_for_language('Spanish').
|
154
|
+
expect(LanguageCodes.standards_for_language('Spanish')).to match_array(spanish_standards)
|
155
155
|
end
|
156
156
|
|
157
157
|
it 'returns empty array for unknown languages' do
|
158
|
-
LanguageCodes.standards_for_language('FooBar').
|
158
|
+
expect(LanguageCodes.standards_for_language('FooBar')).to eq([])
|
159
159
|
end
|
160
160
|
end
|
161
161
|
end
|
@@ -10,98 +10,98 @@ include TwitterCldr::Shared
|
|
10
10
|
describe Languages do
|
11
11
|
describe "#translate_language" do
|
12
12
|
it "should translate a language from one locale to another" do
|
13
|
-
Languages.translate_language("Russian", :en, :es).
|
14
|
-
Languages.translate_language("ruso", :es, :en).
|
15
|
-
Languages.translate_language("Spanish", :en, :es).
|
16
|
-
Languages.translate_language("ruso", :es, :ru).
|
13
|
+
expect(Languages.translate_language("Russian", :en, :es)).to match_normalized("ruso")
|
14
|
+
expect(Languages.translate_language("ruso", :es, :en)).to match_normalized("Russian")
|
15
|
+
expect(Languages.translate_language("Spanish", :en, :es)).to match_normalized("español")
|
16
|
+
expect(Languages.translate_language("ruso", :es, :ru)).to match_normalized("русский")
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should be capitalization agnostic" do
|
20
|
-
Languages.translate_language("russian", :en, :es).
|
21
|
-
Languages.translate_language("RUSSIAN", :en, :es).
|
20
|
+
expect(Languages.translate_language("russian", :en, :es)).to match_normalized("ruso")
|
21
|
+
expect(Languages.translate_language("RUSSIAN", :en, :es)).to match_normalized("ruso")
|
22
22
|
end
|
23
23
|
|
24
24
|
it "defaults the destination language to English (or whatever the global locale is)" do
|
25
|
-
Languages.translate_language("Ruso", :es).
|
26
|
-
Languages.translate_language("русский", :ru).
|
25
|
+
expect(Languages.translate_language("Ruso", :es)).to match_normalized("Russian")
|
26
|
+
expect(Languages.translate_language("русский", :ru)).to match_normalized("Russian")
|
27
27
|
end
|
28
28
|
|
29
29
|
it "defaults source and destination language to English if not given" do
|
30
|
-
Languages.translate_language("Russian").
|
30
|
+
expect(Languages.translate_language("Russian")).to match_normalized("Russian")
|
31
31
|
TwitterCldr.locale = :es
|
32
|
-
Languages.translate_language("Russian").
|
32
|
+
expect(Languages.translate_language("Russian")).to match_normalized("ruso")
|
33
33
|
end
|
34
34
|
|
35
35
|
it "successfully translates locale codes that are and are not in the CLDR using the locale map" do
|
36
|
-
Languages.translate_language("Russian", :en, :'zh-cn').
|
37
|
-
Languages.translate_language("Russian", :en, :'zh').
|
36
|
+
expect(Languages.translate_language("Russian", :en, :'zh-cn')).to match_normalized("俄文")
|
37
|
+
expect(Languages.translate_language("Russian", :en, :'zh')).to match_normalized("俄文")
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should return nil if no translation was found" do
|
41
|
-
Languages.translate_language("Russian", :en, :blarg).
|
41
|
+
expect(Languages.translate_language("Russian", :en, :blarg)).to eq(nil)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
describe "#from_code_for_locale" do
|
46
46
|
it "should return the language in the correct locale for the given locale code (i.e. es in English should be Spanish)" do
|
47
|
-
Languages.from_code_for_locale(:es, :en).
|
48
|
-
Languages.from_code_for_locale(:en, :es).
|
47
|
+
expect(Languages.from_code_for_locale(:es, :en)).to match_normalized("Spanish")
|
48
|
+
expect(Languages.from_code_for_locale(:en, :es)).to match_normalized("inglés")
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
describe "#from_code" do
|
53
53
|
it "should return the language in the default locale for the given locale code" do
|
54
|
-
Languages.from_code(:es).
|
55
|
-
Languages.from_code(:ru).
|
54
|
+
expect(Languages.from_code(:es)).to match_normalized("Spanish")
|
55
|
+
expect(Languages.from_code(:ru)).to match_normalized("Russian")
|
56
56
|
TwitterCldr.locale = :es
|
57
|
-
Languages.from_code(:es).
|
57
|
+
expect(Languages.from_code(:es)).to match_normalized("español")
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
describe "#all_for" do
|
62
62
|
it "should return a hash of all languages for the given language code" do
|
63
63
|
langs = Languages.all_for(:es)
|
64
|
-
langs.
|
65
|
-
langs[:ru].
|
64
|
+
expect(langs).to be_a(Hash)
|
65
|
+
expect(langs[:ru]).to match_normalized("ruso")
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should return an empty hash for an invalid language" do
|
69
69
|
langs = Languages.all_for(:blarg)
|
70
|
-
langs.
|
70
|
+
expect(langs).to eq({})
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
74
|
describe "#all" do
|
75
75
|
it "should use the default language to get the language hash" do
|
76
76
|
langs = Languages.all
|
77
|
-
langs.
|
78
|
-
langs[:ru].
|
79
|
-
langs[:de].
|
77
|
+
expect(langs).to be_a(Hash)
|
78
|
+
expect(langs[:ru]).to match_normalized("Russian")
|
79
|
+
expect(langs[:de]).to match_normalized("German")
|
80
80
|
|
81
81
|
TwitterCldr.locale = :es
|
82
82
|
langs = Languages.all
|
83
|
-
langs.
|
84
|
-
langs[:ru].
|
85
|
-
langs[:de].
|
83
|
+
expect(langs).to be_a(Hash)
|
84
|
+
expect(langs[:ru]).to match_normalized("ruso")
|
85
|
+
expect(langs[:de]).to match_normalized("alemán")
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
89
|
describe "#is_rtl?" do
|
90
90
|
it "should return true for certain locales" do
|
91
91
|
[:ar, :he, :ur, :fa].each do |locale|
|
92
|
-
Languages.is_rtl?(locale).
|
92
|
+
expect(Languages.is_rtl?(locale)).to be_true
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
96
|
it "should return false for certain locales" do
|
97
97
|
[:en, :es, :hu, :ja].each do |locale|
|
98
|
-
Languages.is_rtl?(locale).
|
98
|
+
expect(Languages.is_rtl?(locale)).to be_false
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
102
|
it "should not raise errors for any locale" do
|
103
103
|
TwitterCldr.supported_locales.each do |locale|
|
104
|
-
|
104
|
+
expect { Languages.is_rtl?(locale) }.not_to raise_error
|
105
105
|
end
|
106
106
|
end
|
107
107
|
end
|
@@ -10,12 +10,12 @@ include TwitterCldr::Shared
|
|
10
10
|
describe NumberingSystem do
|
11
11
|
describe "#for_name" do
|
12
12
|
it "should return the correct numbering system for the given name" do
|
13
|
-
NumberingSystem.for_name("latn").digits.
|
14
|
-
NumberingSystem.for_name("arab").digits.
|
13
|
+
expect(NumberingSystem.for_name("latn").digits).to eq(%w(0 1 2 3 4 5 6 7 8 9))
|
14
|
+
expect(NumberingSystem.for_name("arab").digits).to eq(%w(٠ ١ ٢ ٣ ٤ ٥ ٦ ٧ ٨ ٩))
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should raise an error if the system is not numeric" do
|
18
|
-
|
18
|
+
expect { NumberingSystem.for_name("roman") }.to raise_error(UnsupportedNumberingSystemError)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -24,8 +24,8 @@ describe NumberingSystem do
|
|
24
24
|
let(:system) { NumberingSystem.for_name("arab") }
|
25
25
|
|
26
26
|
it "replaces ascii numeral characters with arabic ones" do
|
27
|
-
system.transliterate(123).
|
28
|
-
system.transliterate(947).
|
27
|
+
expect(system.transliterate(123)).to match_normalized("١٢٣")
|
28
|
+
expect(system.transliterate(947)).to match_normalized("٩٤٧")
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -33,8 +33,8 @@ describe NumberingSystem do
|
|
33
33
|
let(:system) { NumberingSystem.for_name("hanidec") }
|
34
34
|
|
35
35
|
it "replaces ascii numeral characters with Han ones" do
|
36
|
-
system.transliterate(123).
|
37
|
-
system.transliterate(947).
|
36
|
+
expect(system.transliterate(123)).to match_normalized("一二三")
|
37
|
+
expect(system.transliterate(947)).to match_normalized("九四七")
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|