Merged updates from trunk into stable branch
[feedcatcher.git] / vendor / rails / activesupport / lib / active_support / vendor / i18n-0.1.3 / test / i18n_exceptions_test.rb
1 $:.unshift "lib"
2
3 require 'rubygems'
4 require 'test/unit'
5 require 'mocha'
6 require 'i18n'
7 require 'active_support'
8
9 class I18nExceptionsTest < Test::Unit::TestCase
10 def test_invalid_locale_stores_locale
11 force_invalid_locale
12 rescue I18n::ArgumentError => e
13 assert_nil e.locale
14 end
15
16 def test_invalid_locale_message
17 force_invalid_locale
18 rescue I18n::ArgumentError => e
19 assert_equal 'nil is not a valid locale', e.message
20 end
21
22 def test_missing_translation_data_stores_locale_key_and_options
23 force_missing_translation_data
24 rescue I18n::ArgumentError => e
25 options = {:scope => :bar}
26 assert_equal 'de', e.locale
27 assert_equal :foo, e.key
28 assert_equal options, e.options
29 end
30
31 def test_missing_translation_data_message
32 force_missing_translation_data
33 rescue I18n::ArgumentError => e
34 assert_equal 'translation missing: de, bar, foo', e.message
35 end
36
37 def test_invalid_pluralization_data_stores_entry_and_count
38 force_invalid_pluralization_data
39 rescue I18n::ArgumentError => e
40 assert_equal [:bar], e.entry
41 assert_equal 1, e.count
42 end
43
44 def test_invalid_pluralization_data_message
45 force_invalid_pluralization_data
46 rescue I18n::ArgumentError => e
47 assert_equal 'translation data [:bar] can not be used with :count => 1', e.message
48 end
49
50 def test_missing_interpolation_argument_stores_key_and_string
51 force_missing_interpolation_argument
52 rescue I18n::ArgumentError => e
53 assert_equal 'bar', e.key
54 assert_equal "{{bar}}", e.string
55 end
56
57 def test_missing_interpolation_argument_message
58 force_missing_interpolation_argument
59 rescue I18n::ArgumentError => e
60 assert_equal 'interpolation argument bar missing in "{{bar}}"', e.message
61 end
62
63 def test_reserved_interpolation_key_stores_key_and_string
64 force_reserved_interpolation_key
65 rescue I18n::ArgumentError => e
66 assert_equal 'scope', e.key
67 assert_equal "{{scope}}", e.string
68 end
69
70 def test_reserved_interpolation_key_message
71 force_reserved_interpolation_key
72 rescue I18n::ArgumentError => e
73 assert_equal 'reserved key "scope" used in "{{scope}}"', e.message
74 end
75
76 private
77 def force_invalid_locale
78 I18n.backend.translate nil, :foo
79 end
80
81 def force_missing_translation_data
82 I18n.backend.store_translations 'de', :bar => nil
83 I18n.backend.translate 'de', :foo, :scope => :bar
84 end
85
86 def force_invalid_pluralization_data
87 I18n.backend.store_translations 'de', :foo => [:bar]
88 I18n.backend.translate 'de', :foo, :count => 1
89 end
90
91 def force_missing_interpolation_argument
92 I18n.backend.store_translations 'de', :foo => "{{bar}}"
93 I18n.backend.translate 'de', :foo, :baz => 'baz'
94 end
95
96 def force_reserved_interpolation_key
97 I18n.backend.store_translations 'de', :foo => "{{scope}}"
98 I18n.backend.translate 'de', :foo, :baz => 'baz'
99 end
100 end