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
data/spec/spec_helper.rb
CHANGED
@@ -80,10 +80,10 @@ RSpec::Matchers.define :exactly_match do |expected|
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def check_token_list(got, expected)
|
83
|
-
got.size.
|
83
|
+
expect(got.size).to eq(expected.size)
|
84
84
|
expected.each_with_index do |exp_hash, index|
|
85
85
|
exp_hash.each_pair do |exp_key, exp_val|
|
86
|
-
got[index].send(exp_key).
|
86
|
+
expect(got[index].send(exp_key)).to eq(exp_val)
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
@@ -41,7 +41,7 @@ describe DateTokenizer do
|
|
41
41
|
|
42
42
|
it "should tokenize composites correctly" do
|
43
43
|
# Ensure that buddhist calendar data is present in th locale.
|
44
|
-
TwitterCldr.get_locale_resource(:th, :calendars)[:th][:calendars][:buddhist].
|
44
|
+
expect(TwitterCldr.get_locale_resource(:th, :calendars)[:th][:calendars][:buddhist]).not_to(
|
45
45
|
be_nil, 'buddhist calendar is missing for :th locale (check resources/locales/th/calendars.yml)'
|
46
46
|
)
|
47
47
|
|
@@ -14,18 +14,18 @@ describe TimespanTokenizer do
|
|
14
14
|
tokenizer = TimespanTokenizer.new(nil)
|
15
15
|
tokenizer.tokenize("Hace {0} minutos").tap do |tokens|
|
16
16
|
tokens[0].tap do |token|
|
17
|
-
token.value.
|
18
|
-
token.type.
|
17
|
+
expect(token.value).to eq("Hace ")
|
18
|
+
expect(token.type).to eq(:plaintext)
|
19
19
|
end
|
20
20
|
|
21
21
|
tokens[1].tap do |token|
|
22
|
-
token.value.
|
23
|
-
token.type.
|
22
|
+
expect(token.value).to eq("{0}")
|
23
|
+
expect(token.type).to eq(:pattern)
|
24
24
|
end
|
25
25
|
|
26
26
|
tokens[2].tap do |token|
|
27
|
-
token.value.
|
28
|
-
token.type.
|
27
|
+
expect(token.value).to eq(" minutos")
|
28
|
+
expect(token.type).to eq(:plaintext)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -14,8 +14,8 @@ describe CompositeToken do
|
|
14
14
|
token_1 = Token.new(:type => "my_type_1", :value => "my_value_1")
|
15
15
|
|
16
16
|
composite_token = CompositeToken.new([token_0, token_1])
|
17
|
-
composite_token.tokens.map { |t| t.type }.
|
18
|
-
composite_token.tokens.map { |t| t.value }.
|
17
|
+
expect(composite_token.tokens.map { |t| t.type }).to eq(["my_type_0", "my_type_1"])
|
18
|
+
expect(composite_token.tokens.map { |t| t.value }).to eq(["my_value_0", "my_value_1"])
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should return content" do
|
@@ -23,7 +23,7 @@ describe CompositeToken do
|
|
23
23
|
token_1 = Token.new(:type => "my_type_1", :value => "my_value_1")
|
24
24
|
|
25
25
|
composite_token = CompositeToken.new([token_0, token_1])
|
26
|
-
composite_token.to_s.
|
26
|
+
expect(composite_token.to_s).to eq("my_value_0my_value_1")
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -11,14 +11,14 @@ describe Token do
|
|
11
11
|
describe "#initialize" do
|
12
12
|
it "should set instance variables passed in the options hash" do
|
13
13
|
token = Token.new(:type => "my_type", :value => "my_value")
|
14
|
-
token.type.
|
15
|
-
token.value.
|
14
|
+
expect(token.type).to eq("my_type")
|
15
|
+
expect(token.value).to eq("my_value")
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
describe "#to_s" do
|
20
20
|
it "should return the token's value" do
|
21
|
-
Token.new(:value => "my_value").to_s.
|
21
|
+
expect(Token.new(:value => "my_value").to_s).to eq("my_value")
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
data/spec/twitter_cldr_spec.rb
CHANGED
@@ -8,57 +8,57 @@ require 'spec_helper'
|
|
8
8
|
describe TwitterCldr do
|
9
9
|
describe "#supported_locale?" do
|
10
10
|
it "should return true if the locale is supported" do
|
11
|
-
TwitterCldr.supported_locale?(:es).
|
12
|
-
TwitterCldr.supported_locale?("es").
|
11
|
+
expect(TwitterCldr.supported_locale?(:es)).to be_true
|
12
|
+
expect(TwitterCldr.supported_locale?("es")).to be_true
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should return false if the locale isn't supported" do
|
16
|
-
TwitterCldr.supported_locale?(:bogus).
|
17
|
-
TwitterCldr.supported_locale?("bogus").
|
16
|
+
expect(TwitterCldr.supported_locale?(:bogus)).to be_false
|
17
|
+
expect(TwitterCldr.supported_locale?("bogus")).to be_false
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should return true if the given locale code is twitter-specific" do
|
21
|
-
TwitterCldr.supported_locale?(:'zh-cn').
|
22
|
-
TwitterCldr.supported_locale?(:'zh-tw').
|
23
|
-
TwitterCldr.supported_locale?(:msa).
|
21
|
+
expect(TwitterCldr.supported_locale?(:'zh-cn')).to be_true
|
22
|
+
expect(TwitterCldr.supported_locale?(:'zh-tw')).to be_true
|
23
|
+
expect(TwitterCldr.supported_locale?(:msa)).to be_true
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
describe "#supported_locales" do
|
28
28
|
it "should return an array of currently supported locale codes" do
|
29
29
|
locales = TwitterCldr.supported_locales
|
30
|
-
locales.
|
31
|
-
locales.
|
32
|
-
locales.
|
33
|
-
locales.
|
30
|
+
expect(locales).to include(:es)
|
31
|
+
expect(locales).to include(:zh)
|
32
|
+
expect(locales).to include(:nb)
|
33
|
+
expect(locales).to include(:ja)
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'should not include :shared or :unicode_data' do
|
37
|
-
(TwitterCldr.supported_locales & [:shared, :unicode_data]).
|
37
|
+
expect(TwitterCldr.supported_locales & [:shared, :unicode_data]).to be_empty
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
describe "#convert_locale" do
|
42
42
|
it "should convert a twitter locale to a CLDR locale" do
|
43
|
-
TwitterCldr.convert_locale(:msa).
|
44
|
-
TwitterCldr.convert_locale(:'zh-cn').
|
45
|
-
TwitterCldr.convert_locale(:'zh-tw').
|
43
|
+
expect(TwitterCldr.convert_locale(:msa)).to eq(:ms)
|
44
|
+
expect(TwitterCldr.convert_locale(:'zh-cn')).to eq(:zh)
|
45
|
+
expect(TwitterCldr.convert_locale(:'zh-tw')).to eq(:'zh-Hant')
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should leave unknown locales alone" do
|
49
|
-
TwitterCldr.convert_locale(:blarg).
|
49
|
+
expect(TwitterCldr.convert_locale(:blarg)).to eq(:blarg)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
describe "#twitter_locale" do
|
54
54
|
it "should convert a CLDR locale to a twitter locale" do
|
55
|
-
TwitterCldr.twitter_locale(:ms).
|
56
|
-
TwitterCldr.twitter_locale(:zh).
|
57
|
-
TwitterCldr.twitter_locale(:'zh-Hant').
|
55
|
+
expect(TwitterCldr.twitter_locale(:ms)).to eq(:msa)
|
56
|
+
expect(TwitterCldr.twitter_locale(:zh)).to eq(:'zh-cn')
|
57
|
+
expect(TwitterCldr.twitter_locale(:'zh-Hant')).to eq(:'zh-tw')
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should leave unknown locales alone" do
|
61
|
-
TwitterCldr.twitter_locale(:blarg).
|
61
|
+
expect(TwitterCldr.twitter_locale(:blarg)).to eq(:blarg)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
@@ -66,22 +66,22 @@ describe TwitterCldr do
|
|
66
66
|
context "with explicit locale" do
|
67
67
|
it "should return the same locale the user sets (if it's supported)" do
|
68
68
|
TwitterCldr.locale = :es
|
69
|
-
TwitterCldr.locale.
|
69
|
+
expect(TwitterCldr.locale).to eq(:es)
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should convert strings to symbols" do
|
73
73
|
TwitterCldr.locale = "es"
|
74
|
-
TwitterCldr.locale.
|
74
|
+
expect(TwitterCldr.locale).to eq(:es)
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should fall back if the user sets an unsupported locale" do
|
78
78
|
FastGettext.locale = :ko
|
79
79
|
TwitterCldr.locale = "blarg"
|
80
|
-
TwitterCldr.locale.
|
80
|
+
expect(TwitterCldr.locale).to eq(:ko)
|
81
81
|
|
82
82
|
FastGettext.locale = nil
|
83
83
|
I18n.locale = :hu
|
84
|
-
TwitterCldr.locale.
|
84
|
+
expect(TwitterCldr.locale).to eq(:hu)
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
@@ -93,13 +93,13 @@ describe TwitterCldr do
|
|
93
93
|
it "should return FastGettext locale before I18n locale and fall back gracefully" do
|
94
94
|
FastGettext.locale = :pt
|
95
95
|
I18n.locale = :ar
|
96
|
-
TwitterCldr.locale.
|
96
|
+
expect(TwitterCldr.locale).to eq(:pt)
|
97
97
|
|
98
98
|
FastGettext.locale = nil
|
99
|
-
TwitterCldr.locale.
|
99
|
+
expect(TwitterCldr.locale).to eq(:ar)
|
100
100
|
|
101
101
|
I18n.locale = nil
|
102
|
-
TwitterCldr.locale.
|
102
|
+
expect(TwitterCldr.locale).to eq(:en)
|
103
103
|
end
|
104
104
|
|
105
105
|
context "with only FastGettext locale" do
|
@@ -109,12 +109,12 @@ describe TwitterCldr do
|
|
109
109
|
|
110
110
|
it "should return the FastGettext locale if it's supported" do
|
111
111
|
FastGettext.locale = "vi"
|
112
|
-
TwitterCldr.locale.
|
112
|
+
expect(TwitterCldr.locale).to eq(:vi)
|
113
113
|
end
|
114
114
|
|
115
115
|
it "should return the default locale if the FastGettext locale is unsupported" do
|
116
116
|
FastGettext.locale = "bogus"
|
117
|
-
TwitterCldr.locale.
|
117
|
+
expect(TwitterCldr.locale).to eq(TwitterCldr::DEFAULT_LOCALE)
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
@@ -125,12 +125,12 @@ describe TwitterCldr do
|
|
125
125
|
|
126
126
|
it "should return the I18n locale if it's supported" do
|
127
127
|
I18n.locale = "ru"
|
128
|
-
TwitterCldr.locale.
|
128
|
+
expect(TwitterCldr.locale).to eq(:ru)
|
129
129
|
end
|
130
130
|
|
131
131
|
it "should return the default locale if the I18n locale is unsupported" do
|
132
132
|
I18n.locale = "bogus"
|
133
|
-
TwitterCldr.locale.
|
133
|
+
expect(TwitterCldr.locale).to eq(TwitterCldr::DEFAULT_LOCALE)
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
@@ -141,33 +141,33 @@ describe TwitterCldr do
|
|
141
141
|
end
|
142
142
|
|
143
143
|
it "should fall back to the custom locale" do
|
144
|
-
TwitterCldr.locale.
|
144
|
+
expect(TwitterCldr.locale).to eq(:en)
|
145
145
|
@allow = true
|
146
|
-
TwitterCldr.locale.
|
146
|
+
expect(TwitterCldr.locale).to eq(:uk)
|
147
147
|
end
|
148
148
|
|
149
149
|
it "should fall back to the next fallback option if the custom one returns nil" do
|
150
150
|
FastGettext.locale = :lv
|
151
|
-
TwitterCldr.locale.
|
151
|
+
expect(TwitterCldr.locale).to eq(:lv)
|
152
152
|
@allow = true
|
153
|
-
TwitterCldr.locale.
|
153
|
+
expect(TwitterCldr.locale).to eq(:uk)
|
154
154
|
end
|
155
155
|
|
156
156
|
it "should not return the fallback locale if it's unsupported" do
|
157
157
|
TwitterCldr.reset_locale_fallbacks
|
158
158
|
TwitterCldr.register_locale_fallback(lambda { :zzz })
|
159
|
-
TwitterCldr.locale.
|
159
|
+
expect(TwitterCldr.locale).to eq(:en)
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
163
163
|
it "should fall back if the user sets an unsupported locale" do
|
164
164
|
FastGettext.locale = :ko
|
165
165
|
TwitterCldr.locale = "blarg"
|
166
|
-
TwitterCldr.locale.
|
166
|
+
expect(TwitterCldr.locale).to eq(:ko)
|
167
167
|
|
168
168
|
FastGettext.locale = nil
|
169
169
|
I18n.locale = :hu
|
170
|
-
TwitterCldr.locale.
|
170
|
+
expect(TwitterCldr.locale).to eq(:hu)
|
171
171
|
end
|
172
172
|
end
|
173
173
|
|
@@ -179,13 +179,13 @@ describe TwitterCldr do
|
|
179
179
|
it "should return FastGettext locale before I18n locale and fall back gracefully" do
|
180
180
|
FastGettext.locale = :pt
|
181
181
|
I18n.locale = :ar
|
182
|
-
TwitterCldr.locale.
|
182
|
+
expect(TwitterCldr.locale).to eq(:pt)
|
183
183
|
|
184
184
|
FastGettext.locale = nil
|
185
|
-
TwitterCldr.locale.
|
185
|
+
expect(TwitterCldr.locale).to eq(:ar)
|
186
186
|
|
187
187
|
I18n.locale = nil
|
188
|
-
TwitterCldr.locale.
|
188
|
+
expect(TwitterCldr.locale).to eq(:en)
|
189
189
|
end
|
190
190
|
|
191
191
|
context "with only FastGettext locale" do
|
@@ -195,12 +195,12 @@ describe TwitterCldr do
|
|
195
195
|
|
196
196
|
it "should return the FastGettext locale if it's supported" do
|
197
197
|
FastGettext.locale = "vi"
|
198
|
-
TwitterCldr.locale.
|
198
|
+
expect(TwitterCldr.locale).to eq(:vi)
|
199
199
|
end
|
200
200
|
|
201
201
|
it "should return the default locale if the FastGettext locale is unsupported" do
|
202
202
|
FastGettext.locale = "bogus"
|
203
|
-
TwitterCldr.locale.
|
203
|
+
expect(TwitterCldr.locale).to eq(TwitterCldr::DEFAULT_LOCALE)
|
204
204
|
end
|
205
205
|
end
|
206
206
|
|
@@ -211,12 +211,12 @@ describe TwitterCldr do
|
|
211
211
|
|
212
212
|
it "should return the I18n locale if it's supported" do
|
213
213
|
I18n.locale = "ru"
|
214
|
-
TwitterCldr.locale.
|
214
|
+
expect(TwitterCldr.locale).to eq(:ru)
|
215
215
|
end
|
216
216
|
|
217
217
|
it "should return the default locale if the I18n locale is unsupported" do
|
218
218
|
I18n.locale = "bogus"
|
219
|
-
TwitterCldr.locale.
|
219
|
+
expect(TwitterCldr.locale).to eq(TwitterCldr::DEFAULT_LOCALE)
|
220
220
|
end
|
221
221
|
end
|
222
222
|
|
@@ -227,22 +227,22 @@ describe TwitterCldr do
|
|
227
227
|
end
|
228
228
|
|
229
229
|
it "should fall back to the custom locale" do
|
230
|
-
TwitterCldr.locale.
|
230
|
+
expect(TwitterCldr.locale).to eq(:en)
|
231
231
|
@allow = true
|
232
|
-
TwitterCldr.locale.
|
232
|
+
expect(TwitterCldr.locale).to eq(:uk)
|
233
233
|
end
|
234
234
|
|
235
235
|
it "should fall back to the next fallback option if the custom one returns nil" do
|
236
236
|
FastGettext.locale = :lv
|
237
|
-
TwitterCldr.locale.
|
237
|
+
expect(TwitterCldr.locale).to eq(:lv)
|
238
238
|
@allow = true
|
239
|
-
TwitterCldr.locale.
|
239
|
+
expect(TwitterCldr.locale).to eq(:uk)
|
240
240
|
end
|
241
241
|
|
242
242
|
it "should not return the fallback locale if it's unsupported" do
|
243
243
|
TwitterCldr.reset_locale_fallbacks
|
244
244
|
TwitterCldr.register_locale_fallback(lambda { :zzz })
|
245
|
-
TwitterCldr.locale.
|
245
|
+
expect(TwitterCldr.locale).to eq(:en)
|
246
246
|
end
|
247
247
|
end
|
248
248
|
end
|
@@ -250,54 +250,54 @@ describe TwitterCldr do
|
|
250
250
|
|
251
251
|
describe "#with_locale" do
|
252
252
|
it "should only change the locale in the context of the block" do
|
253
|
-
TwitterCldr::Shared::Languages.from_code(:es).
|
254
|
-
TwitterCldr.with_locale(:es) { TwitterCldr::Shared::Languages.from_code(:es) }.
|
255
|
-
TwitterCldr::Shared::Languages.from_code(:es).
|
253
|
+
expect(TwitterCldr::Shared::Languages.from_code(:es)).to eq("Spanish")
|
254
|
+
expect(TwitterCldr.with_locale(:es) { TwitterCldr::Shared::Languages.from_code(:es) }).to match_normalized("español")
|
255
|
+
expect(TwitterCldr::Shared::Languages.from_code(:es)).to eq("Spanish")
|
256
256
|
end
|
257
257
|
|
258
258
|
it "switches the locale back to the original if the block raises an error" do
|
259
|
-
TwitterCldr.locale.
|
259
|
+
expect(TwitterCldr.locale).to eq(:en)
|
260
260
|
locale_inside_block = nil
|
261
261
|
|
262
|
-
|
262
|
+
expect do
|
263
263
|
TwitterCldr.with_locale(:es) do
|
264
264
|
locale_inside_block = TwitterCldr.locale
|
265
265
|
raise "Error!"
|
266
266
|
end
|
267
|
-
end.
|
267
|
+
end.to raise_error
|
268
268
|
|
269
|
-
locale_inside_block.
|
270
|
-
TwitterCldr.locale.
|
269
|
+
expect(locale_inside_block).to eq(:es)
|
270
|
+
expect(TwitterCldr.locale).to eq(:en)
|
271
271
|
end
|
272
272
|
end
|
273
273
|
|
274
274
|
describe "#with_locale" do
|
275
275
|
it "should only change the locale in the context of the block" do
|
276
|
-
TwitterCldr::Shared::Languages.from_code(:es).
|
277
|
-
TwitterCldr.with_locale(:es) { TwitterCldr::Shared::Languages.from_code(:es) }.
|
278
|
-
TwitterCldr::Shared::Languages.from_code(:es).
|
276
|
+
expect(TwitterCldr::Shared::Languages.from_code(:es)).to eq("Spanish")
|
277
|
+
expect(TwitterCldr.with_locale(:es) { TwitterCldr::Shared::Languages.from_code(:es) }).to match_normalized("español")
|
278
|
+
expect(TwitterCldr::Shared::Languages.from_code(:es)).to eq("Spanish")
|
279
279
|
end
|
280
280
|
|
281
281
|
it "doesn't mess up if the given locale isn't supported" do
|
282
282
|
TwitterCldr.locale = :pt
|
283
|
-
TwitterCldr.locale.
|
284
|
-
|
285
|
-
TwitterCldr.locale.
|
283
|
+
expect(TwitterCldr.locale).to eq(:pt)
|
284
|
+
expect { TwitterCldr.with_locale(:xx) {} }.to raise_error
|
285
|
+
expect(TwitterCldr.locale).to eq(:pt)
|
286
286
|
end
|
287
287
|
|
288
288
|
it "switches the locale back to the original if the block raises an error" do
|
289
|
-
TwitterCldr.locale.
|
289
|
+
expect(TwitterCldr.locale).to eq(:en)
|
290
290
|
locale_inside_block = nil
|
291
291
|
|
292
|
-
|
292
|
+
expect do
|
293
293
|
TwitterCldr.with_locale(:es) do
|
294
294
|
locale_inside_block = TwitterCldr.locale
|
295
295
|
raise "Error!"
|
296
296
|
end
|
297
|
-
end.
|
297
|
+
end.to raise_error
|
298
298
|
|
299
|
-
locale_inside_block.
|
300
|
-
TwitterCldr.locale.
|
299
|
+
expect(locale_inside_block).to eq(:es)
|
300
|
+
expect(TwitterCldr.locale).to eq(:en)
|
301
301
|
end
|
302
302
|
end
|
303
303
|
|
@@ -306,7 +306,7 @@ describe TwitterCldr do
|
|
306
306
|
resources = TwitterCldr::Resources::Loader.new
|
307
307
|
TwitterCldr.instance_variable_set(:@resources, resources)
|
308
308
|
|
309
|
-
TwitterCldr.resources.
|
309
|
+
expect(TwitterCldr.resources).to eq(resources)
|
310
310
|
end
|
311
311
|
end
|
312
312
|
|
@@ -317,7 +317,7 @@ describe TwitterCldr do
|
|
317
317
|
stub(resources).get_resource(:shared, :currencies) { 'result' }
|
318
318
|
stub(TwitterCldr).resources { resources }
|
319
319
|
|
320
|
-
TwitterCldr.get_resource(:shared, :currencies).
|
320
|
+
expect(TwitterCldr.get_resource(:shared, :currencies)).to eq('result')
|
321
321
|
end
|
322
322
|
end
|
323
323
|
|
@@ -326,7 +326,7 @@ describe TwitterCldr do
|
|
326
326
|
stub(resources).get_locale_resource(:de, :numbers) { 'result' }
|
327
327
|
stub(TwitterCldr).resources { resources }
|
328
328
|
|
329
|
-
TwitterCldr.get_locale_resource(:de, :numbers).
|
329
|
+
expect(TwitterCldr.get_locale_resource(:de, :numbers)).to eq('result')
|
330
330
|
end
|
331
331
|
end
|
332
332
|
end
|
@@ -9,53 +9,53 @@ describe TwitterCldr::Utils::CodePoints do
|
|
9
9
|
|
10
10
|
describe '#to_char' do
|
11
11
|
it 'converts unicode code points to the actual character' do
|
12
|
-
TwitterCldr::Utils::CodePoints.to_char(0x221E).
|
12
|
+
expect(TwitterCldr::Utils::CodePoints.to_char(0x221E)).to eq('∞')
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
describe '#from_char' do
|
17
17
|
it 'converts a character to a unicode code point' do
|
18
|
-
TwitterCldr::Utils::CodePoints.from_char('∞').
|
18
|
+
expect(TwitterCldr::Utils::CodePoints.from_char('∞')).to eq(0x221E)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
describe '#to_chars' do
|
23
23
|
it 'should handle an empty array' do
|
24
|
-
TwitterCldr::Utils::CodePoints.to_chars([]).
|
24
|
+
expect(TwitterCldr::Utils::CodePoints.to_chars([])).to eq([])
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'converts an array of unicode code points to an array of chars' do
|
28
|
-
TwitterCldr::Utils::CodePoints.to_chars([0x65, 0x73, 0x70]).
|
28
|
+
expect(TwitterCldr::Utils::CodePoints.to_chars([0x65, 0x73, 0x70])).to eq(%w[e s p])
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
describe '#from_chars' do
|
33
33
|
it 'should handle an empty array' do
|
34
|
-
TwitterCldr::Utils::CodePoints.from_chars([]).
|
34
|
+
expect(TwitterCldr::Utils::CodePoints.from_chars([])).to eq([])
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'converts an array of chars to an array of unicode code points' do
|
38
|
-
TwitterCldr::Utils::CodePoints.from_chars(%w[e s p]).
|
38
|
+
expect(TwitterCldr::Utils::CodePoints.from_chars(%w[e s p])).to eq([0x65, 0x73, 0x70])
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
describe '#to_string' do
|
43
43
|
it 'should handle an empty array' do
|
44
|
-
TwitterCldr::Utils::CodePoints.to_string([]).
|
44
|
+
expect(TwitterCldr::Utils::CodePoints.to_string([])).to eq('')
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'converts an array of unicode code points to a string' do
|
48
|
-
TwitterCldr::Utils::CodePoints.to_string([0x65, 0x73, 0x70, 0x61, 0xF1, 0x6F, 0x6C]).
|
48
|
+
expect(TwitterCldr::Utils::CodePoints.to_string([0x65, 0x73, 0x70, 0x61, 0xF1, 0x6F, 0x6C])).to eq('español')
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
describe '#from_string' do
|
53
53
|
it 'should handle an empty string' do
|
54
|
-
TwitterCldr::Utils::CodePoints.from_string('').
|
54
|
+
expect(TwitterCldr::Utils::CodePoints.from_string('')).to eq([])
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'converts a string into an array of unicode code points' do
|
58
|
-
TwitterCldr::Utils::CodePoints.from_string('español').
|
58
|
+
expect(TwitterCldr::Utils::CodePoints.from_string('español')).to eq([0x65, 0x73, 0x70, 0x61, 0xF1, 0x6F, 0x6C])
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|