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.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -2
  3. data/History.txt +4 -0
  4. data/README.md +17 -6
  5. data/lib/twitter_cldr/resources/postal_codes_importer.rb +12 -1
  6. data/lib/twitter_cldr/resources/regexp_ast_generator.rb +41 -0
  7. data/lib/twitter_cldr/resources.rb +1 -0
  8. data/lib/twitter_cldr/shared/postal_code_generator.rb +50 -0
  9. data/lib/twitter_cldr/shared/postal_codes.rb +48 -9
  10. data/lib/twitter_cldr/shared.rb +15 -14
  11. data/lib/twitter_cldr/utils/regexp_ast.rb +115 -0
  12. data/lib/twitter_cldr/utils/regexp_sampler.rb +149 -0
  13. data/lib/twitter_cldr/utils.rb +5 -3
  14. data/lib/twitter_cldr/version.rb +1 -1
  15. data/resources/shared/postal_codes.yml +1442 -159
  16. data/spec/bidi/bidi_spec.rb +1 -1
  17. data/spec/collation/collation_spec.rb +1 -1
  18. data/spec/collation/collator_spec.rb +31 -31
  19. data/spec/collation/implicit_collation_elements_spec.rb +6 -6
  20. data/spec/collation/sort_key_builder_spec.rb +28 -26
  21. data/spec/collation/tailoring_spec.rb +1 -1
  22. data/spec/collation/trie_builder_spec.rb +16 -16
  23. data/spec/collation/trie_dumps_spec.rb +2 -2
  24. data/spec/collation/trie_loader_spec.rb +8 -8
  25. data/spec/collation/trie_spec.rb +61 -61
  26. data/spec/collation/trie_with_fallback_spec.rb +5 -5
  27. data/spec/core_ext_spec.rb +1 -1
  28. data/spec/data_readers/additional_date_format_selector_spec.rb +38 -38
  29. data/spec/data_readers/date_time_data_reader_spec.rb +2 -2
  30. data/spec/data_readers/number_data_reader_spec.rb +1 -1
  31. data/spec/formatters/calendars/datetime_formatter_spec.rb +218 -218
  32. data/spec/formatters/list_formatter_spec.rb +8 -8
  33. data/spec/formatters/numbers/abbreviated/abbreviated_number_formatter_spec.rb +14 -14
  34. data/spec/formatters/numbers/abbreviated/long_decimal_formatter_spec.rb +4 -4
  35. data/spec/formatters/numbers/abbreviated/short_decimal_formatter_spec.rb +4 -4
  36. data/spec/formatters/numbers/currency_formatter_spec.rb +11 -11
  37. data/spec/formatters/numbers/decimal_formatter_spec.rb +3 -3
  38. data/spec/formatters/numbers/helpers/fraction_spec.rb +3 -3
  39. data/spec/formatters/numbers/helpers/integer_spec.rb +16 -16
  40. data/spec/formatters/numbers/number_formatter_spec.rb +21 -21
  41. data/spec/formatters/numbers/percent_formatter_spec.rb +3 -3
  42. data/spec/formatters/numbers/rbnf/rbnf_spec.rb +2 -2
  43. data/spec/formatters/plurals/plural_formatter_spec.rb +41 -41
  44. data/spec/formatters/plurals/rules_spec.rb +13 -13
  45. data/spec/localized/localized_array_spec.rb +12 -12
  46. data/spec/localized/localized_date_spec.rb +33 -33
  47. data/spec/localized/localized_datetime_spec.rb +11 -11
  48. data/spec/localized/localized_hash_spec.rb +4 -4
  49. data/spec/localized/localized_number_spec.rb +36 -36
  50. data/spec/localized/localized_object_spec.rb +8 -8
  51. data/spec/localized/localized_string_spec.rb +53 -53
  52. data/spec/localized/localized_symbol_spec.rb +9 -9
  53. data/spec/localized/localized_time_spec.rb +10 -10
  54. data/spec/localized/localized_timespan_spec.rb +8 -8
  55. data/spec/normalization_spec.rb +6 -6
  56. data/spec/parsers/number_parser_spec.rb +36 -36
  57. data/spec/parsers/parser_spec.rb +5 -5
  58. data/spec/parsers/segmentation_parser_spec.rb +19 -19
  59. data/spec/parsers/symbol_table_spec.rb +4 -4
  60. data/spec/parsers/unicode_regex/character_class_spec.rb +19 -19
  61. data/spec/parsers/unicode_regex/character_range_spec.rb +1 -1
  62. data/spec/parsers/unicode_regex/character_set_spec.rb +8 -8
  63. data/spec/parsers/unicode_regex/literal_spec.rb +5 -5
  64. data/spec/parsers/unicode_regex/unicode_string_spec.rb +2 -2
  65. data/spec/parsers/unicode_regex_parser_spec.rb +28 -28
  66. data/spec/resources/loader_spec.rb +32 -32
  67. data/spec/shared/break_iterator_spec.rb +13 -13
  68. data/spec/shared/calendar_spec.rb +59 -59
  69. data/spec/shared/casefolder_spec.rb +5 -5
  70. data/spec/shared/code_point_spec.rb +46 -46
  71. data/spec/shared/currencies_spec.rb +7 -7
  72. data/spec/shared/language_codes_spec.rb +34 -34
  73. data/spec/shared/languages_spec.rb +30 -30
  74. data/spec/shared/numbering_system_spec.rb +7 -7
  75. data/spec/shared/numbers_spec.rb +4 -4
  76. data/spec/shared/phone_codes_spec.rb +7 -7
  77. data/spec/shared/postal_code_generator_spec.rb +76 -0
  78. data/spec/shared/postal_codes_spec.rb +35 -29
  79. data/spec/shared/territories_spec.rb +40 -40
  80. data/spec/shared/unicode_regex_spec.rb +71 -71
  81. data/spec/spec_helper.rb +2 -2
  82. data/spec/tokenizers/calendars/date_tokenizer_spec.rb +1 -1
  83. data/spec/tokenizers/calendars/timespan_tokenizer_spec.rb +6 -6
  84. data/spec/tokenizers/composite_token_spec.rb +3 -3
  85. data/spec/tokenizers/token_spec.rb +3 -3
  86. data/spec/twitter_cldr_spec.rb +72 -72
  87. data/spec/utils/code_points_spec.rb +10 -10
  88. data/spec/utils/interpolation_spec.rb +32 -32
  89. data/spec/utils/range_set_spec.rb +36 -36
  90. data/spec/utils/regexp_ast_spec.rb +44 -0
  91. data/spec/utils/regexp_sampler_spec.rb +182 -0
  92. data/spec/utils/yaml/yaml_spec.rb +23 -23
  93. data/spec/utils_spec.rb +19 -19
  94. metadata +263 -258
@@ -14,22 +14,22 @@ describe Numbers do
14
14
  it 'returns numerical symbols for default locale' do
15
15
  stub(TwitterCldr).locale { :jp }
16
16
  stub(TwitterCldr).get_locale_resource(:jp, :numbers) { { :jp => { :numbers => { :symbols => symbols } } } }
17
- TwitterCldr::Shared::Numbers.symbols.should == symbols
17
+ expect(TwitterCldr::Shared::Numbers.symbols).to eq(symbols)
18
18
  end
19
19
 
20
20
  it 'returns numerical symbols for default locale' do
21
21
  stub(TwitterCldr).get_locale_resource(:np, :numbers) { { :np => { :numbers => { :symbols => symbols } } } }
22
- TwitterCldr::Shared::Numbers.symbols(:np).should == symbols
22
+ expect(TwitterCldr::Shared::Numbers.symbols(:np)).to eq(symbols)
23
23
  end
24
24
 
25
25
  it 'converts locale' do
26
26
  stub(TwitterCldr).get_locale_resource(:'zh-Hant', :numbers) { { :'zh-Hant' => { :numbers => { :symbols => symbols } } } }
27
- TwitterCldr::Shared::Numbers.symbols('zh-tw').should == symbols
27
+ expect(TwitterCldr::Shared::Numbers.symbols('zh-tw')).to eq(symbols)
28
28
  end
29
29
 
30
30
  it 'returns nil if the resource is missing' do
31
31
  stub(TwitterCldr).get_locale_resource(:nop, :numbers) { nil }
32
- TwitterCldr::Shared::Numbers.symbols(:nop).should be_nil
32
+ expect(TwitterCldr::Shared::Numbers.symbols(:nop)).to be_nil
33
33
  end
34
34
  end
35
35
  end
@@ -12,15 +12,15 @@ describe PhoneCodes do
12
12
  let(:territories) { PhoneCodes.territories }
13
13
 
14
14
  it 'returns an array' do
15
- territories.should be_instance_of(Array)
15
+ expect(territories).to be_instance_of(Array)
16
16
  end
17
17
 
18
18
  it 'returns symbols' do
19
- territories.each { |territory| territory.should be_instance_of(Symbol) }
19
+ territories.each { |territory| expect(territory).to be_instance_of(Symbol) }
20
20
  end
21
21
 
22
22
  it 'returns supported territories' do
23
- territories.should include(:br, :fr, :jp)
23
+ expect(territories).to include(:br, :fr, :jp)
24
24
  end
25
25
  end
26
26
 
@@ -31,19 +31,19 @@ describe PhoneCodes do
31
31
  before(:each) { mock(PhoneCodes).resource { { territory => code } } }
32
32
 
33
33
  it 'returns phone code for a given territory' do
34
- PhoneCodes.code_for_territory(territory).should == code
34
+ expect(PhoneCodes.code_for_territory(territory)).to eq(code)
35
35
  end
36
36
 
37
37
  it 'returns nil if the regex is missing' do
38
- PhoneCodes.code_for_territory(:foo).should be_nil
38
+ expect(PhoneCodes.code_for_territory(:foo)).to be_nil
39
39
  end
40
40
 
41
41
  it 'accepts strings' do
42
- PhoneCodes.code_for_territory(territory.to_s).should == code
42
+ expect(PhoneCodes.code_for_territory(territory.to_s)).to eq(code)
43
43
  end
44
44
 
45
45
  it 'accepts upper-case strings' do
46
- PhoneCodes.code_for_territory(territory.to_s.upcase).should == code
46
+ expect(PhoneCodes.code_for_territory(territory.to_s.upcase)).to eq(code)
47
47
  end
48
48
  end
49
49
  end
@@ -0,0 +1,76 @@
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::Shared
9
+ include TwitterCldr::Utils
10
+
11
+ describe PostalCodeGenerator do
12
+ let(:generator) do
13
+ PostalCodeGenerator.new(
14
+ RegexpAst::Root.new([
15
+ RegexpAst::Digit.new([], RegexpAst::Quantifier.new(3, 3)),
16
+ RegexpAst::Literal.new([], nil, '- '),
17
+ RegexpAst::Word.new([], RegexpAst::Quantifier.new(3, 3))
18
+ ], nil)
19
+ )
20
+ end
21
+
22
+ let(:blank_generator) do
23
+ PostalCodeGenerator.new(
24
+ RegexpAst::Root.new([
25
+ RegexpAst::Alternation.new([
26
+ RegexpAst::Literal.new([], nil, ''),
27
+ RegexpAst::Word.new([], nil)
28
+ ], nil)
29
+ ], nil)
30
+ )
31
+ end
32
+
33
+ let(:limited_generator) do
34
+ PostalCodeGenerator.new(
35
+ RegexpAst::Root.new([
36
+ RegexpAst::CharacterSet.new([], nil, ['A-C'], false),
37
+ ], nil)
38
+ )
39
+ end
40
+
41
+ describe "#generate" do
42
+ it "should generate correctly and not allow dashes to be followed by spaces" do
43
+ 10.times do
44
+ generator.generate.should match(/\d{3}-\w{3}/)
45
+ end
46
+ end
47
+ end
48
+
49
+ describe "#sample" do
50
+ it "should generate the given number of unique samples" do
51
+ samples = generator.sample(10)
52
+ samples.size.should == 10
53
+ samples.uniq.should == samples
54
+ samples.each do |sample|
55
+ sample.should match(/\d{3}-\w{3}/)
56
+ end
57
+ end
58
+
59
+ it "should not return blank samples" do
60
+ 10.times do
61
+ blank_generator.sample(10).all? do |sample|
62
+ sample.empty?
63
+ end.should be_false
64
+ end
65
+ end
66
+
67
+ it "shouldn't loop infinitely if the number of possible samples is less than requested" do
68
+ limited_generator.sample(10).size.should < 10
69
+ end
70
+
71
+ it "should attempt to generate more samples if the set doesn't contain enough (but shouldn't infinite loop)" do
72
+ mock.proxy(limited_generator).generate.at_least(10)
73
+ limited_generator.sample(10).size.should < 10
74
+ end
75
+ end
76
+ end
@@ -12,57 +12,63 @@ describe PostalCodes do
12
12
  let(:territories) { PostalCodes.territories }
13
13
 
14
14
  it 'returns an array' do
15
- territories.should be_instance_of(Array)
15
+ expect(territories).to be_instance_of(Array)
16
16
  end
17
17
 
18
18
  it 'returns symbols' do
19
- territories.each { |territory| territory.should be_instance_of(Symbol) }
19
+ territories.each { |territory| expect(territory).to be_instance_of(Symbol) }
20
20
  end
21
21
 
22
22
  it 'returns supported territories' do
23
- territories.should include(:br, :fr, :jp)
23
+ expect(territories).to include(:br, :fr, :jp)
24
24
  end
25
25
  end
26
26
 
27
- describe '#regex_for_territory' do
28
- let(:regex) { /\d{5}[\-]?\d{3}/ }
29
- let(:territory) { :br }
30
-
31
- before(:each) { mock(PostalCodes).resource { { territory => regex } } }
32
-
33
- it 'returns postal code regex for a given territory' do
34
- PostalCodes.regex_for_territory(territory).should == regex
35
- end
36
-
37
- it 'returns nil if the regex is missing' do
38
- PostalCodes.regex_for_territory(:foo).should be_nil
27
+ describe "#new" do
28
+ it "should raise an error if the territory isn't supported" do
29
+ lambda { PostalCodes.for_territory(:xx) }.should raise_error(InvalidTerritoryError)
39
30
  end
40
31
 
41
32
  it 'accepts strings' do
42
- PostalCodes.regex_for_territory(territory.to_s).should == regex
33
+ PostalCodes.for_territory("us").should be_a(PostalCodes)
43
34
  end
44
35
 
45
36
  it 'accepts upper-case strings' do
46
- PostalCodes.regex_for_territory(territory.to_s.upcase).should == regex
37
+ PostalCodes.for_territory("US").should be_a(PostalCodes)
47
38
  end
48
39
  end
49
40
 
50
- describe '#valid?' do
51
- let(:regex) { /\d{5}[\-]?\d{3}/ }
52
- let(:territory) { :br }
53
-
54
- before(:each) { mock(PostalCodes).resource { { territory => regex } } }
41
+ context "with a PostalCodes instance" do
42
+ let(:postal_code) { PostalCodes.for_territory(:us) }
55
43
 
56
- it 'returns true if a given postal code satisfies the regexp' do
57
- PostalCodes.valid?(territory, '12345-321').should be_true
44
+ describe '#regexp' do
45
+ it 'returns postal code regex for a given territory' do
46
+ postal_code.regexp.should be_a(Regexp)
47
+ end
58
48
  end
59
49
 
60
- it "returns false if a given postal code doesn't satisfy the regexp" do
61
- PostalCodes.valid?(territory, 'postal-code').should be_false
50
+ describe '#valid?' do
51
+ it 'returns true if a given postal code satisfies the regexp' do
52
+ postal_code.valid?('12345-6789').should be_true
53
+ end
54
+
55
+ it "returns false if a given postal code doesn't satisfy the regexp" do
56
+ postal_code.valid?('postal-code').should be_false
57
+ end
62
58
  end
63
59
 
64
- it 'returns false if the regexp is missing' do
65
- PostalCodes.valid?(:foo, '12345-321').should be_false
60
+ describe "#sample" do
61
+ PostalCodes.territories.each do |territory|
62
+ postal_code = PostalCodes.for_territory(territory)
63
+
64
+ it "returns samples that match #{territory}" do
65
+ postal_code.sample(10).each do |sample|
66
+ result = postal_code.valid?(sample)
67
+ puts "Failed with example #{sample}" unless result
68
+ result.should be_true
69
+ end
70
+ end
71
+ end
66
72
  end
67
73
  end
68
- end
74
+ end
@@ -10,109 +10,109 @@ include TwitterCldr::Shared
10
10
  describe Territories do
11
11
  describe "#translate_territory" do
12
12
  it "should translate country names from one locale to another" do
13
- Territories.translate_territory("Russia", :en, :es).should match_normalized("Rusia")
14
- Territories.translate_territory("Rusia", :es, :en).should match_normalized("Russia")
15
- Territories.translate_territory("Spain", :en, :es).should match_normalized("España")
16
- Territories.translate_territory("España", :es, :ru).should match_normalized("Испания")
13
+ expect(Territories.translate_territory("Russia", :en, :es)).to match_normalized("Rusia")
14
+ expect(Territories.translate_territory("Rusia", :es, :en)).to match_normalized("Russia")
15
+ expect(Territories.translate_territory("Spain", :en, :es)).to match_normalized("España")
16
+ expect(Territories.translate_territory("España", :es, :ru)).to match_normalized("Испания")
17
17
  end
18
18
 
19
19
  it "should use alternate/short names" do
20
- Territories.translate_territory("Congo (DRC)", :en, :es).should match_normalized("Congo (República Democrática del Congo)")
21
- Territories.translate_territory("Congo (Republic)", :en, :es).should match_normalized("Congo (República)")
22
- Territories.translate_territory("East Timor", :en, :es).should match_normalized("Timor Oriental")
23
- Territories.translate_territory("Falkland Islands (Islas Malvinas)", :en, :es).should match_normalized("Islas Malvinas (Islas Falkland)")
24
- Territories.translate_territory("Hong Kong", :en, :es).should match_normalized("Hong Kong")
25
- Territories.translate_territory("Ivory Coast", :en, :es).should match_normalized("Costa de Marfil")
26
- Territories.translate_territory("Macau", :en, :es).should match_normalized("Macao")
27
- Territories.translate_territory("Macedonia (FYROM)", :en, :es).should match_normalized("Macedonia (ERYM)")
20
+ expect(Territories.translate_territory("Congo (DRC)", :en, :es)).to match_normalized("Congo (República Democrática del Congo)")
21
+ expect(Territories.translate_territory("Congo (Republic)", :en, :es)).to match_normalized("Congo (República)")
22
+ expect(Territories.translate_territory("East Timor", :en, :es)).to match_normalized("Timor Oriental")
23
+ expect(Territories.translate_territory("Falkland Islands (Islas Malvinas)", :en, :es)).to match_normalized("Islas Malvinas (Islas Falkland)")
24
+ expect(Territories.translate_territory("Hong Kong", :en, :es)).to match_normalized("Hong Kong")
25
+ expect(Territories.translate_territory("Ivory Coast", :en, :es)).to match_normalized("Costa de Marfil")
26
+ expect(Territories.translate_territory("Macau", :en, :es)).to match_normalized("Macao")
27
+ expect(Territories.translate_territory("Macedonia (FYROM)", :en, :es)).to match_normalized("Macedonia (ERYM)")
28
28
  end
29
29
 
30
30
  it "should be capitalization agnostic" do
31
- Territories.translate_territory("russia", :en, :es).should match_normalized("Rusia")
32
- Territories.translate_territory("RUSSIA", :en, :es).should match_normalized("Rusia")
31
+ expect(Territories.translate_territory("russia", :en, :es)).to match_normalized("Rusia")
32
+ expect(Territories.translate_territory("RUSSIA", :en, :es)).to match_normalized("Rusia")
33
33
  end
34
34
 
35
35
  it "defaults the destination language to English (or whatever the global locale is)" do
36
- Territories.translate_territory("Rusia", :es).should match_normalized("Russia")
37
- Territories.translate_territory("Россия", :ru).should match_normalized("Russia")
36
+ expect(Territories.translate_territory("Rusia", :es)).to match_normalized("Russia")
37
+ expect(Territories.translate_territory("Россия", :ru)).to match_normalized("Russia")
38
38
  end
39
39
 
40
40
  it "defaults source and destination language to English if not given" do
41
- Territories.translate_territory("Russia").should match_normalized("Russia")
41
+ expect(Territories.translate_territory("Russia")).to match_normalized("Russia")
42
42
  TwitterCldr.locale = :es
43
- Territories.translate_territory("Russia").should match_normalized("Rusia")
43
+ expect(Territories.translate_territory("Russia")).to match_normalized("Rusia")
44
44
  end
45
45
 
46
46
  it "successfully translates locale codes that are and are not in the CLDR using the locale map" do
47
- Territories.translate_territory("Russia", :en, :'zh-cn').should match_normalized("俄罗斯")
48
- Territories.translate_territory("Russia", :en, :'zh').should match_normalized("俄罗斯")
47
+ expect(Territories.translate_territory("Russia", :en, :'zh-cn')).to match_normalized("俄罗斯")
48
+ expect(Territories.translate_territory("Russia", :en, :'zh')).to match_normalized("俄罗斯")
49
49
  end
50
50
 
51
51
  it "should return nil if no translation was found" do
52
- Territories.translate_territory("Russia", :en, :blarg).should == nil
52
+ expect(Territories.translate_territory("Russia", :en, :blarg)).to eq(nil)
53
53
  end
54
54
  end
55
55
 
56
56
  describe "#from_territory_code_for_locale" do
57
57
  it "should return the territory in the correct locale for the given locale code (i.e. RU in English should be Russia)" do
58
- Territories.from_territory_code_for_locale(:ES, :en).should match_normalized("Spain")
59
- Territories.from_territory_code_for_locale(:GB, :es).should match_normalized("UK")
58
+ expect(Territories.from_territory_code_for_locale(:ES, :en)).to match_normalized("Spain")
59
+ expect(Territories.from_territory_code_for_locale(:GB, :es)).to match_normalized("UK")
60
60
  end
61
61
 
62
62
  it "should work with lower-case country codes as well" do
63
- Territories.from_territory_code_for_locale(:es, :en).should match_normalized("Spain")
64
- Territories.from_territory_code_for_locale(:gb, :es).should match_normalized("UK")
63
+ expect(Territories.from_territory_code_for_locale(:es, :en)).to match_normalized("Spain")
64
+ expect(Territories.from_territory_code_for_locale(:gb, :es)).to match_normalized("UK")
65
65
  end
66
66
 
67
67
  it "should work with Traditional Chinese" do
68
- Territories.from_territory_code_for_locale(:US, :"zh-Hant").should match_normalized("美國")
68
+ expect(Territories.from_territory_code_for_locale(:US, :"zh-Hant")).to match_normalized("美國")
69
69
  end
70
70
  end
71
71
 
72
72
  describe "#from_territory_code" do
73
73
  it "should return the language in the default locale for the given locale code" do
74
- Territories.from_territory_code(:ES).should match_normalized("Spain")
75
- Territories.from_territory_code(:RU).should match_normalized("Russia")
74
+ expect(Territories.from_territory_code(:ES)).to match_normalized("Spain")
75
+ expect(Territories.from_territory_code(:RU)).to match_normalized("Russia")
76
76
  TwitterCldr.locale = :es
77
- Territories.from_territory_code(:ES).should match_normalized("España")
77
+ expect(Territories.from_territory_code(:ES)).to match_normalized("España")
78
78
  end
79
79
  end
80
80
 
81
81
  describe "#all_for" do
82
82
  it "should return a hash of all languages for the given language code" do
83
83
  territories = Territories.all_for(:es)
84
- territories.should be_a(Hash)
85
- territories[:ru].should match_normalized("Rusia")
84
+ expect(territories).to be_a(Hash)
85
+ expect(territories[:ru]).to match_normalized("Rusia")
86
86
  end
87
87
 
88
88
  it "should return an empty hash for an invalid language" do
89
89
  territories = Territories.all_for(:blarg)
90
- territories.should == {}
90
+ expect(territories).to eq({})
91
91
  end
92
92
  end
93
93
 
94
94
  describe "#all" do
95
95
  it "should use the default language to get the language hash" do
96
96
  territories = Territories.all
97
- territories.should be_a(Hash)
98
- territories[:ru].should match_normalized("Russia")
99
- territories[:de].should match_normalized("Germany")
97
+ expect(territories).to be_a(Hash)
98
+ expect(territories[:ru]).to match_normalized("Russia")
99
+ expect(territories[:de]).to match_normalized("Germany")
100
100
 
101
101
  TwitterCldr.locale = :es
102
102
  territories = Territories.all
103
- territories.should be_a(Hash)
104
- territories[:ru].should match_normalized("Rusia")
105
- territories[:de].should match_normalized("Alemania")
103
+ expect(territories).to be_a(Hash)
104
+ expect(territories[:ru]).to match_normalized("Rusia")
105
+ expect(territories[:de]).to match_normalized("Alemania")
106
106
  end
107
107
  end
108
108
 
109
109
  describe "the lack of knowledge about three-digit UN area codes" do
110
110
  it "should not be able to translate three-digit UN area codes" do
111
- Territories.translate_territory("Southern Africa", :en, :es).should == nil
111
+ expect(Territories.translate_territory("Southern Africa", :en, :es)).to eq(nil)
112
112
  end
113
113
 
114
114
  it "should not be able to name three-digit UN area codes" do
115
- Territories.from_territory_code_for_locale(:"18", :es).should == nil
115
+ expect(Territories.from_territory_code_for_locale(:"18", :es)).to eq(nil)
116
116
  end
117
117
  end
118
118
 
@@ -25,40 +25,40 @@ describe UnicodeRegex do
25
25
 
26
26
  describe "#compile" do
27
27
  it "should return a UnicodeRegex, parsed and ready to go" do
28
- regex.should be_a(UnicodeRegex)
28
+ expect(regex).to be_a(UnicodeRegex)
29
29
  end
30
30
  end
31
31
 
32
32
  describe "#to_regexp_str" do
33
33
  it "should return the string representation of this regex" do
34
- regex.to_regexp_str.should == "(?:[\\141-\\143])"
34
+ expect(regex.to_regexp_str).to eq("(?:[\\141-\\143])")
35
35
  end
36
36
  end
37
37
 
38
38
  describe "#to_regexp" do
39
39
  it "should return a ruby Regexp" do
40
40
  if RUBY_VERSION <= "1.8.7"
41
- regex.to_regexp.should be_a(Oniguruma::ORegexp)
41
+ expect(regex.to_regexp).to be_a(Oniguruma::ORegexp)
42
42
  else
43
- regex.to_regexp.should be_a(Regexp)
43
+ expect(regex.to_regexp).to be_a(Regexp)
44
44
  end
45
45
  end
46
46
 
47
47
  it "should properly turn various basic regexes into strings" do
48
- compile("^abc$").to_regexp_str.should == "^(?:\\141)(?:\\142)(?:\\143)$"
49
- compile("a(b)c").to_regexp_str.should == "(?:\\141)((?:\\142))(?:\\143)"
50
- compile("a(?:b)c").to_regexp_str.should == "(?:\\141)(?:(?:\\142))(?:\\143)"
51
- compile("a{1,3}").to_regexp_str.should == "(?:\\141){1,3}"
52
- compile("[abc]").to_regexp_str.should == "(?:[\\141-\\143])"
48
+ expect(compile("^abc$").to_regexp_str).to eq("^(?:\\141)(?:\\142)(?:\\143)$")
49
+ expect(compile("a(b)c").to_regexp_str).to eq("(?:\\141)((?:\\142))(?:\\143)")
50
+ expect(compile("a(?:b)c").to_regexp_str).to eq("(?:\\141)(?:(?:\\142))(?:\\143)")
51
+ expect(compile("a{1,3}").to_regexp_str).to eq("(?:\\141){1,3}")
52
+ expect(compile("[abc]").to_regexp_str).to eq("(?:[\\141-\\143])")
53
53
  end
54
54
 
55
55
  it "should properly turn various complex regexes into strings" do
56
- compile("[a-z0-9]").to_regexp_str.should == "(?:[\\60-\\71]|[\\141-\\172])"
57
- compile("[\\u0067-\\u0071]").to_regexp_str.should == "(?:[\\147-\\161])"
56
+ expect(compile("[a-z0-9]").to_regexp_str).to eq("(?:[\\60-\\71]|[\\141-\\172])")
57
+ expect(compile("[\\u0067-\\u0071]").to_regexp_str).to eq("(?:[\\147-\\161])")
58
58
  end
59
59
 
60
60
  it "should properly substitute variables" do
61
- compile("$FOO$BAR", symbol_table).to_regexp_str.should == "(?:[\\147-\\153])(?:[\\160-\\163])"
61
+ expect(compile("$FOO$BAR", symbol_table).to_regexp_str).to eq("(?:[\\147-\\153])(?:[\\160-\\163])")
62
62
  end
63
63
  end
64
64
  end
@@ -67,10 +67,10 @@ describe UnicodeRegex do
67
67
  describe "#match" do
68
68
  it "should substitute variables from the symbol table" do
69
69
  regex = compile("$FOO $BAR", symbol_table)
70
- regex.should exactly_match("h r")
71
- regex.should exactly_match("j q")
72
- regex.should_not exactly_match("h t")
73
- regex.should_not exactly_match("c s")
70
+ expect(regex).to exactly_match("h r")
71
+ expect(regex).to exactly_match("j q")
72
+ expect(regex).not_to exactly_match("h t")
73
+ expect(regex).not_to exactly_match("c s")
74
74
  end
75
75
  end
76
76
  end
@@ -79,40 +79,40 @@ describe UnicodeRegex do
79
79
  describe "#match" do
80
80
  it "should match a regex with no char class" do
81
81
  regex = compile("^abc$")
82
- regex.should exactly_match("abc")
83
- regex.should_not exactly_match("cba")
82
+ expect(regex).to exactly_match("abc")
83
+ expect(regex).not_to exactly_match("cba")
84
84
  end
85
85
 
86
86
  it "should match a regex with a capturing group" do
87
87
  regex = compile("a(b)c")
88
88
  match = regex.match("abc")
89
- match.should_not be_nil
90
- match.captures[0].should == "b"
89
+ expect(match).not_to be_nil
90
+ expect(match.captures[0]).to eq("b")
91
91
  end
92
92
 
93
93
  it "should match a regex with a non-capturing group" do
94
94
  regex = compile("a(?:b)c")
95
95
  match = regex.match("abc")
96
- match.should_not be_nil
97
- match.captures.should == []
96
+ expect(match).not_to be_nil
97
+ expect(match.captures).to eq([])
98
98
  end
99
99
 
100
100
  it "should match a regex with a quantifier" do
101
101
  regex = compile("a{1,3}")
102
- regex.should exactly_match("a")
103
- regex.should exactly_match("aa")
104
- regex.should exactly_match("aaa")
105
- regex.should_not exactly_match("aaaa")
106
- regex.should_not exactly_match("b")
102
+ expect(regex).to exactly_match("a")
103
+ expect(regex).to exactly_match("aa")
104
+ expect(regex).to exactly_match("aaa")
105
+ expect(regex).not_to exactly_match("aaaa")
106
+ expect(regex).not_to exactly_match("b")
107
107
  end
108
108
 
109
109
  it "should match a regex with a basic char class" do
110
110
  regex = compile("[abc]")
111
- regex.should exactly_match("a")
112
- regex.should exactly_match("b")
113
- regex.should exactly_match("c")
114
- regex.should_not exactly_match("ab")
115
- regex.should_not exactly_match("d")
111
+ expect(regex).to exactly_match("a")
112
+ expect(regex).to exactly_match("b")
113
+ expect(regex).to exactly_match("c")
114
+ expect(regex).not_to exactly_match("ab")
115
+ expect(regex).not_to exactly_match("d")
116
116
  end
117
117
  end
118
118
  end
@@ -121,82 +121,82 @@ describe UnicodeRegex do
121
121
  describe "#match" do
122
122
  it "should match a regex with a char class containing a range" do
123
123
  regex = compile("[a-z0-9]")
124
- regex.should exactly_match("a")
125
- regex.should exactly_match("m")
126
- regex.should exactly_match("z")
127
- regex.should exactly_match("0")
128
- regex.should exactly_match("3")
129
- regex.should exactly_match("9")
130
- regex.should_not exactly_match("a0")
131
- regex.should_not exactly_match("m4")
124
+ expect(regex).to exactly_match("a")
125
+ expect(regex).to exactly_match("m")
126
+ expect(regex).to exactly_match("z")
127
+ expect(regex).to exactly_match("0")
128
+ expect(regex).to exactly_match("3")
129
+ expect(regex).to exactly_match("9")
130
+ expect(regex).not_to exactly_match("a0")
131
+ expect(regex).not_to exactly_match("m4")
132
132
  end
133
133
 
134
134
  it "should match a regex with a char class containing a unicode range" do
135
135
  regex = compile("[\\u0067-\\u0071]") # g-q
136
- regex.should exactly_match("g")
137
- regex.should exactly_match("q")
138
- regex.should exactly_match("h")
139
- regex.should_not exactly_match("z")
136
+ expect(regex).to exactly_match("g")
137
+ expect(regex).to exactly_match("q")
138
+ expect(regex).to exactly_match("h")
139
+ expect(regex).not_to exactly_match("z")
140
140
  end
141
141
 
142
142
  it "should match a regex containing a character set" do
143
143
  regex = compile("[\\p{Zs}]")
144
- regex.should exactly_match([160].pack("U*")) # non-breaking space
145
- regex.should exactly_match([5760].pack("U*")) # ogham space mark
146
- regex.should_not exactly_match("a")
144
+ expect(regex).to exactly_match([160].pack("U*")) # non-breaking space
145
+ expect(regex).to exactly_match([5760].pack("U*")) # ogham space mark
146
+ expect(regex).not_to exactly_match("a")
147
147
  end
148
148
 
149
149
  it "should match a regex containing a negated character set" do
150
150
  regex = compile("[\\P{Zs}]")
151
- regex.should exactly_match("a")
152
- regex.should_not exactly_match([160].pack("U*"))
153
- regex.should_not exactly_match([5760].pack("U*"))
151
+ expect(regex).to exactly_match("a")
152
+ expect(regex).not_to exactly_match([160].pack("U*"))
153
+ expect(regex).not_to exactly_match([5760].pack("U*"))
154
154
  end
155
155
 
156
156
  it "should match a regex containing a character set (alternate syntax)" do
157
157
  regex = compile("[[:Zs:]]")
158
- regex.should exactly_match([160].pack("U*")) # non-breaking space
159
- regex.should exactly_match([5760].pack("U*")) # ogham space mark
160
- regex.should_not exactly_match("a")
158
+ expect(regex).to exactly_match([160].pack("U*")) # non-breaking space
159
+ expect(regex).to exactly_match([5760].pack("U*")) # ogham space mark
160
+ expect(regex).not_to exactly_match("a")
161
161
  end
162
162
 
163
163
  it "should match a regex containing a negated character set (alternate syntax)" do
164
164
  regex = compile("[[:^Zs:]]")
165
- regex.should exactly_match("a")
166
- regex.should_not exactly_match([160].pack("U*"))
167
- regex.should_not exactly_match([5760].pack("U*"))
165
+ expect(regex).to exactly_match("a")
166
+ expect(regex).not_to exactly_match([160].pack("U*"))
167
+ expect(regex).not_to exactly_match([5760].pack("U*"))
168
168
  end
169
169
 
170
170
  it "should match a regex with a character set and some quantifiers" do
171
171
  regex = compile("[\\u0067-\\u0071]+")
172
- regex.should exactly_match("gg")
173
- regex.should exactly_match("gh")
174
- regex.should exactly_match("qjk")
175
- regex.should_not exactly_match("")
172
+ expect(regex).to exactly_match("gg")
173
+ expect(regex).to exactly_match("gh")
174
+ expect(regex).to exactly_match("qjk")
175
+ expect(regex).not_to exactly_match("")
176
176
  end
177
177
 
178
178
  it "should match a regex that uses special switches inside the char class" do
179
179
  regex = compile("[\\w]+")
180
- regex.should exactly_match("a")
181
- regex.should exactly_match("abc")
182
- regex.should exactly_match("a0b_1c2")
183
- regex.should_not exactly_match("$@#")
180
+ expect(regex).to exactly_match("a")
181
+ expect(regex).to exactly_match("abc")
182
+ expect(regex).to exactly_match("a0b_1c2")
183
+ expect(regex).not_to exactly_match("$@#")
184
184
  end
185
185
 
186
186
  it "should match a regex that uses negated special switches inside the char class" do
187
187
  regex = compile("[\\W]+")
188
- regex.should_not exactly_match("a")
189
- regex.should_not exactly_match("abc")
190
- regex.should_not exactly_match("a0b_1c2")
191
- regex.should exactly_match("$@#")
188
+ expect(regex).not_to exactly_match("a")
189
+ expect(regex).not_to exactly_match("abc")
190
+ expect(regex).not_to exactly_match("a0b_1c2")
191
+ expect(regex).to exactly_match("$@#")
192
192
  end
193
193
 
194
194
  it "should match a regex with a complicated expression inside the char class" do
195
195
  # not [separators U space-tilde] diff [letters diff numbers] (diff is commutative)
196
196
  regex = compile("[^[\\p{Z}\\u0020-\\u007f]-[\\p{L}]-[\\p{N}]]")
197
- regex.should exactly_match(" ")
198
- regex.should exactly_match(",")
199
- regex.should_not exactly_match("a")
197
+ expect(regex).to exactly_match(" ")
198
+ expect(regex).to exactly_match(",")
199
+ expect(regex).not_to exactly_match("a")
200
200
  end
201
201
  end
202
202
  end