twitter_cldr 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +6 -0
- data/README.md +61 -5
- data/Rakefile +64 -60
- data/js/lib/twitter_cldr_js.rb +0 -2
- data/lib/twitter_cldr/core_ext.rb +12 -12
- data/lib/twitter_cldr/formatters/calendars/timespan_formatter.rb +13 -11
- data/lib/twitter_cldr/localized/localized_array.rb +33 -0
- data/lib/twitter_cldr/localized/localized_date.rb +23 -0
- data/lib/twitter_cldr/localized/localized_datetime.rb +63 -0
- data/lib/twitter_cldr/localized/localized_number.rb +50 -0
- data/lib/twitter_cldr/localized/localized_object.rb +38 -0
- data/lib/twitter_cldr/localized/localized_string.rb +41 -0
- data/lib/twitter_cldr/localized/localized_symbol.rb +20 -0
- data/lib/twitter_cldr/localized/localized_time.rb +23 -0
- data/lib/twitter_cldr/localized/localized_timespan.rb +26 -0
- data/lib/twitter_cldr/localized.rb +18 -0
- data/lib/twitter_cldr/normalization.rb +23 -0
- data/lib/twitter_cldr/resources/{tries_dumper.rb → collation_tries_dumper.rb} +1 -1
- data/lib/twitter_cldr/resources/composition_exclusions_importer.rb +1 -1
- data/lib/twitter_cldr/resources/language_codes_importer.rb +232 -0
- data/lib/twitter_cldr/resources/locales_resources_importer.rb +1 -1
- data/lib/twitter_cldr/resources/phone_codes_importer.rb +1 -1
- data/lib/twitter_cldr/resources/postal_codes_importer.rb +1 -1
- data/lib/twitter_cldr/resources/tailoring_importer.rb +12 -3
- data/lib/twitter_cldr/resources/unicode_data_importer.rb +3 -1
- data/lib/twitter_cldr/resources.rb +2 -1
- data/lib/twitter_cldr/shared/calendar.rb +2 -6
- data/lib/twitter_cldr/shared/language_codes.rb +75 -0
- data/lib/twitter_cldr/shared/languages.rb +4 -11
- data/lib/twitter_cldr/shared.rb +8 -7
- data/lib/twitter_cldr/tokenizers/base.rb +2 -8
- data/lib/twitter_cldr/utils.rb +8 -0
- data/lib/twitter_cldr/version.rb +1 -1
- data/lib/twitter_cldr.rb +5 -4
- data/resources/custom/locales/cs/units.yml +3 -3
- data/resources/custom/locales/pl/units.yml +4 -4
- data/resources/custom/locales/pt/units.yml +2 -2
- data/resources/shared/language_codes_table.dump +0 -0
- data/spec/core_ext_spec.rb +19 -0
- data/spec/{core_ext/array_spec.rb → localized/localized_array_spec.rb} +1 -1
- data/spec/{core_ext/calendars/date_spec.rb → localized/localized_date_spec.rb} +24 -44
- data/spec/localized/localized_datetime_spec.rb +81 -0
- data/spec/{core_ext/numbers → localized}/localized_number_spec.rb +34 -1
- data/spec/localized/localized_object_spec.rb +89 -0
- data/spec/{core_ext/string_spec.rb → localized/localized_string_spec.rb} +16 -33
- data/spec/{core_ext/symbol_spec.rb → localized/localized_symbol_spec.rb} +3 -1
- data/spec/localized/localized_time_spec.rb +70 -0
- data/spec/normalization_spec.rb +42 -0
- data/spec/readme_spec.rb +51 -5
- data/spec/shared/language_codes_spec.rb +161 -0
- data/spec/shared/phone_codes_spec.rb +2 -2
- data/spec/shared/postal_codes_spec.rb +2 -2
- data/spec/spec_helper.rb +2 -0
- data/spec/tokenizers/base_spec.rb +15 -6
- data/spec/utils_spec.rb +18 -2
- data/twitter_cldr.gemspec +2 -1
- metadata +28 -44
- data/lib/twitter_cldr/core_ext/array.rb +0 -35
- data/lib/twitter_cldr/core_ext/calendars/date.rb +0 -25
- data/lib/twitter_cldr/core_ext/calendars/datetime.rb +0 -65
- data/lib/twitter_cldr/core_ext/calendars/time.rb +0 -25
- data/lib/twitter_cldr/core_ext/calendars/timespan.rb +0 -24
- data/lib/twitter_cldr/core_ext/localized_object.rb +0 -25
- data/lib/twitter_cldr/core_ext/numbers/bignum.rb +0 -8
- data/lib/twitter_cldr/core_ext/numbers/fixnum.rb +0 -8
- data/lib/twitter_cldr/core_ext/numbers/float.rb +0 -8
- data/lib/twitter_cldr/core_ext/numbers/localized_number.rb +0 -54
- data/lib/twitter_cldr/core_ext/string.rb +0 -51
- data/lib/twitter_cldr/core_ext/symbol.rb +0 -22
- data/spec/core_ext/calendars/datetime_spec.rb +0 -90
- data/spec/core_ext/calendars/time_spec.rb +0 -90
- data/spec/core_ext/calendars_spec.rb +0 -34
- data/spec/core_ext/numbers/bignum_spec.rb +0 -25
- data/spec/core_ext/numbers/fixnum_spec.rb +0 -25
- data/spec/core_ext/numbers/float_spec.rb +0 -25
- data/spec/core_ext/numbers_spec.rb +0 -39
@@ -0,0 +1,81 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
require 'spec_helper'
|
7
|
+
|
8
|
+
include TwitterCldr::Localized
|
9
|
+
|
10
|
+
describe LocalizedDateTime do
|
11
|
+
|
12
|
+
let(:date_time) { DateTime.new(1987, 9, 20, 22, 5) }
|
13
|
+
|
14
|
+
describe '#initilize' do
|
15
|
+
it 'sets calendar type' do
|
16
|
+
date_time.localize(:th, :calendar_type => :buddhist).calendar_type.should == :buddhist
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'uses default calendar type' do
|
20
|
+
date_time.localize(:en).calendar_type.should == TwitterCldr::DEFAULT_CALENDAR_TYPE
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "stringify" do
|
25
|
+
it "should stringify with a default calendar" do
|
26
|
+
#date_time.localize(:th, :calendar_type => :buddhist).to_full_s # It doesn't support era
|
27
|
+
date_time.localize(:th).to_long_s
|
28
|
+
date_time.localize(:th).to_medium_s
|
29
|
+
date_time.localize(:th).to_short_s
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should stringify with buddhist calendar" do
|
33
|
+
# Ensure that buddhist calendar data is present in th locale.
|
34
|
+
TwitterCldr.get_locale_resource(:th, :calendars)[:th][:calendars][:buddhist].should_not(
|
35
|
+
be_nil, 'buddhist calendar is missing for :th locale (check resources/locales/th/calendars.yml)'
|
36
|
+
)
|
37
|
+
|
38
|
+
#date_time.localize(:th, :calendar_type => :buddhist).to_full_s # It doesn't support era
|
39
|
+
date_time.localize(:th, :calendar_type => :buddhist).to_long_s
|
40
|
+
date_time.localize(:th, :calendar_type => :buddhist).to_medium_s
|
41
|
+
date_time.localize(:th, :calendar_type => :buddhist).to_short_s
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#to_date" do
|
46
|
+
it "should convert to a date" do
|
47
|
+
date_time.localize.to_date.base_obj.strftime("%Y-%m-%d").should == "1987-09-20"
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'forwards calendar type' do
|
51
|
+
date_time.localize(:th, :calendar_type => :buddhist).to_date.calendar_type == :buddhist
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#to_time" do
|
56
|
+
it "should convert to a time" do
|
57
|
+
date_time.localize.to_time.base_obj.getgm.strftime("%H:%M:%S").should == "22:05:00"
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'forwards calendar type' do
|
61
|
+
date_time.localize(:th, :calendar_type => :buddhist).to_time.calendar_type == :buddhist
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#to_timespan" do
|
66
|
+
it "should return a localized timespan with a direction of :none" do
|
67
|
+
date_time.localize.to_timespan.formatter.instance_variable_get(:'@direction').should == :none
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'formatters' do
|
72
|
+
it "don't raise errors for any locale" do
|
73
|
+
TwitterCldr.supported_locales.each do |locale|
|
74
|
+
TwitterCldr::Tokenizers::DateTimeTokenizer::VALID_TYPES.each do |type|
|
75
|
+
lambda { DateTime.now.localize(locale).send(:"to_#{type}_s") }.should_not raise_error
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -8,6 +8,7 @@ require 'spec_helper'
|
|
8
8
|
include TwitterCldr
|
9
9
|
|
10
10
|
describe LocalizedNumber do
|
11
|
+
|
11
12
|
describe '#initialize' do
|
12
13
|
let(:decimal) { LocalizedNumber.new(10, :en) }
|
13
14
|
let(:currency) { LocalizedNumber.new(10, :en, :type => :currency) }
|
@@ -58,7 +59,7 @@ describe LocalizedNumber do
|
|
58
59
|
|
59
60
|
it 'creates a new object with the same base object and locale' do
|
60
61
|
percent = LocalizedNumber.new(42, :fr, :type => :percent)
|
61
|
-
mock.proxy(TwitterCldr::LocalizedNumber).new(42, :fr, :type => type)
|
62
|
+
mock.proxy(TwitterCldr::Localized::LocalizedNumber).new(42, :fr, :type => type)
|
62
63
|
percent.send(method)
|
63
64
|
end
|
64
65
|
end
|
@@ -123,4 +124,36 @@ describe LocalizedNumber do
|
|
123
124
|
5.localize.plural_rule.should == :other
|
124
125
|
end
|
125
126
|
end
|
127
|
+
|
128
|
+
describe 'formatters for every locale' do
|
129
|
+
it "makes sure currency formatters for every locale don't raise errors" do
|
130
|
+
TwitterCldr.supported_locales.each do |locale|
|
131
|
+
lambda { 1337.localize(locale).to_currency.to_s }.should_not raise_error
|
132
|
+
lambda { 1337.localize(locale).to_currency.to_s(:precision => 3) }.should_not raise_error
|
133
|
+
lambda { 1337.localize(locale).to_currency.to_s(:precision => 3, :currency => "EUR") }.should_not raise_error
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
it "makes sure decimal formatters for every locale don't raise errors" do
|
138
|
+
TwitterCldr.supported_locales.each do |locale|
|
139
|
+
lambda { 1337.localize(locale).to_decimal.to_s }.should_not raise_error
|
140
|
+
lambda { 1337.localize(locale).to_decimal.to_s(:precision => 3) }.should_not raise_error
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
it "makes sure percentage formatters for every locale don't raise errors" do
|
145
|
+
TwitterCldr.supported_locales.each do |locale|
|
146
|
+
lambda { 1337.localize(locale).to_percent.to_s }.should_not raise_error
|
147
|
+
lambda { 1337.localize(locale).to_percent.to_s(:precision => 3) }.should_not raise_error
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
it "makes sure basic number formatters for every locale don't raise errors" do
|
152
|
+
TwitterCldr.supported_locales.each do |locale|
|
153
|
+
lambda { 1337.localize(locale).to_s }.should_not raise_error
|
154
|
+
lambda { 1337.localize(locale).to_s(:precision => 3) }.should_not raise_error
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
126
159
|
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
require 'spec_helper'
|
7
|
+
|
8
|
+
include TwitterCldr::Localized
|
9
|
+
|
10
|
+
describe LocalizedObject do
|
11
|
+
|
12
|
+
class LocalizedFormatter
|
13
|
+
def initialize(options); end
|
14
|
+
end
|
15
|
+
|
16
|
+
class LocalizedClass < LocalizedObject
|
17
|
+
def formatter_const
|
18
|
+
LocalizedFormatter
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#initialize' do
|
23
|
+
let(:base_object) { 'base-object' }
|
24
|
+
let(:locale) { :fr }
|
25
|
+
let(:localized_object) { LocalizedClass.new(base_object, locale) }
|
26
|
+
let(:options) { { :foobar => 'value' } }
|
27
|
+
|
28
|
+
it 'sets base object' do
|
29
|
+
localized_object.base_obj.should == base_object
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'sets locale' do
|
33
|
+
localized_object.locale.should == locale
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'converts locale' do
|
37
|
+
LocalizedClass.new(base_object, :msa).locale.should == :ms
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'falls back to default locale if unsupported locale is passed' do
|
41
|
+
LocalizedClass.new(base_object, :foobar).locale.should == TwitterCldr::DEFAULT_LOCALE
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'passes options (including locale) to formatter' do
|
45
|
+
mock(LocalizedFormatter).new(options.merge(:locale => locale))
|
46
|
+
LocalizedClass.new(base_object, locale, options)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "doesn't change original options hash" do
|
50
|
+
lambda { LocalizedClass.new(base_object, locale, options) }.should_not change { options }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '.localize' do
|
55
|
+
it 'defines #localize method on a class' do
|
56
|
+
some_class = Class.new
|
57
|
+
|
58
|
+
some_class.new.should_not respond_to(:localize)
|
59
|
+
LocalizedClass.localize(some_class)
|
60
|
+
some_class.new.should respond_to(:localize)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#localize' do
|
65
|
+
let(:locale) { :ru }
|
66
|
+
let(:options) { { :option => 'value' } }
|
67
|
+
|
68
|
+
let(:localizable_object) do
|
69
|
+
some_class = Class.new
|
70
|
+
LocalizedClass.localize(some_class)
|
71
|
+
some_class.new
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'returns localized object' do
|
75
|
+
localizable_object.localize.should be_a(LocalizedClass)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'accepts locale and options and pass them to the localized class constructor' do
|
79
|
+
mock(LocalizedClass).new(localizable_object, locale, options)
|
80
|
+
localizable_object.localize(locale, options)
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'uses default locale and empty options hash by default' do
|
84
|
+
mock(LocalizedClass).new(localizable_object, TwitterCldr.get_locale, {})
|
85
|
+
localizable_object.localize
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
@@ -5,26 +5,7 @@
|
|
5
5
|
|
6
6
|
require 'spec_helper'
|
7
7
|
|
8
|
-
include TwitterCldr
|
9
|
-
|
10
|
-
describe String do
|
11
|
-
|
12
|
-
describe '#localize' do
|
13
|
-
it 'returns localized string object' do
|
14
|
-
'foo'.localize.should be_a(LocalizedString)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "uses default locale if it's not explicitly specified" do
|
18
|
-
mock(TwitterCldr).get_locale { :ja }
|
19
|
-
'foo'.localize.locale.should == :ja
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'uses provided locale if there is one' do
|
23
|
-
'foo'.localize(:ru).locale.should == :ru
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
8
|
+
include TwitterCldr::Localized
|
28
9
|
|
29
10
|
describe LocalizedString do
|
30
11
|
describe '#%' do
|
@@ -110,24 +91,26 @@ describe LocalizedString do
|
|
110
91
|
end
|
111
92
|
|
112
93
|
describe "#normalize" do
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
94
|
+
let(:string) { 'string' }
|
95
|
+
let(:normalized_string) { 'normalized' }
|
96
|
+
let(:localized_string) { string.localize }
|
97
|
+
|
98
|
+
it 'returns a LocalizedString' do
|
99
|
+
localized_string.normalize.should be_an_instance_of(LocalizedString)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'it uses NFD by default' do
|
103
|
+
mock(TwitterCldr::Normalization::NFD).normalize(string) { normalized_string }
|
104
|
+
localized_string.normalize.base_obj.should == normalized_string
|
119
105
|
end
|
120
106
|
|
121
|
-
it "
|
122
|
-
mock
|
123
|
-
|
124
|
-
result = "español".localize.normalize(:using => :NFKD)
|
125
|
-
result.should be_a(LocalizedString)
|
126
|
-
result.to_s.bytes.to_a.should == [101, 115, 112, 97, 110, 204, 131, 111, 108]
|
107
|
+
it "uses specified algorithm if there is any" do
|
108
|
+
mock(TwitterCldr::Normalization::NFKD).normalize(string) { normalized_string }
|
109
|
+
localized_string.normalize(:using => :NFKD).base_obj.should == normalized_string
|
127
110
|
end
|
128
111
|
|
129
112
|
it "raises an ArgumentError if passed an unsupported normalization form" do
|
130
|
-
lambda {
|
113
|
+
lambda { localized_string.normalize(:using => :blarg) }.should raise_error(ArgumentError)
|
131
114
|
end
|
132
115
|
end
|
133
116
|
|
@@ -5,9 +5,10 @@
|
|
5
5
|
|
6
6
|
require 'spec_helper'
|
7
7
|
|
8
|
-
include TwitterCldr
|
8
|
+
include TwitterCldr::Localized
|
9
9
|
|
10
10
|
describe LocalizedSymbol do
|
11
|
+
|
11
12
|
describe "#as_language_code" do
|
12
13
|
it "returns the correct localized language from the symbol" do
|
13
14
|
:es.localize.as_language_code.should == "Spanish"
|
@@ -26,4 +27,5 @@ describe LocalizedSymbol do
|
|
26
27
|
:'zh'.localize.as_language_code.should == "Chinese"
|
27
28
|
end
|
28
29
|
end
|
30
|
+
|
29
31
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
require 'spec_helper'
|
7
|
+
|
8
|
+
include TwitterCldr::Localized
|
9
|
+
|
10
|
+
describe LocalizedTime do
|
11
|
+
let(:time) { Time.now }
|
12
|
+
|
13
|
+
describe "stringify" do
|
14
|
+
it "should stringify with a default calendar" do
|
15
|
+
#time.localize(:th, :calendar_type => :buddhist).to_full_s # It doesn't support era
|
16
|
+
time.localize(:th).to_long_s
|
17
|
+
time.localize(:th).to_medium_s
|
18
|
+
time.localize(:th).to_short_s
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should stringify with buddhist calendar" do
|
22
|
+
# Ensure that buddhist calendar data is present in th locale.
|
23
|
+
TwitterCldr.get_locale_resource(:th, :calendars)[:th][:calendars][:buddhist].should_not(
|
24
|
+
be_nil, 'buddhist calendar is missing for :th locale (check resources/locales/th/calendars.yml)'
|
25
|
+
)
|
26
|
+
|
27
|
+
#time.localize(:th, :calendar_type => :buddhist).to_full_s # It doesn't support era
|
28
|
+
time.localize(:th, :calendar_type => :buddhist).to_long_s
|
29
|
+
time.localize(:th, :calendar_type => :buddhist).to_medium_s
|
30
|
+
time.localize(:th, :calendar_type => :buddhist).to_short_s
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#ago" do
|
35
|
+
it "should ago-ify a time with a number of different units" do
|
36
|
+
base_time = time + 172800
|
37
|
+
loc_time = time.localize(:de)
|
38
|
+
loc_time.ago(:base_time => base_time).to_s(:unit => :hour).should match_normalized("Vor 48 Stunden")
|
39
|
+
loc_time.ago(:base_time => base_time).to_s(:unit => :day).should match_normalized("Vor 2 Tagen")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#to_datetime" do
|
44
|
+
it "should combine a date and a time object into a datetime" do
|
45
|
+
date = Date.new(1987, 9, 20)
|
46
|
+
time = Time.local(2000, 5, 12, 22, 5)
|
47
|
+
datetime = time.localize.to_datetime(date)
|
48
|
+
datetime.should be_a(LocalizedDateTime)
|
49
|
+
datetime.base_obj.strftime("%Y-%m-%d %H:%M:%S").should == "1987-09-20 22:05:00"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should work with an instance of LocalizedDate too" do
|
53
|
+
date = Date.new(1987, 9, 20).localize
|
54
|
+
time = Time.local(2000, 5, 12, 22, 5)
|
55
|
+
datetime = time.localize.to_datetime(date)
|
56
|
+
datetime.should be_a(LocalizedDateTime)
|
57
|
+
datetime.base_obj.strftime("%Y-%m-%d %H:%M:%S").should == "1987-09-20 22:05:00"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'formatters' do
|
62
|
+
it "don't raise errors for any locale" do
|
63
|
+
TwitterCldr.supported_locales.each do |locale|
|
64
|
+
TwitterCldr::Tokenizers::DateTimeTokenizer::VALID_TYPES.each do |type|
|
65
|
+
lambda { Time.now.localize(locale).send(:"to_#{type}_s") }.should_not raise_error
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
require 'spec_helper'
|
7
|
+
|
8
|
+
include TwitterCldr
|
9
|
+
|
10
|
+
describe TwitterCldr::Normalization do
|
11
|
+
|
12
|
+
describe "#normalize" do
|
13
|
+
let(:string) { 'string' }
|
14
|
+
let(:normalized_string) { 'normalized' }
|
15
|
+
|
16
|
+
it 'it uses NFD by default' do
|
17
|
+
mock(TwitterCldr::Normalization::NFD).normalize(string) { normalized_string }
|
18
|
+
Normalization.normalize(string).should == normalized_string
|
19
|
+
end
|
20
|
+
|
21
|
+
it "uses specified algorithm if there is any" do
|
22
|
+
mock(TwitterCldr::Normalization::NFKD).normalize(string) { normalized_string }
|
23
|
+
Normalization.normalize(string, :using => :NFKD).should == normalized_string
|
24
|
+
end
|
25
|
+
|
26
|
+
it "raises an ArgumentError if passed an unsupported normalizer name" do
|
27
|
+
lambda { Normalization.normalize(string, :using => :blarg) }.should raise_error(ArgumentError)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'accepts normalizer name in a lower case' do
|
31
|
+
mock(TwitterCldr::Normalization::NFKD).normalize(string) { normalized_string }
|
32
|
+
Normalization.normalize(string, :using => :nfkd).should == normalized_string
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'accepts a string' do
|
36
|
+
mock(TwitterCldr::Normalization::NFKD).normalize(string) { normalized_string }
|
37
|
+
Normalization.normalize(string, :using => 'NFKD').should == normalized_string
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/spec/readme_spec.rb
CHANGED
@@ -31,7 +31,7 @@ describe "README" do
|
|
31
31
|
1337.localize(:es).to_percent.to_s(:precision => 2).should == "1.337,00%"
|
32
32
|
1337.localize(:es).to_decimal.to_s(:precision => 3).should == "1.337,000"
|
33
33
|
|
34
|
-
num = TwitterCldr::LocalizedNumber.new(1337, :es)
|
34
|
+
num = TwitterCldr::Localized::LocalizedNumber.new(1337, :es)
|
35
35
|
spaces(num.to_currency.to_s).should == "1.337,00 $"
|
36
36
|
end
|
37
37
|
|
@@ -70,7 +70,7 @@ describe "README" do
|
|
70
70
|
time.localize(:es).to_medium_s.should == "21:44:57"
|
71
71
|
time.localize(:es).to_short_s.should == "21:44"
|
72
72
|
|
73
|
-
dt = TwitterCldr::LocalizedDateTime.new(date_time, :es)
|
73
|
+
dt = TwitterCldr::Localized::LocalizedDateTime.new(date_time, :es)
|
74
74
|
dt.to_short_s.should == "12/12/11 21:44"
|
75
75
|
end
|
76
76
|
|
@@ -90,11 +90,11 @@ describe "README" do
|
|
90
90
|
# 86400 = 1 day in seconds, 259200 = 3 days in seconds
|
91
91
|
(Time.now + 86400).localize(:de).ago(:base_time => (Time.now + 259200)).to_s(:unit => :hour).should match_normalized("Vor 48 Stunden")
|
92
92
|
|
93
|
-
ts = TwitterCldr::LocalizedTimespan.new(86400, :locale => :de)
|
93
|
+
ts = TwitterCldr::Localized::LocalizedTimespan.new(86400, :locale => :de)
|
94
94
|
ts.to_s.should match_normalized("In 1 Tag")
|
95
95
|
ts.to_s(:unit => :hour).should match_normalized("In 24 Stunden")
|
96
96
|
|
97
|
-
ts = TwitterCldr::LocalizedTimespan.new(-86400, :locale => :de)
|
97
|
+
ts = TwitterCldr::Localized::LocalizedTimespan.new(-86400, :locale => :de)
|
98
98
|
ts.to_s.should match_normalized("Vor 1 Tag")
|
99
99
|
ts.to_s(:unit => :hour).should match_normalized("Vor 24 Stunden")
|
100
100
|
end
|
@@ -140,10 +140,56 @@ describe "README" do
|
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
|
+
it "verifies language code conversion" do
|
144
|
+
TwitterCldr::Shared::LanguageCodes.convert(:es, :from => :bcp_47, :to => :iso_639_2).should == :spa
|
145
|
+
|
146
|
+
expected = [:bcp_47, :iso_639_1, :iso_639_2, :iso_639_3]
|
147
|
+
actual = TwitterCldr::Shared::LanguageCodes.standards_for(:es, :bcp_47)
|
148
|
+
expected.size.should == actual.size
|
149
|
+
actual.each { |standard| expected.should include(standard) }
|
150
|
+
|
151
|
+
expected = [:bcp_47, :iso_639_1, :iso_639_2, :iso_639_3]
|
152
|
+
actual = TwitterCldr::Shared::LanguageCodes.standards_for_language(:Spanish)
|
153
|
+
expected.size.should == actual.size
|
154
|
+
actual.each { |standard| expected.should include(standard) }
|
155
|
+
|
156
|
+
TwitterCldr::Shared::LanguageCodes.languages.should include(:Spanish)
|
157
|
+
|
158
|
+
TwitterCldr::Shared::LanguageCodes.valid_standard?(:iso_639_1).should be_true
|
159
|
+
TwitterCldr::Shared::LanguageCodes.valid_standard?(:blarg).should be_false
|
160
|
+
|
161
|
+
TwitterCldr::Shared::LanguageCodes.valid_code?(:es, :bcp_47).should be_true
|
162
|
+
TwitterCldr::Shared::LanguageCodes.valid_code?(:es, :iso_639_2).should be_false
|
163
|
+
|
164
|
+
TwitterCldr::Shared::LanguageCodes.from_language(:Spanish, :iso_639_2).should == :spa
|
165
|
+
|
166
|
+
TwitterCldr::Shared::LanguageCodes.to_language(:spa, :iso_639_2).should == "Spanish"
|
167
|
+
end
|
168
|
+
|
169
|
+
it "verifies postal code validations" do
|
170
|
+
TwitterCldr::Shared::PostalCodes.valid?(:us, "94103").should be_true
|
171
|
+
TwitterCldr::Shared::PostalCodes.valid?(:us, "9410").should be_false
|
172
|
+
TwitterCldr::Shared::PostalCodes.valid?(:gb, "BS98 1TL").should be_true
|
173
|
+
TwitterCldr::Shared::PostalCodes.valid?(:se, "280 12").should be_true
|
174
|
+
TwitterCldr::Shared::PostalCodes.valid?(:ca, "V3H 1Z7").should be_true
|
175
|
+
|
176
|
+
TwitterCldr::Shared::PostalCodes.territories.should include(:gb)
|
177
|
+
|
178
|
+
TwitterCldr::Shared::PostalCodes.regex_for_territory(:us).should == /\d{5}([ \-]\d{4})?/
|
179
|
+
end
|
180
|
+
|
181
|
+
it "verifies phone codes" do
|
182
|
+
TwitterCldr::Shared::PhoneCodes.code_for_territory(:us).should == "1"
|
183
|
+
TwitterCldr::Shared::PhoneCodes.code_for_territory(:pe).should == "51"
|
184
|
+
TwitterCldr::Shared::PhoneCodes.code_for_territory(:eg).should == "20"
|
185
|
+
TwitterCldr::Shared::PhoneCodes.code_for_territory(:dk).should == "45"
|
186
|
+
TwitterCldr::Shared::PhoneCodes.territories.should include(:pe)
|
187
|
+
end
|
188
|
+
|
143
189
|
it "verifies world languages" do
|
144
190
|
:es.localize(:es).as_language_code.should == "español"
|
145
191
|
:ru.localize(:es).as_language_code.should == "ruso"
|
146
|
-
ls = TwitterCldr::LocalizedSymbol.new(:ru, :es)
|
192
|
+
ls = TwitterCldr::Localized::LocalizedSymbol.new(:ru, :es)
|
147
193
|
ls.as_language_code.should == "ruso"
|
148
194
|
end
|
149
195
|
|