a926d1c4fe5962d0b953c1e1e620c330eed961de
[packages/precise/mcollective.git] / lib / mcollective / vendor / i18n / lib / i18n / tests / localization / date_time.rb
1 # encoding: utf-8
2
3 module I18n
4   module Tests
5     module Localization
6       module DateTime
7         def setup
8           super
9           setup_datetime_translations
10           @datetime = ::DateTime.new(2008, 3, 1, 6)
11           @other_datetime = ::DateTime.new(2008, 3, 1, 18)
12         end
13
14         test "localize DateTime: given the short format it uses it" do
15           # TODO should be Mrz, shouldn't it?
16           assert_equal '01. Mar 06:00', I18n.l(@datetime, :format => :short, :locale => :de)
17         end
18
19         test "localize DateTime: given the long format it uses it" do
20           assert_equal '01. März 2008 06:00', I18n.l(@datetime, :format => :long, :locale => :de)
21         end
22
23         test "localize DateTime: given the default format it uses it" do
24           # TODO should be Mrz, shouldn't it?
25           assert_equal 'Sa, 01. Mar 2008 06:00:00 +0000', I18n.l(@datetime, :format => :default, :locale => :de)
26         end
27
28         test "localize DateTime: given a day name format it returns the correct day name" do
29           assert_equal 'Samstag', I18n.l(@datetime, :format => '%A', :locale => :de)
30         end
31
32         test "localize DateTime: given an abbreviated day name format it returns the correct abbreviated day name" do
33           assert_equal 'Sa', I18n.l(@datetime, :format => '%a', :locale => :de)
34         end
35
36         test "localize DateTime: given a month name format it returns the correct month name" do
37           assert_equal 'März', I18n.l(@datetime, :format => '%B', :locale => :de)
38         end
39
40         test "localize DateTime: given an abbreviated month name format it returns the correct abbreviated month name" do
41           # TODO should be Mrz, shouldn't it?
42           assert_equal 'Mar', I18n.l(@datetime, :format => '%b', :locale => :de)
43         end
44
45         test "localize DateTime: given a meridian indicator format it returns the correct meridian indicator" do
46           assert_equal 'am', I18n.l(@datetime, :format => '%p', :locale => :de)
47           assert_equal 'pm', I18n.l(@other_datetime, :format => '%p', :locale => :de)
48         end
49
50         test "localize DateTime: given an unknown format it does not fail" do
51           assert_nothing_raised { I18n.l(@datetime, :format => '%x') }
52         end
53
54         test "localize DateTime: given a format is missing it raises I18n::MissingTranslationData" do
55           assert_raise(I18n::MissingTranslationData) { I18n.l(@datetime, :format => :missing) }
56         end
57
58         protected
59
60           def setup_datetime_translations
61             # time translations might have been set up in Tests::Api::Localization::Time
62             I18n.backend.store_translations :de, {
63               :time => {
64                 :formats => {
65                   :default => "%a, %d. %b %Y %H:%M:%S %z",
66                   :short => "%d. %b %H:%M",
67                   :long => "%d. %B %Y %H:%M"
68                 },
69                 :am => 'am',
70                 :pm => 'pm'
71               }
72             }
73           end
74       end
75     end
76   end
77 end