edtf 3.3.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,296 +0,0 @@
1
- module EDTF
2
-
3
- describe Uncertainty do
4
-
5
- let(:uncertainty) { Uncertainty.new }
6
-
7
- describe '#uncertain?' do
8
-
9
- it { is_expected.to be_certain }
10
-
11
- it 'should be uncertain if at least one part is uncertain' do
12
- expect(Uncertainty.new(false, false, true)).to be_uncertain
13
- end
14
-
15
- it 'should not be uncertain if all parts are certain' do
16
- expect(Uncertainty.new(false, false, false)).to be_certain
17
- end
18
-
19
- it 'should be uncertain if all parts are uncertain' do
20
- expect(Uncertainty.new(true, true, true)).to be_uncertain
21
- end
22
-
23
- # [:year, :month, :day, :hour, :minute, :second].each do |part|
24
- [:year, :month, :day].each do |part|
25
- it "#{ part } should not be uncertain by default" do
26
- expect(uncertainty.uncertain?(part)).to be false
27
- end
28
-
29
- it "#{ part } should be uncertain if set to uncertain" do
30
- uncertainty.send("#{part}=", true)
31
- expect(uncertainty.uncertain?(part)).to be true
32
- end
33
-
34
- # ([:year, :month, :day, :hour, :minute, :second] - [part]).each do |other|
35
- ([:year, :month, :day] - [part]).each do |other|
36
- it "#{other} should not be uncertain if #{part} is uncertain" do
37
- uncertainty.send("#{part}=", true)
38
- expect(uncertainty.uncertain?(other)).to be false
39
- end
40
- end
41
-
42
- end
43
-
44
- describe '#hash' do
45
-
46
- describe 'with the default hash base (1)' do
47
-
48
- it 'returns 0 by default' do
49
- expect(Uncertainty.new.hash).to eq(0)
50
- end
51
-
52
- it 'returns 1 for uncertain year' do
53
- expect(Uncertainty.new.hash).to eq(0)
54
- end
55
-
56
- it 'returns 2 for uncertain month' do
57
- expect(Uncertainty.new.hash).to eq(0)
58
- end
59
-
60
- it 'returns 4 for uncertain day' do
61
- expect(Uncertainty.new.hash).to eq(0)
62
- end
63
-
64
- it 'returns 3 for uncertain year, month' do
65
- expect(Uncertainty.new(true, true).hash).to eq(3)
66
- end
67
-
68
- it 'returns 7 for uncertain year, month, day' do
69
- expect(Uncertainty.new(true, true, true).hash).to eq(7)
70
- end
71
-
72
- it 'returns 5 for uncertain year, day' do
73
- expect(Uncertainty.new(true, nil, true).hash).to eq(5)
74
- end
75
-
76
- it 'returns 6 for uncertain month, day' do
77
- expect(Uncertainty.new(nil, true, true).hash).to eq(6)
78
- end
79
-
80
- end
81
-
82
- end
83
-
84
- end
85
-
86
- describe '#uncertain!' do
87
- it 'should make all parts certain when no part given' do
88
- expect { uncertainty.uncertain! }.to change { uncertainty.certain? }
89
- end
90
- end
91
-
92
- end
93
-
94
- describe Unspecified do
95
- let(:u) { Unspecified.new }
96
-
97
-
98
- describe '#unspecified?' do
99
- it 'should return false by default' do
100
- expect(u).not_to be_unspecified
101
- end
102
-
103
- it 'should return true if the day is unspecified' do
104
- expect(u.unspecified!(:day)).to be_unspecified
105
- end
106
-
107
- it 'should return true if the month is unspecified' do
108
- expect(u.unspecified!(:month)).to be_unspecified
109
- end
110
-
111
- it 'should return true if the year is unspecified' do
112
- expect(u.unspecified!(:year)).to be_unspecified
113
- end
114
- end
115
-
116
- describe '#year' do
117
- it 'returns the year values' do
118
- expect(u.year).to eq([nil,nil,nil,nil])
119
- end
120
-
121
- it 'allows you to set individual offsets' do
122
- u.year[1] = true
123
- expect(u.to_s).to eq('sXss-ss-ss')
124
- end
125
- end
126
-
127
- describe '#to_s' do
128
- it 'should be return "ssss-ss-ss" by default' do
129
- expect(u.to_s).to eq('ssss-ss-ss')
130
- end
131
-
132
- it 'should return "ssss-ss-uu" if the day is unspecified' do
133
- expect(u.unspecified!(:day).to_s).to eq('ssss-ss-XX')
134
- end
135
-
136
- it 'should return "ssss-uu-ss" if the month is unspecified' do
137
- expect(u.unspecified!(:month).to_s).to eq('ssss-XX-ss')
138
- end
139
-
140
- it 'should return "ssss-uu-uu" if month and day are unspecified' do
141
- expect(u.unspecified!([:day, :month]).to_s).to eq('ssss-XX-XX')
142
- end
143
-
144
- it 'should return "uuuu-ss-ss" if the year is unspecified' do
145
- expect(u.unspecified!(:year).to_s).to eq('XXXX-ss-ss')
146
- end
147
-
148
- it 'should return "uuuu-uu-uu" if the date is unspecified' do
149
- expect(u.unspecified!.to_s).to eq('XXXX-XX-XX')
150
- end
151
-
152
- end
153
-
154
- describe '#mask' do
155
-
156
- context 'when passed an empty array' do
157
- it 'should return an empty array' do
158
- expect(u.mask([])).to eq([])
159
- end
160
- end
161
-
162
- context 'when passed an array with a year string' do
163
- let(:date) { ['1994'] }
164
-
165
- it 'should return the array with the year by default' do
166
- expect(u.mask(date)).to eq(['1994'])
167
- end
168
-
169
- context 'when the year is unspecified' do
170
- before(:each) { u.year[3] = true }
171
-
172
- it 'should return the array with the year and the fourth digit masked' do
173
- expect(u.mask(date)).to eq(['199X'])
174
- end
175
-
176
- end
177
-
178
- context 'when the decade is unspecified' do
179
- before(:each) { u.year[2,2] = [true,true] }
180
-
181
- it 'should return the array with the year and the third and fourth digit masked' do
182
- expect(u.mask(date)).to eq(['19XX'])
183
- end
184
-
185
- end
186
-
187
- end
188
-
189
- context 'when passed an array with a negative year string' do
190
- let(:date) { ['-1994'] }
191
-
192
- it 'should return the array with the year by default' do
193
- expect(u.mask(date)).to eq(['-1994'])
194
- end
195
-
196
- context 'when the year is unspecified' do
197
- before(:each) { u.year[3] = true }
198
-
199
- it 'should return the array with the year and the fourth digit masked' do
200
- expect(u.mask(date)).to eq(['-199X'])
201
- end
202
- end
203
-
204
- context 'when the decade is unspecified' do
205
- before(:each) { u.year[2,2] = [true,true] }
206
-
207
- it 'should return the array with the year and the third and fourth digit masked' do
208
- expect(u.mask(date)).to eq(['-19XX'])
209
- end
210
-
211
- end
212
- end
213
-
214
- context 'when passed an array with a year-month string' do
215
- let(:date) { ['1994', '01'] }
216
-
217
- it 'should return the array with the year by default' do
218
- expect(u.mask(date)).to eq(['1994', '01'])
219
- end
220
-
221
- context 'when the year is unspecified' do
222
- before(:each) { u.year[3] = true }
223
-
224
- it 'should return the array with the year and the fourth digit masked' do
225
- expect(u.mask(date)).to eq(['199X', '01'])
226
- end
227
-
228
- context 'when the month is unspecified' do
229
- before(:each) { u.unspecified! :month }
230
-
231
- it 'should return the array with the month masked' do
232
- expect(u.mask(date)).to eq(['199X', 'XX'])
233
- end
234
- end
235
- end
236
-
237
- context 'when the decade is unspecified' do
238
- before(:each) { u.year[2,2] = [true,true] }
239
-
240
- it 'should return the array with the year and the third and fourth digit masked' do
241
- expect(u.mask(date)).to eq(['19XX', '01'])
242
- end
243
-
244
- context 'when the month is unspecified' do
245
- before(:each) { u.unspecified! :month }
246
-
247
- it 'should return the array with the month masked' do
248
- expect(u.mask(date)).to eq(['19XX', 'XX'])
249
- end
250
- end
251
- end
252
-
253
- context 'when the month is unspecified' do
254
- before(:each) { u.unspecified! :month }
255
-
256
- it 'should return the array with the month masked' do
257
- expect(u.mask(date)).to eq(['1994', 'XX'])
258
- end
259
- end
260
-
261
- end
262
-
263
- context 'when passed an array with a year-month-day string' do
264
- let(:date) { ['1994', '01', '27'] }
265
-
266
- it 'should return the array with the date by default' do
267
- expect(u.mask(date)).to eq(['1994', '01', '27'])
268
- end
269
-
270
- context 'when the year is unspecified' do
271
- before(:each) { u.year[3] = true }
272
-
273
- it 'should return the array with the year and the fourth digit masked' do
274
- expect(u.mask(date)).to eq(['199X', '01', '27'])
275
- end
276
-
277
- context 'when the month is unspecified' do
278
- before(:each) { u.unspecified! :month }
279
-
280
- it 'should return the array with the month masked' do
281
- expect(u.mask(date)).to eq(['199X', 'XX', '27'])
282
- end
283
-
284
- context 'when the day is unspecified' do
285
- before(:each) { u.unspecified! :day }
286
-
287
- it 'should return the array with the month masked' do
288
- expect(u.mask(date)).to eq(['199X', 'XX', 'XX'])
289
- end
290
- end
291
- end
292
- end
293
- end
294
- end
295
- end
296
- end
data/spec/spec_helper.rb DELETED
@@ -1,15 +0,0 @@
1
- begin
2
- require 'simplecov'
3
- rescue LoadError
4
- # ignore
5
- end
6
-
7
- begin
8
- require 'debug' unless RUBY_PLATFORM == 'java'
9
- rescue LoadError
10
- # ignore
11
- end
12
-
13
- $LOAD_PATH << File.expand_path('../../lib', __FILE__)
14
-
15
- require 'edtf'