twitter_cldr 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +177 -0
- data/NOTICE +26 -0
- data/README.md +83 -0
- data/Rakefile +36 -0
- data/lib/ext/calendars/date.rb +20 -0
- data/lib/ext/calendars/datetime.rb +36 -0
- data/lib/ext/calendars/time.rb +20 -0
- data/lib/ext/localized_object.rb +15 -0
- data/lib/ext/numbers/bignum.rb +3 -0
- data/lib/ext/numbers/fixnum.rb +3 -0
- data/lib/ext/numbers/float.rb +3 -0
- data/lib/ext/numbers/localized_number.rb +53 -0
- data/lib/ext/strings/symbol.rb +17 -0
- data/lib/formatters/base.rb +36 -0
- data/lib/formatters/calendars/date_formatter.rb +9 -0
- data/lib/formatters/calendars/datetime_formatter.rb +217 -0
- data/lib/formatters/calendars/time_formatter.rb +9 -0
- data/lib/formatters/numbers/currency_formatter.rb +25 -0
- data/lib/formatters/numbers/decimal_formatter.rb +22 -0
- data/lib/formatters/numbers/helpers/base.rb +18 -0
- data/lib/formatters/numbers/helpers/fraction.rb +29 -0
- data/lib/formatters/numbers/helpers/integer.rb +46 -0
- data/lib/formatters/numbers/number_formatter.rb +48 -0
- data/lib/formatters/numbers/percent_formatter.rb +18 -0
- data/lib/formatters/plurals/rules.rb +34 -0
- data/lib/shared/currencies.rb +33 -0
- data/lib/shared/languages.rb +48 -0
- data/lib/shared/resources.rb +45 -0
- data/lib/shared/timezones.rb +1 -0
- data/lib/tokenizers/base.rb +112 -0
- data/lib/tokenizers/calendars/date_tokenizer.rb +24 -0
- data/lib/tokenizers/calendars/datetime_tokenizer.rb +46 -0
- data/lib/tokenizers/calendars/time_tokenizer.rb +24 -0
- data/lib/tokenizers/key_path.rb +30 -0
- data/lib/tokenizers/numbers/number_tokenizer.rb +50 -0
- data/lib/tokenizers/token.rb +17 -0
- data/lib/twitter_cldr.rb +104 -0
- data/lib/version.rb +3 -0
- data/resources/ar/calendars.yml +145 -0
- data/resources/ar/languages.yml +498 -0
- data/resources/ar/numbers.yml +35 -0
- data/resources/ar/plurals.yml +1 -0
- data/resources/da/calendars.yml +157 -0
- data/resources/da/languages.yml +508 -0
- data/resources/da/numbers.yml +31 -0
- data/resources/da/plurals.yml +1 -0
- data/resources/de/calendars.yml +152 -0
- data/resources/de/languages.yml +508 -0
- data/resources/de/numbers.yml +31 -0
- data/resources/de/plurals.yml +1 -0
- data/resources/en/calendars.yml +145 -0
- data/resources/en/languages.yml +510 -0
- data/resources/en/numbers.yml +31 -0
- data/resources/en/plurals.yml +1 -0
- data/resources/es/calendars.yml +145 -0
- data/resources/es/languages.yml +508 -0
- data/resources/es/numbers.yml +30 -0
- data/resources/es/plurals.yml +1 -0
- data/resources/fa/calendars.yml +150 -0
- data/resources/fa/languages.yml +484 -0
- data/resources/fa/numbers.yml +30 -0
- data/resources/fa/plurals.yml +1 -0
- data/resources/fi/calendars.yml +176 -0
- data/resources/fi/languages.yml +508 -0
- data/resources/fi/numbers.yml +31 -0
- data/resources/fi/plurals.yml +1 -0
- data/resources/fil/calendars.yml +159 -0
- data/resources/fil/languages.yml +115 -0
- data/resources/fil/numbers.yml +31 -0
- data/resources/fil/plurals.yml +1 -0
- data/resources/fr/calendars.yml +149 -0
- data/resources/fr/languages.yml +508 -0
- data/resources/fr/numbers.yml +31 -0
- data/resources/fr/plurals.yml +1 -0
- data/resources/he/calendars.yml +145 -0
- data/resources/he/languages.yml +266 -0
- data/resources/he/numbers.yml +31 -0
- data/resources/he/plurals.yml +1 -0
- data/resources/hi/calendars.yml +144 -0
- data/resources/hi/languages.yml +505 -0
- data/resources/hi/numbers.yml +31 -0
- data/resources/hi/plurals.yml +1 -0
- data/resources/hu/calendars.yml +145 -0
- data/resources/hu/languages.yml +508 -0
- data/resources/hu/numbers.yml +30 -0
- data/resources/hu/plurals.yml +1 -0
- data/resources/id/calendars.yml +145 -0
- data/resources/id/languages.yml +506 -0
- data/resources/id/numbers.yml +30 -0
- data/resources/id/plurals.yml +1 -0
- data/resources/it/calendars.yml +164 -0
- data/resources/it/languages.yml +503 -0
- data/resources/it/numbers.yml +30 -0
- data/resources/it/plurals.yml +1 -0
- data/resources/ja/calendars.yml +157 -0
- data/resources/ja/languages.yml +502 -0
- data/resources/ja/numbers.yml +30 -0
- data/resources/ja/plurals.yml +1 -0
- data/resources/ko/calendars.yml +133 -0
- data/resources/ko/languages.yml +505 -0
- data/resources/ko/numbers.yml +30 -0
- data/resources/ko/plurals.yml +1 -0
- data/resources/ms/calendars.yml +145 -0
- data/resources/ms/languages.yml +54 -0
- data/resources/ms/numbers.yml +30 -0
- data/resources/ms/plurals.yml +1 -0
- data/resources/nl/calendars.yml +145 -0
- data/resources/nl/languages.yml +508 -0
- data/resources/nl/numbers.yml +31 -0
- data/resources/nl/plurals.yml +1 -0
- data/resources/no/calendars.yml +122 -0
- data/resources/no/languages.yml +508 -0
- data/resources/no/numbers.yml +30 -0
- data/resources/no/plurals.yml +1 -0
- data/resources/pl/calendars.yml +161 -0
- data/resources/pl/languages.yml +504 -0
- data/resources/pl/numbers.yml +31 -0
- data/resources/pl/plurals.yml +1 -0
- data/resources/pt/calendars.yml +145 -0
- data/resources/pt/languages.yml +508 -0
- data/resources/pt/numbers.yml +31 -0
- data/resources/pt/plurals.yml +1 -0
- data/resources/ru/calendars.yml +176 -0
- data/resources/ru/languages.yml +508 -0
- data/resources/ru/numbers.yml +30 -0
- data/resources/ru/plurals.yml +1 -0
- data/resources/shared/currencies.yml +451 -0
- data/resources/sv/calendars.yml +145 -0
- data/resources/sv/languages.yml +508 -0
- data/resources/sv/numbers.yml +31 -0
- data/resources/sv/plurals.yml +1 -0
- data/resources/th/calendars.yml +145 -0
- data/resources/th/languages.yml +507 -0
- data/resources/th/numbers.yml +30 -0
- data/resources/th/plurals.yml +1 -0
- data/resources/tr/calendars.yml +145 -0
- data/resources/tr/languages.yml +508 -0
- data/resources/tr/numbers.yml +30 -0
- data/resources/tr/plurals.yml +1 -0
- data/resources/ur/calendars.yml +133 -0
- data/resources/ur/languages.yml +81 -0
- data/resources/ur/numbers.yml +31 -0
- data/resources/ur/plurals.yml +1 -0
- data/resources/zh/calendars.yml +169 -0
- data/resources/zh/languages.yml +506 -0
- data/resources/zh/numbers.yml +30 -0
- data/resources/zh/plurals.yml +1 -0
- data/resources/zh-Hant/calendars.yml +141 -0
- data/resources/zh-Hant/languages.yml +409 -0
- data/resources/zh-Hant/numbers.yml +30 -0
- data/spec/ext/calendars/date_spec.rb +45 -0
- data/spec/ext/calendars/datetime_spec.rb +43 -0
- data/spec/ext/calendars/time_spec.rb +45 -0
- data/spec/ext/numbers/bignum_spec.rb +19 -0
- data/spec/ext/numbers/fixnum_spec.rb +19 -0
- data/spec/ext/numbers/float_spec.rb +19 -0
- data/spec/ext/numbers/localized_number_spec.rb +53 -0
- data/spec/ext/strings/symbol_spec.rb +23 -0
- data/spec/formatters/base_spec.rb +12 -0
- data/spec/formatters/calendars/datetime_formatter_spec.rb +324 -0
- data/spec/formatters/numbers/currency_formatter_spec.rb +27 -0
- data/spec/formatters/numbers/decimal_formatter_spec.rb +30 -0
- data/spec/formatters/numbers/helpers/fraction_spec.rb +22 -0
- data/spec/formatters/numbers/helpers/integer_spec.rb +99 -0
- data/spec/formatters/numbers/number_formatter_spec.rb +79 -0
- data/spec/formatters/numbers/percent_formatter_spec.rb +12 -0
- data/spec/formatters/plurals/rules_spec.rb +73 -0
- data/spec/shared/currencies_spec.rb +55 -0
- data/spec/shared/languages_spec.rb +82 -0
- data/spec/shared/resources_spec.rb +44 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/tokenizers/base_spec.rb +134 -0
- data/spec/tokenizers/calendars/date_tokenizer_spec.rb +36 -0
- data/spec/tokenizers/calendars/datetime_tokenizer_spec.rb +52 -0
- data/spec/tokenizers/calendars/time_tokenizer_spec.rb +34 -0
- data/spec/tokenizers/key_path_spec.rb +44 -0
- data/spec/tokenizers/numbers/number_tokenizer_spec.rb +60 -0
- data/spec/tokenizers/token_spec.rb +18 -0
- data/spec/twitter_cldr_spec.rb +53 -0
- metadata +293 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), %w[.. spec_helper])
|
2
|
+
include TwitterCldr::Formatters
|
3
|
+
|
4
|
+
describe Base do
|
5
|
+
describe "#extract_locale" do
|
6
|
+
it "should return the locale specified in the options hash, :en otherwise" do
|
7
|
+
base = TwitterCldr::Formatters::Base.new
|
8
|
+
base.send(:extract_locale, { :locale => :hi }).should == :hi
|
9
|
+
base.send(:extract_locale, {}).should == :en
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,324 @@
|
|
1
|
+
require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
|
2
|
+
include TwitterCldr::Formatters
|
3
|
+
|
4
|
+
describe DateTimeFormatter do
|
5
|
+
before(:each) do
|
6
|
+
@formatter = DateTimeFormatter.new(:locale => :de)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#day" do
|
10
|
+
it "test: pattern d" do
|
11
|
+
@formatter.send(:day, Date.new(2010, 1, 1), 'd', 1).should == '1'
|
12
|
+
@formatter.send(:day, Date.new(2010, 1, 10), 'd', 1).should == '10'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "test: pattern dd" do
|
16
|
+
@formatter.send(:day, Date.new(2010, 1, 1), 'dd', 2).should == '01'
|
17
|
+
@formatter.send(:day, Date.new(2010, 1, 10), 'dd', 2).should == '10'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#weekday" do
|
22
|
+
it "test: pattern E, EE, EEE" do
|
23
|
+
@formatter.send(:weekday, Date.new(2010, 1, 1), 'E', 1).should == 'Fr.'
|
24
|
+
@formatter.send(:weekday, Date.new(2010, 1, 1), 'EE', 2).should == 'Fr.'
|
25
|
+
@formatter.send(:weekday, Date.new(2010, 1, 1), 'EEE', 3).should == 'Fr.'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "test: pattern EEEE" do
|
29
|
+
@formatter.send(:weekday, Date.new(2010, 1, 1), 'EEEE', 4).should == 'Freitag'
|
30
|
+
end
|
31
|
+
|
32
|
+
it "test: pattern EEEEE" do
|
33
|
+
@formatter.send(:weekday, Date.new(2010, 1, 1), 'EEEEE', 5).should == 'F'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#hour" do
|
38
|
+
it "test: h" do
|
39
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 0, 1, 1), 'h', 1).should == '12'
|
40
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 1, 1, 1), 'h', 1).should == '1'
|
41
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 11, 1, 1), 'h', 1).should == '11'
|
42
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 12, 1, 1), 'h', 1).should == '12'
|
43
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 23, 1, 1), 'h', 1).should == '11'
|
44
|
+
end
|
45
|
+
|
46
|
+
it "test: hh" do
|
47
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 0, 1, 1), 'hh', 2).should == '12'
|
48
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 1, 1, 1), 'hh', 2).should == '01'
|
49
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 11, 1, 1), 'hh', 2).should == '11'
|
50
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 12, 1, 1), 'hh', 2).should == '12'
|
51
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 23, 1, 1), 'hh', 2).should == '11'
|
52
|
+
end
|
53
|
+
|
54
|
+
it "test: H" do
|
55
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 0, 1, 1), 'H', 1).should == '0'
|
56
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 1, 1, 1), 'H', 1).should == '1'
|
57
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 11, 1, 1), 'H', 1).should == '11'
|
58
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 12, 1, 1), 'H', 1).should == '12'
|
59
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 23, 1, 1), 'H', 1).should == '23'
|
60
|
+
end
|
61
|
+
|
62
|
+
it "test: HH" do
|
63
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 0, 1, 1), 'HH', 2).should == '00'
|
64
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 1, 1, 1), 'HH', 2).should == '01'
|
65
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 11, 1, 1), 'HH', 2).should == '11'
|
66
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 12, 1, 1), 'HH', 2).should == '12'
|
67
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 23, 1, 1), 'HH', 2).should == '23'
|
68
|
+
end
|
69
|
+
|
70
|
+
it "test: K" do
|
71
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 0, 1, 1), 'K', 1).should == '0'
|
72
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 1, 1, 1), 'K', 1).should == '1'
|
73
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 11, 1, 1), 'K', 1).should == '11'
|
74
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 12, 1, 1), 'K', 1).should == '0'
|
75
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 23, 1, 1), 'K', 1).should == '11'
|
76
|
+
end
|
77
|
+
|
78
|
+
it "test: KK" do
|
79
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 0, 1, 1), 'KK', 2).should == '00'
|
80
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 1, 1, 1), 'KK', 2).should == '01'
|
81
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 11, 1, 1), 'KK', 2).should == '11'
|
82
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 12, 1, 1), 'KK', 2).should == '00'
|
83
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 23, 1, 1), 'KK', 2).should == '11'
|
84
|
+
end
|
85
|
+
|
86
|
+
it "test: k" do
|
87
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 0, 1, 1), 'k', 1).should == '24'
|
88
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 1, 1, 1), 'k', 1).should == '1'
|
89
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 11, 1, 1), 'k', 1).should == '11'
|
90
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 12, 1, 1), 'k', 1).should == '12'
|
91
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 23, 1, 1), 'k', 1).should == '23'
|
92
|
+
end
|
93
|
+
|
94
|
+
it "test: kk" do
|
95
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 0, 1, 1), 'kk', 2).should == '24'
|
96
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 1, 1, 1), 'kk', 2).should == '01'
|
97
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 11, 1, 1), 'kk', 2).should == '11'
|
98
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 12, 1, 1), 'kk', 2).should == '12'
|
99
|
+
@formatter.send(:hour, Time.local(2000, 1, 1, 23, 1, 1), 'kk', 2).should == '23'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "#minute" do
|
104
|
+
it "test: m" do
|
105
|
+
@formatter.send(:minute, Time.local(2000, 1, 1, 1, 1, 1), 'm', 1).should == '1'
|
106
|
+
@formatter.send(:minute, Time.local(2000, 1, 1, 1, 11, 1), 'm', 1).should == '11'
|
107
|
+
end
|
108
|
+
|
109
|
+
it "test: mm" do
|
110
|
+
@formatter.send(:minute, Time.local(2000, 1, 1, 1, 1, 1), 'mm', 2).should == '01'
|
111
|
+
@formatter.send(:minute, Time.local(2000, 1, 1, 1, 11, 1), 'mm', 2).should == '11'
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "#month" do
|
116
|
+
it "test: pattern M" do
|
117
|
+
@formatter.send(:month, Date.new(2010, 1, 1), 'M', 1).should == '1'
|
118
|
+
@formatter.send(:month, Date.new(2010, 10, 1), 'M', 1).should == '10'
|
119
|
+
end
|
120
|
+
|
121
|
+
it "test: pattern MM" do
|
122
|
+
@formatter.send(:month, Date.new(2010, 1, 1), 'MM', 2).should == '01'
|
123
|
+
@formatter.send(:month, Date.new(2010, 10, 1), 'MM', 2).should == '10'
|
124
|
+
end
|
125
|
+
|
126
|
+
it "test: pattern MMM" do
|
127
|
+
@formatter.send(:month, Date.new(2010, 1, 1), 'MMM', 3).should == 'Jan'
|
128
|
+
@formatter.send(:month, Date.new(2010, 10, 1), 'MMM', 3).should == 'Okt'
|
129
|
+
end
|
130
|
+
|
131
|
+
it "test: pattern MMMM" do
|
132
|
+
@formatter.send(:month, Date.new(2010, 1, 1), 'MMMM', 4).should == 'Januar'
|
133
|
+
@formatter.send(:month, Date.new(2010, 10, 1), 'MMMM', 4).should == 'Oktober'
|
134
|
+
end
|
135
|
+
|
136
|
+
it "test: pattern L" do
|
137
|
+
@formatter.send(:month, Date.new(2010, 1, 1), 'L', 1).should == '1'
|
138
|
+
@formatter.send(:month, Date.new(2010, 10, 1), 'L', 1).should == '10'
|
139
|
+
end
|
140
|
+
|
141
|
+
it "test: pattern LL" do
|
142
|
+
@formatter.send(:month, Date.new(2010, 1, 1), 'LL', 2).should == '01'
|
143
|
+
@formatter.send(:month, Date.new(2010, 10, 1), 'LL', 2).should == '10'
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe "#period" do
|
148
|
+
it "test: a" do
|
149
|
+
@formatter.send(:period, Time.local(2000, 1, 1, 1, 1, 1), 'a', 1).should == 'vorm.'
|
150
|
+
@formatter.send(:period, Time.local(2000, 1, 1, 15, 1, 1), 'a', 1).should == 'nachm.'
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "#quarter" do
|
155
|
+
it "test: pattern Q" do
|
156
|
+
@formatter.send(:quarter, Date.new(2010, 1, 1), 'Q', 1).should == '1'
|
157
|
+
@formatter.send(:quarter, Date.new(2010, 3, 31), 'Q', 1).should == '1'
|
158
|
+
@formatter.send(:quarter, Date.new(2010, 4, 1), 'Q', 1).should == '2'
|
159
|
+
@formatter.send(:quarter, Date.new(2010, 6, 30), 'Q', 1).should == '2'
|
160
|
+
@formatter.send(:quarter, Date.new(2010, 7, 1), 'Q', 1).should == '3'
|
161
|
+
@formatter.send(:quarter, Date.new(2010, 9, 30), 'Q', 1).should == '3'
|
162
|
+
@formatter.send(:quarter, Date.new(2010, 10, 1), 'Q', 1).should == '4'
|
163
|
+
@formatter.send(:quarter, Date.new(2010, 12, 31), 'Q', 1).should == '4'
|
164
|
+
end
|
165
|
+
|
166
|
+
it "test: pattern QQ" do
|
167
|
+
@formatter.send(:quarter, Date.new(2010, 1, 1), 'QQ', 2).should == '01'
|
168
|
+
@formatter.send(:quarter, Date.new(2010, 3, 31), 'QQ', 2).should == '01'
|
169
|
+
@formatter.send(:quarter, Date.new(2010, 4, 1), 'QQ', 2).should == '02'
|
170
|
+
@formatter.send(:quarter, Date.new(2010, 6, 30), 'QQ', 2).should == '02'
|
171
|
+
@formatter.send(:quarter, Date.new(2010, 7, 1), 'QQ', 2).should == '03'
|
172
|
+
@formatter.send(:quarter, Date.new(2010, 9, 30), 'QQ', 2).should == '03'
|
173
|
+
@formatter.send(:quarter, Date.new(2010, 10, 1), 'QQ', 2).should == '04'
|
174
|
+
@formatter.send(:quarter, Date.new(2010, 12, 31), 'QQ', 2).should == '04'
|
175
|
+
end
|
176
|
+
|
177
|
+
it "test: pattern QQQ" do
|
178
|
+
@formatter.send(:quarter, Date.new(2010, 1, 1), 'QQQ', 3).should == 'Q1'
|
179
|
+
@formatter.send(:quarter, Date.new(2010, 3, 31), 'QQQ', 3).should == 'Q1'
|
180
|
+
@formatter.send(:quarter, Date.new(2010, 4, 1), 'QQQ', 3).should == 'Q2'
|
181
|
+
@formatter.send(:quarter, Date.new(2010, 6, 30), 'QQQ', 3).should == 'Q2'
|
182
|
+
@formatter.send(:quarter, Date.new(2010, 7, 1), 'QQQ', 3).should == 'Q3'
|
183
|
+
@formatter.send(:quarter, Date.new(2010, 9, 30), 'QQQ', 3).should == 'Q3'
|
184
|
+
@formatter.send(:quarter, Date.new(2010, 10, 1), 'QQQ', 3).should == 'Q4'
|
185
|
+
@formatter.send(:quarter, Date.new(2010, 12, 31), 'QQQ', 3).should == 'Q4'
|
186
|
+
end
|
187
|
+
|
188
|
+
it "test: pattern QQQQ" do
|
189
|
+
@formatter.send(:quarter, Date.new(2010, 1, 1), 'QQQQ', 4).should == '1. Quartal'
|
190
|
+
@formatter.send(:quarter, Date.new(2010, 3, 31), 'QQQQ', 4).should == '1. Quartal'
|
191
|
+
@formatter.send(:quarter, Date.new(2010, 4, 1), 'QQQQ', 4).should == '2. Quartal'
|
192
|
+
@formatter.send(:quarter, Date.new(2010, 6, 30), 'QQQQ', 4).should == '2. Quartal'
|
193
|
+
@formatter.send(:quarter, Date.new(2010, 7, 1), 'QQQQ', 4).should == '3. Quartal'
|
194
|
+
@formatter.send(:quarter, Date.new(2010, 9, 30), 'QQQQ', 4).should == '3. Quartal'
|
195
|
+
@formatter.send(:quarter, Date.new(2010, 10, 1), 'QQQQ', 4).should == '4. Quartal'
|
196
|
+
@formatter.send(:quarter, Date.new(2010, 12, 31), 'QQQQ', 4).should == '4. Quartal'
|
197
|
+
end
|
198
|
+
|
199
|
+
it "test: pattern q" do
|
200
|
+
@formatter.send(:quarter, Date.new(2010, 1, 1), 'q', 1).should == '1'
|
201
|
+
@formatter.send(:quarter, Date.new(2010, 3, 31), 'q', 1).should == '1'
|
202
|
+
@formatter.send(:quarter, Date.new(2010, 4, 1), 'q', 1).should == '2'
|
203
|
+
@formatter.send(:quarter, Date.new(2010, 6, 30), 'q', 1).should == '2'
|
204
|
+
@formatter.send(:quarter, Date.new(2010, 7, 1), 'q', 1).should == '3'
|
205
|
+
@formatter.send(:quarter, Date.new(2010, 9, 30), 'q', 1).should == '3'
|
206
|
+
@formatter.send(:quarter, Date.new(2010, 10, 1), 'q', 1).should == '4'
|
207
|
+
@formatter.send(:quarter, Date.new(2010, 12, 31), 'q', 1).should == '4'
|
208
|
+
end
|
209
|
+
|
210
|
+
it "test: pattern qq" do
|
211
|
+
@formatter.send(:quarter, Date.new(2010, 1, 1), 'qq', 2).should == '01'
|
212
|
+
@formatter.send(:quarter, Date.new(2010, 3, 31), 'qq', 2).should == '01'
|
213
|
+
@formatter.send(:quarter, Date.new(2010, 4, 1), 'qq', 2).should == '02'
|
214
|
+
@formatter.send(:quarter, Date.new(2010, 6, 30), 'qq', 2).should == '02'
|
215
|
+
@formatter.send(:quarter, Date.new(2010, 7, 1), 'qq', 2).should == '03'
|
216
|
+
@formatter.send(:quarter, Date.new(2010, 9, 30), 'qq', 2).should == '03'
|
217
|
+
@formatter.send(:quarter, Date.new(2010, 10, 1), 'qq', 2).should == '04'
|
218
|
+
@formatter.send(:quarter, Date.new(2010, 12, 31), 'qq', 2).should == '04'
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
describe "#second" do
|
223
|
+
it "test: s" do
|
224
|
+
@formatter.send(:second, Time.local(2000, 1, 1, 1, 1, 1), 's', 1).should == '1'
|
225
|
+
@formatter.send(:second, Time.local(2000, 1, 1, 1, 1, 11), 's', 1).should == '11'
|
226
|
+
end
|
227
|
+
|
228
|
+
it "test: ss" do
|
229
|
+
@formatter.send(:second, Time.local(2000, 1, 1, 1, 1, 1), 'ss', 2).should == '01'
|
230
|
+
@formatter.send(:second, Time.local(2000, 1, 1, 1, 1, 11), 'ss', 2).should == '11'
|
231
|
+
end
|
232
|
+
|
233
|
+
# have i gotten the spec right here? (Sven Fuchs)
|
234
|
+
it "test: S" do
|
235
|
+
@formatter.send(:second, Time.local(2000, 1, 1, 1, 1, 0), 'S', 1).should == '0'
|
236
|
+
@formatter.send(:second, Time.local(2000, 1, 1, 1, 1, 1), 'S', 1).should == '1'
|
237
|
+
@formatter.send(:second, Time.local(2000, 1, 1, 1, 1, 18), 'S', 1).should == '18'
|
238
|
+
end
|
239
|
+
|
240
|
+
it "test: SS" do
|
241
|
+
@formatter.send(:second, Time.local(2000, 1, 1, 1, 1, 0), 'SS', 2).should == '00'
|
242
|
+
@formatter.send(:second, Time.local(2000, 1, 1, 1, 1, 1), 'SS', 2).should == '01'
|
243
|
+
@formatter.send(:second, Time.local(2000, 1, 1, 1, 1, 8), 'SS', 2).should == '08'
|
244
|
+
@formatter.send(:second, Time.local(2000, 1, 1, 1, 1, 21), 'SS', 2).should == '21'
|
245
|
+
end
|
246
|
+
|
247
|
+
it "test: SSS" do
|
248
|
+
@formatter.send(:second, Time.local(2000, 1, 1, 1, 1, 0), 'SSS', 3).should == '000'
|
249
|
+
@formatter.send(:second, Time.local(2000, 1, 1, 1, 1, 1), 'SSS', 3).should == '001'
|
250
|
+
@formatter.send(:second, Time.local(2000, 1, 1, 1, 1, 8), 'SSS', 3).should == '008'
|
251
|
+
@formatter.send(:second, Time.local(2000, 1, 1, 1, 1, 21), 'SSS', 3).should == '021'
|
252
|
+
end
|
253
|
+
|
254
|
+
it "test: SSSS" do
|
255
|
+
@formatter.send(:second, Time.local(2000, 1, 1, 1, 1, 0), 'SSSS', 4).should == '0000'
|
256
|
+
@formatter.send(:second, Time.local(2000, 1, 1, 1, 1, 1), 'SSSS', 4).should == '0001'
|
257
|
+
@formatter.send(:second, Time.local(2000, 1, 1, 1, 1, 8), 'SSSS', 4).should == '0008'
|
258
|
+
@formatter.send(:second, Time.local(2000, 1, 1, 1, 1, 21), 'SSSS', 4).should == '0021'
|
259
|
+
end
|
260
|
+
|
261
|
+
it "test: SSSSS" do
|
262
|
+
@formatter.send(:second, Time.local(2000, 1, 1, 1, 1, 1), 'SSSSS', 5).should == '00001'
|
263
|
+
@formatter.send(:second, Time.local(2000, 1, 1, 1, 1, 8), 'SSSSS', 5).should == '00008'
|
264
|
+
@formatter.send(:second, Time.local(2000, 1, 1, 1, 1, 21), 'SSSSS', 5).should == '00021'
|
265
|
+
end
|
266
|
+
|
267
|
+
it "test: SSSSSS" do
|
268
|
+
@formatter.send(:second, Time.local(2000, 1, 1, 1, 1, 1), 'SSSSSS', 6).should == '000001'
|
269
|
+
@formatter.send(:second, Time.local(2000, 1, 1, 1, 1, 8), 'SSSSSS', 6).should == '000008'
|
270
|
+
@formatter.send(:second, Time.local(2000, 1, 1, 1, 1, 21), 'SSSSSS', 6).should == '000021'
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
describe "#timezone" do
|
275
|
+
it "test: z, zz, zzz" do # TODO is this what's meant by the spec?
|
276
|
+
@formatter.send(:timezone, Time.gm(2000, 1, 1, 1, 1, 1), 'z', 1).should == 'UTC'
|
277
|
+
@formatter.send(:timezone, Time.gm(2000, 1, 1, 1, 1, 1), 'zz', 2).should == 'UTC'
|
278
|
+
@formatter.send(:timezone, Time.gm(2000, 1, 1, 1, 1, 1), 'zzz', 3).should == 'UTC'
|
279
|
+
@formatter.send(:timezone, Time.gm(2000, 1, 1, 1, 1, 1), 'zzzz', 4).should match(/UTC\s\-?\d{4}/)
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
describe "#year" do
|
284
|
+
it "test: pattern y" do
|
285
|
+
@formatter.send(:year, Date.new( 5, 1, 1), 'y', 1).should == '5'
|
286
|
+
@formatter.send(:year, Date.new( 45, 1, 1), 'y', 1).should == '45'
|
287
|
+
@formatter.send(:year, Date.new( 345, 1, 1), 'y', 1).should == '345'
|
288
|
+
@formatter.send(:year, Date.new( 2345, 1, 1), 'y', 1).should == '2345'
|
289
|
+
@formatter.send(:year, Date.new(12345, 1, 1), 'y', 1).should == '12345'
|
290
|
+
end
|
291
|
+
|
292
|
+
it "test: pattern yy" do
|
293
|
+
@formatter.send(:year, Date.new( 5, 1, 1), 'yy', 2).should == '05'
|
294
|
+
@formatter.send(:year, Date.new( 45, 1, 1), 'yy', 2).should == '45'
|
295
|
+
@formatter.send(:year, Date.new( 345, 1, 1), 'yy', 2).should == '45'
|
296
|
+
@formatter.send(:year, Date.new( 2345, 1, 1), 'yy', 2).should == '45'
|
297
|
+
@formatter.send(:year, Date.new(12345, 1, 1), 'yy', 2).should == '45'
|
298
|
+
end
|
299
|
+
|
300
|
+
it "test: pattern yyy" do
|
301
|
+
@formatter.send(:year, Date.new( 5, 1, 1), 'yyy', 3).should == '005'
|
302
|
+
@formatter.send(:year, Date.new( 45, 1, 1), 'yyy', 3).should == '045'
|
303
|
+
@formatter.send(:year, Date.new( 345, 1, 1), 'yyy', 3).should == '345'
|
304
|
+
@formatter.send(:year, Date.new( 2345, 1, 1), 'yyy', 3).should == '2345'
|
305
|
+
@formatter.send(:year, Date.new(12345, 1, 1), 'yyy', 3).should == '12345'
|
306
|
+
end
|
307
|
+
|
308
|
+
it "test: pattern yyyy" do
|
309
|
+
@formatter.send(:year, Date.new( 5, 1, 1), 'yyyy', 4).should == '0005'
|
310
|
+
@formatter.send(:year, Date.new( 45, 1, 1), 'yyyy', 4).should == '0045'
|
311
|
+
@formatter.send(:year, Date.new( 345, 1, 1), 'yyyy', 4).should == '0345'
|
312
|
+
@formatter.send(:year, Date.new( 2345, 1, 1), 'yyyy', 4).should == '2345'
|
313
|
+
@formatter.send(:year, Date.new(12345, 1, 1), 'yyyy', 4).should == '12345'
|
314
|
+
end
|
315
|
+
|
316
|
+
it "test: pattern yyyyy" do
|
317
|
+
@formatter.send(:year, Date.new( 5, 1, 1), 'yyyyy', 5).should == '00005'
|
318
|
+
@formatter.send(:year, Date.new( 45, 1, 1), 'yyyyy', 5).should == '00045'
|
319
|
+
@formatter.send(:year, Date.new( 345, 1, 1), 'yyyyy', 5).should == '00345'
|
320
|
+
@formatter.send(:year, Date.new( 2345, 1, 1), 'yyyyy', 5).should == '02345'
|
321
|
+
@formatter.send(:year, Date.new(12345, 1, 1), 'yyyyy', 5).should == '12345'
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
|
2
|
+
include TwitterCldr::Formatters
|
3
|
+
|
4
|
+
describe CurrencyFormatter do
|
5
|
+
describe "#format" do
|
6
|
+
before(:each) do
|
7
|
+
@formatter = CurrencyFormatter.new(:locale => :msa)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should use a dollar sign when no other currency symbol is given (and default to a precision of 2)" do
|
11
|
+
@formatter.format(12).should == "$12.00"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should use the specified currency symbol when specified" do
|
15
|
+
# S/. is the symbol for the Peruvian Nuevo Sol, just in case you were curious
|
16
|
+
@formatter.format(12, :currency => "S/.").should == "S/.12.00"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should use the currency symbol for the corresponding currency code" do
|
20
|
+
@formatter.format(12, :currency => "PEN").should == "S/.12.00"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "overrides the default precision" do
|
24
|
+
@formatter.format(12, :precision => 3).should == "$12.000"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
|
2
|
+
include TwitterCldr::Formatters
|
3
|
+
|
4
|
+
describe DecimalFormatter do
|
5
|
+
before(:each) do
|
6
|
+
@formatter = DecimalFormatter.new(:locale => :nl)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#format" do
|
10
|
+
it "should format positive decimals correctly" do
|
11
|
+
@formatter.format(12.0).should == "12,0"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should format negative decimals correctly" do
|
15
|
+
@formatter.format(-12.0).should == "-12,0"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#get_tokens" do
|
20
|
+
it "should ask the tokenizer for the tokens for a positive number" do
|
21
|
+
mock(@formatter.tokenizer).tokens(:sign => :positive) { true }
|
22
|
+
@formatter.send(:get_tokens, 12)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should ask the tokenizer for the tokens for a negative number" do
|
26
|
+
mock(@formatter.tokenizer).tokens(:sign => :negative) { true }
|
27
|
+
@formatter.send(:get_tokens, -12)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))), "spec_helper")
|
2
|
+
include TwitterCldr::Formatters::Numbers
|
3
|
+
include TwitterCldr::Tokenizers
|
4
|
+
|
5
|
+
describe Fraction do
|
6
|
+
describe "#apply" do
|
7
|
+
it "test: formats a fraction" do
|
8
|
+
token = Token.new(:value => '###.##', :type => :pattern)
|
9
|
+
Fraction.new(token).apply('45').should == '.45'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "test: pads zero digits on the right side" do
|
13
|
+
token = Token.new(:value => '###.0000#', :type => :pattern)
|
14
|
+
Fraction.new(token).apply('45').should == '.45000'
|
15
|
+
end
|
16
|
+
|
17
|
+
it "test: :precision option overrides format precision" do
|
18
|
+
token = Token.new(:value => '###.##', :type => :pattern)
|
19
|
+
Fraction.new(token).apply('78901', :precision => 5).should == '.78901'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))), "spec_helper")
|
2
|
+
include TwitterCldr::Formatters::Numbers
|
3
|
+
include TwitterCldr::Tokenizers
|
4
|
+
|
5
|
+
describe Integer do
|
6
|
+
describe "#apply" do
|
7
|
+
context "with the ### format" do
|
8
|
+
before(:each) do
|
9
|
+
@token = Token.new(:value => "###", :type => :pattern)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "test: interpolates a number" do
|
13
|
+
TwitterCldr::Formatters::Numbers::Integer.new(@token).apply(123).should == '123'
|
14
|
+
end
|
15
|
+
|
16
|
+
it "test: does not include a fraction for a float" do
|
17
|
+
TwitterCldr::Formatters::Numbers::Integer.new(@token).apply(123.45).should == '123'
|
18
|
+
end
|
19
|
+
|
20
|
+
it "test: does not round when given a float" do
|
21
|
+
TwitterCldr::Formatters::Numbers::Integer.new(@token).apply(123.55).should == '123'
|
22
|
+
end
|
23
|
+
|
24
|
+
it "test: does not round with :precision => 1" do
|
25
|
+
TwitterCldr::Formatters::Numbers::Integer.new(@token).apply(123.55, :precision => 1).should == '123'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "with the #,## format" do
|
30
|
+
before(:each) do
|
31
|
+
@token = Token.new(:value => "#,##", :type => :pattern)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "test: single group" do
|
35
|
+
TwitterCldr::Formatters::Numbers::Integer.new(@token).apply(123).should == '1,23'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "test: multiple groups with a primary group size" do
|
39
|
+
TwitterCldr::Formatters::Numbers::Integer.new(@token).apply(123456789).should == '1,23,45,67,89'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "with the #,##0.## format" do
|
44
|
+
before(:each) do
|
45
|
+
@token = Token.new(:value => "#,##0.##", :type => :pattern)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "test: ignores a fraction part given in the format string" do
|
49
|
+
TwitterCldr::Formatters::Numbers::Integer.new(@token).apply(1234.567).should == '1,234'
|
50
|
+
end
|
51
|
+
|
52
|
+
it "test: cldr example #,##0.## => 1 234" do
|
53
|
+
TwitterCldr::Formatters::Numbers::Integer.new(@token).apply(1234.567).should == '1,234'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "miscellaneous formats" do
|
58
|
+
it "test: interpolates a number on the right side" do
|
59
|
+
token = Token.new(:value => "0###", :type => :pattern)
|
60
|
+
TwitterCldr::Formatters::Numbers::Integer.new(token).apply(123).should == '0123'
|
61
|
+
end
|
62
|
+
|
63
|
+
it "test: strips optional digits" do
|
64
|
+
token = Token.new(:value => "######", :type => :pattern)
|
65
|
+
TwitterCldr::Formatters::Numbers::Integer.new(token).apply(123).should == '123'
|
66
|
+
end
|
67
|
+
|
68
|
+
it "test: multiple groups with a primary and secondary group size" do
|
69
|
+
token = Token.new(:value => "#,##,##0", :type => :pattern)
|
70
|
+
TwitterCldr::Formatters::Numbers::Integer.new(token).apply(123456789).should == '12,34,56,789'
|
71
|
+
end
|
72
|
+
|
73
|
+
it "test: does not group when no digits left of the grouping position" do
|
74
|
+
token = Token.new(:value => "#,###", :type => :pattern)
|
75
|
+
TwitterCldr::Formatters::Numbers::Integer.new(token).apply(123).should == '123'
|
76
|
+
end
|
77
|
+
|
78
|
+
it "test: cldr example #,##0.### => 1 234" do
|
79
|
+
token = Token.new(:value => "#,##0.###", :type => :pattern)
|
80
|
+
TwitterCldr::Formatters::Numbers::Integer.new(token, :group => ' ').apply(1234.567).should == '1 234'
|
81
|
+
end
|
82
|
+
|
83
|
+
it "test: cldr example ###0.##### => 1234" do
|
84
|
+
token = Token.new(:value => "###0.#####", :type => :pattern)
|
85
|
+
TwitterCldr::Formatters::Numbers::Integer.new(token, :group => ' ').apply(1234.567).should == '1234'
|
86
|
+
end
|
87
|
+
|
88
|
+
it "test: cldr example ###0.0000# => 1234" do
|
89
|
+
token = Token.new(:value => "###0.0000#", :type => :pattern)
|
90
|
+
TwitterCldr::Formatters::Numbers::Integer.new(token, :group => ' ').apply(1234.567).should == '1234'
|
91
|
+
end
|
92
|
+
|
93
|
+
it "test: cldr example 00000.0000 => 01234" do
|
94
|
+
token = Token.new(:value => "00000.0000", :type => :pattern)
|
95
|
+
TwitterCldr::Formatters::Numbers::Integer.new(token, :group => ' ').apply(1234.567).should == '01234'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
|
2
|
+
include TwitterCldr::Formatters
|
3
|
+
|
4
|
+
describe NumberFormatter do
|
5
|
+
before(:each) do
|
6
|
+
@tokenizer = TwitterCldr::Tokenizers::NumberTokenizer.new(:locale => :sv, :type => :decimal)
|
7
|
+
|
8
|
+
any_instance_of(NumberFormatter) do |formatter|
|
9
|
+
mock(formatter).tokenizer { @tokenizer }
|
10
|
+
end
|
11
|
+
|
12
|
+
@formatter = NumberFormatter.new(:locale => :sv)
|
13
|
+
@formatter.instance_variable_set("@tokenizer", @tokenizer)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#precision_from" do
|
17
|
+
it "should return the correct precision" do
|
18
|
+
@formatter.send(:precision_from, 12.123).should == 3
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return zero precision if the number isn't a decimal" do
|
22
|
+
@formatter.send(:precision_from, 12).should == 0
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#round_to" do
|
27
|
+
it "should round a number to the given precision" do
|
28
|
+
@formatter.send(:round_to, 12, 0).should == 12
|
29
|
+
@formatter.send(:round_to, 12.2, 0).should == 12
|
30
|
+
@formatter.send(:round_to, 12.5, 0).should == 13
|
31
|
+
@formatter.send(:round_to, 12.25, 1).should == 12.3
|
32
|
+
@formatter.send(:round_to, 12.25, 2).should == 12.25
|
33
|
+
@formatter.send(:round_to, 12.25, 3).should == 12.25
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#parse_number" do
|
38
|
+
it "should round and split the given number by decimal" do
|
39
|
+
@formatter.send(:parse_number, 12, :precision => 0).should == ["12", "0"]
|
40
|
+
@formatter.send(:parse_number, 12.2, :precision => 0).should == ["12", "0"]
|
41
|
+
@formatter.send(:parse_number, 12.5, :precision => 0).should == ["13", "0"]
|
42
|
+
@formatter.send(:parse_number, 12.25, :precision => 1).should == ["12", "3"]
|
43
|
+
@formatter.send(:parse_number, 12.25, :precision => 2).should == ["12", "25"]
|
44
|
+
@formatter.send(:parse_number, 12.25, :precision => 3).should == ["12", "25"]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#format" do
|
49
|
+
it "should format a basic integer" do
|
50
|
+
@formatter.format(12).should == "12"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should format a basic decimal" do
|
54
|
+
@formatter.format(12.0).should == "12,0"
|
55
|
+
end
|
56
|
+
|
57
|
+
context "should respect the :precision option" do
|
58
|
+
it "formats with precision of 0" do
|
59
|
+
@formatter.format(12.1, :precision => 0).should == "12"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "rounds and formats with precision of 1" do
|
63
|
+
@formatter.format(12.25, :precision => 1).should == "12,3"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it "uses the length of the original decimal as the precision" do
|
68
|
+
@formatter.format(12.8543).should == "12,8543"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "formats an integer larger than 999" do
|
72
|
+
@formatter.format(1337).should == "1 337"
|
73
|
+
end
|
74
|
+
|
75
|
+
it "formats an decimal larger than 999.9" do
|
76
|
+
@formatter.format(1337.37).should == "1 337,37"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec_helper")
|
2
|
+
include TwitterCldr::Formatters
|
3
|
+
|
4
|
+
describe PercentFormatter do
|
5
|
+
before(:each) do
|
6
|
+
@formatter = PercentFormatter.new(:locale => :da)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should format the number correctly" do
|
10
|
+
@formatter.format(12).should == "12 %"
|
11
|
+
end
|
12
|
+
end
|