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
@@ -14,16 +14,16 @@ describe LocalizedNumber do
|
|
14
14
|
let(:currency) { LocalizedNumber.new(10, :en, :type => :currency) }
|
15
15
|
|
16
16
|
it 'uses nil type by default (defers decision to data reader)' do
|
17
|
-
decimal.type.
|
17
|
+
expect(decimal.type).to eq(nil)
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'uses provided type if there is one' do
|
21
|
-
currency.type.
|
21
|
+
expect(currency.type).to eq(:currency)
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'sets up object with correct locale, falls back to default locale' do
|
25
|
-
LocalizedNumber.new(10, :es).locale.
|
26
|
-
LocalizedNumber.new(10, :blarg).locale.
|
25
|
+
expect(LocalizedNumber.new(10, :es).locale).to eq(:es)
|
26
|
+
expect(LocalizedNumber.new(10, :blarg).locale).to eq(TwitterCldr::DEFAULT_LOCALE)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -36,20 +36,20 @@ describe LocalizedNumber do
|
|
36
36
|
let(:method) { "to_#{type}" }
|
37
37
|
|
38
38
|
it 'creates a new object' do
|
39
|
-
number.send(method).object_id.
|
39
|
+
expect(number.send(method).object_id).not_to eq(number.object_id)
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'creates an object of the appropriate type, but does not change the type of the original object' do
|
43
43
|
new_number = currency.send(method)
|
44
|
-
new_number.type.
|
45
|
-
currency.type.
|
44
|
+
expect(new_number.type).to eq(type)
|
45
|
+
expect(currency.type).to eq(:currency)
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'creates a new object with the same base object and locale' do
|
49
49
|
percent = LocalizedNumber.new(42, :fr, :type => :percent)
|
50
50
|
new_percent = percent.send(method)
|
51
|
-
new_percent.locale.
|
52
|
-
new_percent.base_obj.
|
51
|
+
expect(new_percent.locale).to eq(:fr)
|
52
|
+
expect(new_percent.base_obj).to eq(42)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
@@ -57,20 +57,20 @@ describe LocalizedNumber do
|
|
57
57
|
|
58
58
|
describe '#to_s' do
|
59
59
|
it 'raises ArguemntError if unsupported type is passed' do
|
60
|
-
|
60
|
+
expect do
|
61
61
|
LocalizedNumber.new(10, :en, :type => :foo).to_s
|
62
|
-
end.
|
62
|
+
end.to raise_error(ArgumentError, 'Type foo is not supported')
|
63
63
|
end
|
64
64
|
|
65
65
|
context 'decimals' do
|
66
66
|
let(:number) { LocalizedNumber.new(10, :en) }
|
67
67
|
|
68
68
|
it 'should default precision to zero' do
|
69
|
-
number.to_s.
|
69
|
+
expect(number.to_s).to eq("10")
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'should not overwrite precision when explicitly passed' do
|
73
|
-
number.to_s(:precision => 2).
|
73
|
+
expect(number.to_s(:precision => 2)).to eq("10.00")
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -78,11 +78,11 @@ describe LocalizedNumber do
|
|
78
78
|
let(:number) { LocalizedNumber.new(10, :en, :type => :currency) }
|
79
79
|
|
80
80
|
it "should default to a precision of 2" do
|
81
|
-
number.to_s(:precision => 2).
|
81
|
+
expect(number.to_s(:precision => 2)).to eq("$10.00")
|
82
82
|
end
|
83
83
|
|
84
84
|
it 'should not overwrite precision when explicitly passed' do
|
85
|
-
number.to_s(:precision => 1).
|
85
|
+
expect(number.to_s(:precision => 1)).to eq("$10.0")
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
@@ -90,11 +90,11 @@ describe LocalizedNumber do
|
|
90
90
|
let(:number) { LocalizedNumber.new(10, :en, :type => :percent) }
|
91
91
|
|
92
92
|
it "should default to a precision of 0" do
|
93
|
-
number.to_s.
|
93
|
+
expect(number.to_s).to eq("10%")
|
94
94
|
end
|
95
95
|
|
96
96
|
it 'should not overwrite precision when explicitly passed' do
|
97
|
-
number.to_s(:precision => 1).
|
97
|
+
expect(number.to_s(:precision => 1)).to eq("10.0%")
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
@@ -102,11 +102,11 @@ describe LocalizedNumber do
|
|
102
102
|
let(:number) { LocalizedNumber.new(1000, :en, :type => :short_decimal) }
|
103
103
|
|
104
104
|
it "should default to a precision of 0" do
|
105
|
-
number.to_s.
|
105
|
+
expect(number.to_s).to eq("1K")
|
106
106
|
end
|
107
107
|
|
108
108
|
it 'should not overwrite precision when explicitly passed' do
|
109
|
-
number.to_s(:precision => 1).
|
109
|
+
expect(number.to_s(:precision => 1)).to eq("1.0K")
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
@@ -114,57 +114,57 @@ describe LocalizedNumber do
|
|
114
114
|
let(:number) { LocalizedNumber.new(1000, :en, :type => :long_decimal) }
|
115
115
|
|
116
116
|
it "should default to a precision of 0" do
|
117
|
-
number.to_s.
|
117
|
+
expect(number.to_s).to eq("1 thousand")
|
118
118
|
end
|
119
119
|
|
120
120
|
it 'should not overwrite precision when explicitly passed' do
|
121
|
-
number.to_s(:precision => 1).
|
121
|
+
expect(number.to_s(:precision => 1)).to eq("1.0 thousand")
|
122
122
|
end
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
126
|
describe '#plural_rule' do
|
127
127
|
it 'returns the appropriate plural rule for the number' do
|
128
|
-
1.localize(:ru).plural_rule.
|
129
|
-
2.localize(:ru).plural_rule.
|
130
|
-
5.localize(:ru).plural_rule.
|
128
|
+
expect(1.localize(:ru).plural_rule).to eq(:one)
|
129
|
+
expect(2.localize(:ru).plural_rule).to eq(:other)
|
130
|
+
expect(5.localize(:ru).plural_rule).to eq(:many)
|
131
131
|
end
|
132
132
|
|
133
133
|
it 'takes FastGettext.locale into account' do
|
134
134
|
FastGettext.locale = :es
|
135
|
-
1.localize.plural_rule.
|
136
|
-
2.localize.plural_rule.
|
137
|
-
5.localize.plural_rule.
|
135
|
+
expect(1.localize.plural_rule).to eq(:one)
|
136
|
+
expect(2.localize.plural_rule).to eq(:other)
|
137
|
+
expect(5.localize.plural_rule).to eq(:other)
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
141
|
describe 'formatters for every locale' do
|
142
142
|
it "makes sure currency formatters for every locale don't raise errors" do
|
143
143
|
TwitterCldr.supported_locales.each do |locale|
|
144
|
-
|
145
|
-
|
146
|
-
|
144
|
+
expect { 1337.localize(locale).to_currency.to_s }.not_to raise_error
|
145
|
+
expect { 1337.localize(locale).to_currency.to_s(:precision => 3) }.not_to raise_error
|
146
|
+
expect { 1337.localize(locale).to_currency.to_s(:precision => 3, :currency => "EUR") }.not_to raise_error
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
150
150
|
it "makes sure decimal formatters for every locale don't raise errors" do
|
151
151
|
TwitterCldr.supported_locales.each do |locale|
|
152
|
-
|
153
|
-
|
152
|
+
expect { 1337.localize(locale).to_decimal.to_s }.not_to raise_error
|
153
|
+
expect { 1337.localize(locale).to_decimal.to_s(:precision => 3) }.not_to raise_error
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
157
157
|
it "makes sure percentage formatters for every locale don't raise errors" do
|
158
158
|
TwitterCldr.supported_locales.each do |locale|
|
159
|
-
|
160
|
-
|
159
|
+
expect { 1337.localize(locale).to_percent.to_s }.not_to raise_error
|
160
|
+
expect { 1337.localize(locale).to_percent.to_s(:precision => 3) }.not_to raise_error
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
164
164
|
it "makes sure basic number formatters for every locale don't raise errors" do
|
165
165
|
TwitterCldr.supported_locales.each do |locale|
|
166
|
-
|
167
|
-
|
166
|
+
expect { 1337.localize(locale).to_s }.not_to raise_error
|
167
|
+
expect { 1337.localize(locale).to_s(:precision => 3) }.not_to raise_error
|
168
168
|
end
|
169
169
|
end
|
170
170
|
end
|
@@ -26,23 +26,23 @@ describe LocalizedObject do
|
|
26
26
|
let(:options) { { :foobar => 'value' } }
|
27
27
|
|
28
28
|
it 'sets base object' do
|
29
|
-
localized_object.base_obj.
|
29
|
+
expect(localized_object.base_obj).to eq(base_object)
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'sets locale' do
|
33
|
-
localized_object.locale.
|
33
|
+
expect(localized_object.locale).to eq(locale)
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'converts locale' do
|
37
|
-
LocalizedClass.new(base_object, :msa).locale.
|
37
|
+
expect(LocalizedClass.new(base_object, :msa).locale).to eq(:ms)
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'falls back to default locale if unsupported locale is passed' do
|
41
|
-
LocalizedClass.new(base_object, :foobar).locale.
|
41
|
+
expect(LocalizedClass.new(base_object, :foobar).locale).to eq(TwitterCldr::DEFAULT_LOCALE)
|
42
42
|
end
|
43
43
|
|
44
44
|
it "doesn't change original options hash" do
|
45
|
-
|
45
|
+
expect { LocalizedClass.new(base_object, locale, options) }.not_to change { options }
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -50,9 +50,9 @@ describe LocalizedObject do
|
|
50
50
|
it 'defines #localize method on a class' do
|
51
51
|
some_class = Class.new
|
52
52
|
|
53
|
-
some_class.new.
|
53
|
+
expect(some_class.new).not_to respond_to(:localize)
|
54
54
|
LocalizedClass.localize(some_class)
|
55
|
-
some_class.new.
|
55
|
+
expect(some_class.new).to respond_to(:localize)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -67,7 +67,7 @@ describe LocalizedObject do
|
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'returns localized object' do
|
70
|
-
localizable_object.localize.
|
70
|
+
expect(localizable_object.localize).to be_a(LocalizedClass)
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'accepts locale and options and pass them to the localized class constructor' do
|
@@ -11,19 +11,19 @@ describe LocalizedString do
|
|
11
11
|
describe '#%' do
|
12
12
|
context 'when argument is not a Hash' do
|
13
13
|
it 'performs regular formatting of values' do
|
14
|
-
('%d is an integer'.localize % 3.14).
|
14
|
+
expect('%d is an integer'.localize % 3.14).to eq('3 is an integer')
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'performs regular formatting of arrays' do
|
18
|
-
('"% 04d" is a %s'.localize % [12, 'number']).
|
18
|
+
expect('"% 04d" is a %s'.localize % [12, 'number']).to eq('" 012" is a number')
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'ignores pluralization placeholders' do
|
22
|
-
('%s: %{horses_count:horses}'.localize % 'total').
|
22
|
+
expect('%s: %{horses_count:horses}'.localize % 'total').to eq('total: %{horses_count:horses}')
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'raises ArgumentError when the string contains named placeholder' do
|
26
|
-
|
26
|
+
expect { '%{msg}: %{horses_count:horses}'.localize % 'total' }.to raise_error(ArgumentError)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -35,47 +35,47 @@ describe LocalizedString do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'interpolates named placeholders' do
|
38
|
-
('%<num>.2f is a %{noun}'.localize % { :num => 3.1415, :noun => 'number' }).
|
38
|
+
expect('%<num>.2f is a %{noun}'.localize % { :num => 3.1415, :noun => 'number' }).to eq('3.14 is a number')
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'performs regular pluralization' do
|
42
|
-
('%{horses_count:horses}'.localize % { :horses_count => 2, :horses => horses }).
|
42
|
+
expect('%{horses_count:horses}'.localize % { :horses_count => 2, :horses => horses }).to eq('2 horses')
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'performs inline pluralization' do
|
46
46
|
string = '%<{ "horses_count": { "other": "%{horses_count} horses" } }>'.localize
|
47
|
-
(string % { :horses_count => 2 }).
|
47
|
+
expect(string % { :horses_count => 2 }).to eq('2 horses')
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'performs both formatting and regular pluralization simultaneously' do
|
51
51
|
string = '%{msg}: %{horses_count:horses}'.localize
|
52
|
-
(string % { :horses_count => 2, :horses => horses, :msg => 'result' }).
|
52
|
+
expect(string % { :horses_count => 2, :horses => horses, :msg => 'result' }).to eq('result: 2 horses')
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'performs both formatting and inline pluralization simultaneously' do
|
56
56
|
string = '%{msg}: %<{"horses_count": {"other": "%{horses_count} horses"}}>'.localize
|
57
|
-
(string % { :horses_count => 2, :msg => 'result' }).
|
57
|
+
expect(string % { :horses_count => 2, :msg => 'result' }).to eq('result: 2 horses')
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'performs both formatted interpolation and inline pluralization simultaneously' do
|
61
61
|
string = '%<number>d, %<{"horses_count": {"other": "%{horses_count} horses" }}>'.localize
|
62
|
-
(string % { :number => 3.14, :horses_count => 2 }).
|
62
|
+
expect(string % { :number => 3.14, :horses_count => 2 }).to eq('3, 2 horses')
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'leaves regular pluralization placeholders unchanged if not enough information given' do
|
66
66
|
string = '%{msg}: %{horses_count:horses}'.localize
|
67
|
-
(string % { :msg => 'no pluralization' } ).
|
67
|
+
expect(string % { :msg => 'no pluralization' } ).to eq('no pluralization: %{horses_count:horses}')
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'leaves inline pluralization placeholders unchanged if not enough information given' do
|
71
71
|
string = '%<number>d, %<{"horses_count": {"one": "one horse"}}>'.localize
|
72
|
-
(string % { :number => 3.14, :horses_count => 2 }).
|
72
|
+
expect(string % { :number => 3.14, :horses_count => 2 }).to eq('3, %<{"horses_count": {"one": "one horse"}}>')
|
73
73
|
end
|
74
74
|
|
75
75
|
it 'raises KeyError when value for a named placeholder is missing' do
|
76
|
-
|
76
|
+
expect do
|
77
77
|
'%{msg}: %{horses_count:horses}'.localize % { :horses_count => 2, :horses => horses }
|
78
|
-
end.
|
78
|
+
end.to raise_error(KeyError)
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
@@ -85,41 +85,41 @@ describe LocalizedString do
|
|
85
85
|
string = "galoshes"
|
86
86
|
result = string.localize.to_s
|
87
87
|
|
88
|
-
result.
|
89
|
-
result.equal?(string).
|
88
|
+
expect(result).to eq(string)
|
89
|
+
expect(result.equal?(string)).not_to be_true
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
93
|
describe "#to_f" do
|
94
94
|
it "should correctly parse a number with a thousands separator" do
|
95
|
-
"1,300".localize.to_f.
|
96
|
-
"1.300".localize(:es).to_f.
|
95
|
+
expect("1,300".localize.to_f).to eq(1300.0)
|
96
|
+
expect("1.300".localize(:es).to_f).to eq(1300.0)
|
97
97
|
end
|
98
98
|
|
99
99
|
it "should correctly parse a number with a decimal separator" do
|
100
|
-
"1.300".localize.to_f.
|
101
|
-
"1,300".localize(:es).to_f.
|
100
|
+
expect("1.300".localize.to_f).to eq(1.3)
|
101
|
+
expect("1,300".localize(:es).to_f).to eq(1.3)
|
102
102
|
end
|
103
103
|
|
104
104
|
it "should correctly parse a number with a thousands and a decimal separator" do
|
105
|
-
"1,300.05".localize.to_f.
|
106
|
-
"1.300,05".localize(:es).to_f.
|
105
|
+
expect("1,300.05".localize.to_f).to eq(1300.05)
|
106
|
+
expect("1.300,05".localize(:es).to_f).to eq(1300.05)
|
107
107
|
end
|
108
108
|
|
109
109
|
it "should return zero if the string contains no numbers" do
|
110
|
-
"abc".localize.to_f.
|
110
|
+
expect("abc".localize.to_f).to eq(0.0)
|
111
111
|
end
|
112
112
|
|
113
113
|
it "should return only the numbers at the beginning of the string if the string contains any non-numeric characters" do
|
114
|
-
"1abc".localize.to_f.
|
115
|
-
"a1bc".localize.to_f.
|
114
|
+
expect("1abc".localize.to_f).to eq(1.0)
|
115
|
+
expect("a1bc".localize.to_f).to eq(0.0)
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
119
|
describe "#to_i" do
|
120
120
|
it "should chop off the decimal" do
|
121
|
-
"1,300.05".localize.to_i.
|
122
|
-
"1.300,05".localize(:es).to_i.
|
121
|
+
expect("1,300.05".localize.to_i).to eq(1300)
|
122
|
+
expect("1.300,05".localize(:es).to_i).to eq(1300)
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
@@ -129,65 +129,65 @@ describe LocalizedString do
|
|
129
129
|
let(:localized_string) { string.localize }
|
130
130
|
|
131
131
|
it 'returns a LocalizedString' do
|
132
|
-
localized_string.normalize.
|
132
|
+
expect(localized_string.normalize).to be_an_instance_of(LocalizedString)
|
133
133
|
end
|
134
134
|
|
135
135
|
it 'it uses NFD by default' do
|
136
136
|
mock(Eprun).normalize(string, :nfd) { normalized_string }
|
137
|
-
localized_string.normalize.base_obj.
|
137
|
+
expect(localized_string.normalize.base_obj).to eq(normalized_string)
|
138
138
|
end
|
139
139
|
|
140
140
|
it "uses specified algorithm if there is any" do
|
141
141
|
mock(Eprun).normalize(string, :nfkd) { normalized_string }
|
142
|
-
localized_string.normalize(:using => :NFKD).base_obj.
|
142
|
+
expect(localized_string.normalize(:using => :NFKD).base_obj).to eq(normalized_string)
|
143
143
|
end
|
144
144
|
|
145
145
|
it "raises an ArgumentError if passed an unsupported normalization form" do
|
146
|
-
|
146
|
+
expect { localized_string.normalize(:using => :blarg) }.to raise_error(ArgumentError)
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
150
150
|
describe "#casefold" do
|
151
151
|
it 'returns a LocalizedString' do
|
152
152
|
str = "Weißrussland".localize.casefold
|
153
|
-
str.
|
154
|
-
str.to_s.
|
153
|
+
expect(str).to be_an_instance_of(LocalizedString)
|
154
|
+
expect(str.to_s).to eq("weissrussland")
|
155
155
|
end
|
156
156
|
|
157
157
|
it 'does not pass the t option by default' do
|
158
|
-
"Istanbul".localize.casefold.to_s.
|
158
|
+
expect("Istanbul".localize.casefold.to_s).to eq("istanbul")
|
159
159
|
end
|
160
160
|
|
161
161
|
it 'uses the t option when explicitly given' do
|
162
|
-
"Istanbul".localize.casefold(:t => true).to_s.
|
162
|
+
expect("Istanbul".localize.casefold(:t => true).to_s).to eq("ıstanbul")
|
163
163
|
end
|
164
164
|
|
165
165
|
it 'uses t by default if the locale is tr (az not supported)' do
|
166
|
-
"Istanbul".localize(:tr).casefold.to_s.
|
166
|
+
expect("Istanbul".localize(:tr).casefold.to_s).to eq("ıstanbul")
|
167
167
|
end
|
168
168
|
end
|
169
169
|
|
170
170
|
describe "#each_sentence" do
|
171
171
|
it "returns an enumerator if not passed a block" do
|
172
|
-
"foo bar".localize.each_sentence.
|
172
|
+
expect("foo bar".localize.each_sentence).to be_a(Enumerator)
|
173
173
|
end
|
174
174
|
|
175
175
|
it "yields sentences as localized strings" do
|
176
176
|
str = "Quick. Brown. Fox.".localize
|
177
177
|
|
178
178
|
str.each_sentence do |sentence|
|
179
|
-
sentence.
|
179
|
+
expect(sentence).to be_a(LocalizedString)
|
180
180
|
end
|
181
181
|
|
182
|
-
str.each_sentence.to_a.map(&:to_s).
|
182
|
+
expect(str.each_sentence.to_a.map(&:to_s)).to eq([
|
183
183
|
"Quick.", " Brown.", " Fox."
|
184
|
-
]
|
184
|
+
])
|
185
185
|
end
|
186
186
|
end
|
187
187
|
|
188
188
|
describe "#code_points" do
|
189
189
|
it "returns an array of Unicode code points for the string" do
|
190
|
-
"español".localize.code_points.
|
190
|
+
expect("español".localize.code_points).to eq([0x65, 0x73, 0x70, 0x61, 0xF1, 0x6F, 0x6C])
|
191
191
|
end
|
192
192
|
end
|
193
193
|
|
@@ -197,34 +197,34 @@ describe LocalizedString do
|
|
197
197
|
str = "twitter"
|
198
198
|
|
199
199
|
str.localize.each_char do |char|
|
200
|
-
str.chars.to_a[index].
|
200
|
+
expect(str.chars.to_a[index]).to eq(char)
|
201
201
|
index += 1
|
202
202
|
end
|
203
203
|
end
|
204
204
|
|
205
205
|
it "returns an enumerator if no block is given" do
|
206
|
-
"twitter".localize.each_char.
|
206
|
+
expect("twitter".localize.each_char).to be_a(Enumerator)
|
207
207
|
end
|
208
208
|
|
209
209
|
it "responds to a few other methods from Enumerable" do
|
210
210
|
upcased = "twitter".localize.map { |letter| letter.upcase }
|
211
|
-
upcased.size.
|
212
|
-
upcased.join.
|
211
|
+
expect(upcased.size).to eq(7)
|
212
|
+
expect(upcased.join).to eq("TWITTER")
|
213
213
|
|
214
|
-
"twitter".localize.inject("") { |str, letter| str = "#{letter}#{str}"; str }.
|
214
|
+
expect("twitter".localize.inject("") { |str, letter| str = "#{letter}#{str}"; str }).to eq("rettiwt")
|
215
215
|
end
|
216
216
|
end
|
217
217
|
|
218
218
|
describe "#to_yaml" do
|
219
219
|
it "should be able to successfully roundtrip the string" do
|
220
|
-
YAML.load("coolio".localize.to_yaml).
|
221
|
-
YAML.load("coolió".localize.to_yaml).
|
220
|
+
expect(YAML.load("coolio".localize.to_yaml)).to eq("coolio")
|
221
|
+
expect(YAML.load("coolió".localize.to_yaml)).to eq("coolió")
|
222
222
|
end
|
223
223
|
end
|
224
224
|
|
225
225
|
describe "#to_bidi" do
|
226
226
|
it "should return an instance of TwitterCldr::Shared::Bidi" do
|
227
|
-
"abc".localize.to_bidi.
|
227
|
+
expect("abc".localize.to_bidi).to be_a(TwitterCldr::Shared::Bidi)
|
228
228
|
end
|
229
229
|
end
|
230
230
|
|
@@ -232,13 +232,13 @@ describe LocalizedString do
|
|
232
232
|
it "should reverse the order a basic RTL string" do
|
233
233
|
str = "{0} \331\210 {1}".gsub("{0}", "a").gsub("{1}", "b")
|
234
234
|
chars = str.chars.to_a
|
235
|
-
chars.first.
|
236
|
-
chars.last.
|
235
|
+
expect(chars.first).to eq("a")
|
236
|
+
expect(chars.last).to eq("b")
|
237
237
|
|
238
238
|
result = str.localize.to_reordered_s(:direction => :RTL)
|
239
239
|
result_chars = result.chars.to_a
|
240
|
-
result_chars.first.
|
241
|
-
result_chars.last.
|
240
|
+
expect(result_chars.first).to eq("b")
|
241
|
+
expect(result_chars.last).to eq("a")
|
242
242
|
end
|
243
243
|
end
|
244
244
|
|
@@ -11,27 +11,27 @@ describe LocalizedSymbol do
|
|
11
11
|
|
12
12
|
describe "#as_language_code" do
|
13
13
|
it "returns the correct localized language from the symbol" do
|
14
|
-
:es.localize.as_language_code.
|
14
|
+
expect(:es.localize.as_language_code).to eq("Spanish")
|
15
15
|
TwitterCldr.locale = :es
|
16
|
-
:es.localize.as_language_code.
|
16
|
+
expect(:es.localize.as_language_code).to eq("español")
|
17
17
|
end
|
18
18
|
|
19
19
|
it "returns nil if the symbol doesn't correspond to a language code" do
|
20
|
-
:blarg.localize.as_language_code.
|
20
|
+
expect(:blarg.localize.as_language_code).to eq(nil)
|
21
21
|
end
|
22
22
|
|
23
23
|
it "returns the correct value for mapped as well as CLDR language codes" do
|
24
|
-
:'zh-cn'.localize.as_language_code.
|
25
|
-
:'zh-tw'.localize.as_language_code.
|
26
|
-
:'zh-Hant'.localize.as_language_code.
|
27
|
-
:'zh'.localize.as_language_code.
|
24
|
+
expect(:'zh-cn'.localize.as_language_code).to eq("Chinese")
|
25
|
+
expect(:'zh-tw'.localize.as_language_code).to eq("Traditional Chinese")
|
26
|
+
expect(:'zh-Hant'.localize.as_language_code).to eq("Traditional Chinese")
|
27
|
+
expect(:'zh'.localize.as_language_code).to eq("Chinese")
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
describe "#is_rtl?" do
|
32
32
|
it "should return true or false depending on the locale" do
|
33
|
-
:es.localize.is_rtl
|
34
|
-
:ar.localize.is_rtl
|
33
|
+
expect(:es.localize.is_rtl?).to be_false
|
34
|
+
expect(:ar.localize.is_rtl?).to be_true
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -20,7 +20,7 @@ describe LocalizedTime do
|
|
20
20
|
|
21
21
|
it "should stringify with buddhist calendar" do
|
22
22
|
# Ensure that buddhist calendar data is present in th locale.
|
23
|
-
TwitterCldr.get_locale_resource(:th, :calendars)[:th][:calendars][:buddhist].
|
23
|
+
expect(TwitterCldr.get_locale_resource(:th, :calendars)[:th][:calendars][:buddhist]).not_to(
|
24
24
|
be_nil, 'buddhist calendar is missing for :th locale (check resources/locales/th/calendars.yml)'
|
25
25
|
)
|
26
26
|
|
@@ -33,7 +33,7 @@ describe LocalizedTime do
|
|
33
33
|
|
34
34
|
describe "#ago" do
|
35
35
|
it "should return a localized timespan" do
|
36
|
-
time.localize(:de).ago.
|
36
|
+
expect(time.localize(:de).ago).to be_a(LocalizedTimespan)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -42,16 +42,16 @@ describe LocalizedTime do
|
|
42
42
|
date = Date.new(1987, 9, 20)
|
43
43
|
time = Time.local(2000, 5, 12, 22, 5)
|
44
44
|
datetime = time.localize.to_datetime(date)
|
45
|
-
datetime.
|
46
|
-
datetime.base_obj.strftime("%Y-%m-%d %H:%M:%S").
|
45
|
+
expect(datetime).to be_a(LocalizedDateTime)
|
46
|
+
expect(datetime.base_obj.strftime("%Y-%m-%d %H:%M:%S")).to eq("1987-09-20 22:05:00")
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should work with an instance of LocalizedDate too" do
|
50
50
|
date = DateTime.new(1987, 9, 20, 0, 0, 0).localize.to_date
|
51
51
|
time = Time.local(2000, 5, 12, 22, 5)
|
52
52
|
datetime = time.localize.to_datetime(date)
|
53
|
-
datetime.
|
54
|
-
datetime.base_obj.strftime("%Y-%m-%d %H:%M:%S").
|
53
|
+
expect(datetime).to be_a(LocalizedDateTime)
|
54
|
+
expect(datetime.base_obj.strftime("%Y-%m-%d %H:%M:%S")).to eq("1987-09-20 22:05:00")
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -59,7 +59,7 @@ describe LocalizedTime do
|
|
59
59
|
it "don't raise errors for any locale" do
|
60
60
|
TwitterCldr.supported_locales.each do |locale|
|
61
61
|
(CalendarDataReader.types - [:additional]).each do |type|
|
62
|
-
|
62
|
+
expect { Time.now.localize(locale).send(:"to_#{type}_s") }.not_to raise_error
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
@@ -68,9 +68,9 @@ describe LocalizedTime do
|
|
68
68
|
describe "#with_timezone" do
|
69
69
|
it "calculates the right time depending on the timezone" do
|
70
70
|
time = Time.utc(2000, 5, 12, 22, 5).localize
|
71
|
-
time.to_s.
|
72
|
-
time.with_timezone("America/Los_Angeles").to_s.
|
73
|
-
time.with_timezone("America/New_York").to_s.
|
71
|
+
expect(time.to_s).to eq("10:05:00 PM")
|
72
|
+
expect(time.with_timezone("America/Los_Angeles").to_s).to eq("3:05:00 PM")
|
73
|
+
expect(time.with_timezone("America/New_York").to_s).to eq("6:05:00 PM")
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|