-
Notifications
You must be signed in to change notification settings - Fork 100
/
tc_ruby_country_info.rb
110 lines (89 loc) · 3.29 KB
/
tc_ruby_country_info.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
include TZInfo
class TCRubyCountryInfo < Minitest::Test
def test_code
ci = RubyCountryInfo.new('ZZ', 'Zzz') {|c| }
assert_equal('ZZ', ci.code)
end
def test_name
ci = RubyCountryInfo.new('ZZ', 'Zzz') {|c| }
assert_equal('Zzz', ci.name)
end
def test_zone_identifiers_empty
ci = RubyCountryInfo.new('ZZ', 'Zzz') {|c| }
assert(ci.zone_identifiers.empty?)
assert(ci.zone_identifiers.frozen?)
end
def test_zone_identifiers_no_block
ci = RubyCountryInfo.new('ZZ', 'Zzz')
assert(ci.zone_identifiers.empty?)
assert(ci.zone_identifiers.frozen?)
end
def test_zone_identifiers
ci = RubyCountryInfo.new('ZZ', 'Zzz') do |c|
c.timezone('ZZ/TimezoneB', 1, 2, 1, 2, 'Timezone B')
c.timezone('ZZ/TimezoneA', 1, 4, 1, 4, 'Timezone A')
c.timezone('ZZ/TimezoneC', -10, 3, -20, 7, 'C')
c.timezone('ZZ/TimezoneD', -10, 3, -20, 7)
end
assert_equal(['ZZ/TimezoneB', 'ZZ/TimezoneA', 'ZZ/TimezoneC', 'ZZ/TimezoneD'], ci.zone_identifiers)
assert(ci.zone_identifiers.frozen?)
end
def test_zone_identifiers_after_freeze
ci = RubyCountryInfo.new('ZZ', 'Zzz') do |c|
c.timezone('ZZ/TimezoneB', 1, 2, 1, 2, 'Timezone B')
c.timezone('ZZ/TimezoneA', 1, 4, 1, 4, 'Timezone A')
c.timezone('ZZ/TimezoneC', -10, 3, -20, 7, 'C')
c.timezone('ZZ/TimezoneD', -10, 3, -20, 7)
end
ci.freeze
assert_equal(['ZZ/TimezoneB', 'ZZ/TimezoneA', 'ZZ/TimezoneC', 'ZZ/TimezoneD'], ci.zone_identifiers)
end
def test_zones_empty
ci = RubyCountryInfo.new('ZZ', 'Zzz') {|c| }
assert(ci.zones.empty?)
assert(ci.zones.frozen?)
end
def test_zones_no_block
ci = RubyCountryInfo.new('ZZ', 'Zzz')
assert(ci.zones.empty?)
assert(ci.zones.frozen?)
end
def test_zones
ci = RubyCountryInfo.new('ZZ', 'Zzz') do |c|
c.timezone('ZZ/TimezoneB', 1, 2, 1, 2, 'Timezone B')
c.timezone('ZZ/TimezoneA', 1, 4, 1, 4, 'Timezone A')
c.timezone('ZZ/TimezoneC', -10, 3, -20, 7, 'C')
c.timezone('ZZ/TimezoneD', -10, 3, -20, 7)
end
assert_equal([CountryTimezone.new!('ZZ/TimezoneB', 1, 2, 1, 2, 'Timezone B'),
CountryTimezone.new!('ZZ/TimezoneA', 1, 4, 1, 4, 'Timezone A'),
CountryTimezone.new!('ZZ/TimezoneC', -10, 3, -20, 7, 'C'),
CountryTimezone.new!('ZZ/TimezoneD', -10, 3, -20, 7)],
ci.zones)
assert(ci.zones.frozen?)
end
def test_zones_after_freeze
ci = RubyCountryInfo.new('ZZ', 'Zzz') do |c|
c.timezone('ZZ/TimezoneB', 1, 2, 1, 2, 'Timezone B')
c.timezone('ZZ/TimezoneA', 1, 4, 1, 4, 'Timezone A')
c.timezone('ZZ/TimezoneC', -10, 3, -20, 7, 'C')
c.timezone('ZZ/TimezoneD', -10, 3, -20, 7)
end
ci.freeze
assert_equal([CountryTimezone.new!('ZZ/TimezoneB', 1, 2, 1, 2, 'Timezone B'),
CountryTimezone.new!('ZZ/TimezoneA', 1, 4, 1, 4, 'Timezone A'),
CountryTimezone.new!('ZZ/TimezoneC', -10, 3, -20, 7, 'C'),
CountryTimezone.new!('ZZ/TimezoneD', -10, 3, -20, 7)],
ci.zones)
end
def test_deferred_evaluate
block_called = false
ci = RubyCountryInfo.new('ZZ', 'Zzz') do |c|
block_called = true
end
assert_equal(false, block_called)
ci.zones
assert_equal(true, block_called)
end
end