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.
- checksums.yaml +4 -4
- data/README.md +143 -117
- data/lib/edtf/date.rb +39 -2
- data/lib/edtf/epoch.rb +3 -1
- data/lib/edtf/interval.rb +40 -15
- data/lib/edtf/parser.rb +33 -33
- data/lib/edtf/parser.y +32 -32
- data/lib/edtf/season.rb +10 -2
- data/lib/edtf/set.rb +15 -1
- data/lib/edtf/uncertainty.rb +7 -8
- data/lib/edtf/version.rb +1 -1
- metadata +26 -57
- data/.github/workflows/ci.yml +0 -44
- data/.gitignore +0 -8
- data/.rspec +0 -3
- data/.simplecov +0 -19
- data/Gemfile +0 -20
- data/Rakefile +0 -41
- data/cucumber.yml +0 -1
- data/edtf.gemspec +0 -29
- data/features/parser/date_times.feature +0 -41
- data/features/parser/dates.feature +0 -89
- data/features/parser/intervals.feature +0 -18
- data/features/parser/precision.feature +0 -14
- data/features/parser/uncertain_or_approximate.feature +0 -129
- data/features/parser/unspecified.feature +0 -34
- data/features/print/level_0_edtf.feature +0 -79
- data/features/print/level_1_edtf.feature +0 -137
- data/features/print/level_2_edtf.feature +0 -39
- data/features/print/uncertain_or_approximate.feature +0 -131
- data/features/step_definitions/edtf_steps.rb +0 -150
- data/features/support/env.rb +0 -13
- data/spec/edtf/date_spec.rb +0 -245
- data/spec/edtf/epoch_spec.rb +0 -88
- data/spec/edtf/interval_spec.rb +0 -308
- data/spec/edtf/parser_spec.rb +0 -427
- data/spec/edtf/season_spec.rb +0 -111
- data/spec/edtf/set_spec.rb +0 -107
- data/spec/edtf/uncertainty_spec.rb +0 -296
- data/spec/spec_helper.rb +0 -15
data/spec/edtf/parser_spec.rb
DELETED
|
@@ -1,427 +0,0 @@
|
|
|
1
|
-
module EDTF
|
|
2
|
-
describe Parser do
|
|
3
|
-
describe '#parse' do
|
|
4
|
-
|
|
5
|
-
it 'parses simple dates "2001-02-03"' do
|
|
6
|
-
expect(Parser.new.parse('2001-02-03').to_s).to eq('2001-02-03')
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
it 'parses negative years' do
|
|
10
|
-
expect(Parser.new.parse('-2323').to_s).to eq('-2323-01-01')
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it 'parses the negative year -2101 and sets the precision to :year' do
|
|
14
|
-
expect(Parser.new.parse('-2101')).to be_year_precision
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it 'parses year zero' do
|
|
18
|
-
expect(Parser.new.parse('0000').to_s).to eq('0000-01-01')
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it 'parses date/time with time zones' do
|
|
22
|
-
expect(Parser.new.parse('2011-08-15T11:19:00+01:00').to_s).to eq('2011-08-15T11:19:00+01:00')
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it 'parses simple intervals like "2007/2008"' do
|
|
26
|
-
expect(Parser.new.parse('2007/2008')).to be_a(Interval)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it 'parses uncertain dates' do
|
|
30
|
-
expect(Parser.new.parse('1984?')).to be_uncertain
|
|
31
|
-
expect(Parser.new.parse('1984')).to be_certain
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it 'parses uncertain dates (day precision)' do
|
|
35
|
-
expect(Parser.new.parse('1984-11-23?')).to be_uncertain
|
|
36
|
-
expect(Parser.new.parse('1984-11-23')).to be_certain
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it 'parses approximate dates' do
|
|
40
|
-
expect(Parser.new.parse('1984-01~')).to be_approximate
|
|
41
|
-
expect(Parser.new.parse('1984-01')).to be_precise
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it 'parses draft spec uncertain approximate dates' do
|
|
45
|
-
expect(Parser.new.parse('1984?~')).to be_uncertain
|
|
46
|
-
expect(Parser.new.parse('1984?~')).to be_approximate
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it 'parses final spec uncertain approximate dates' do
|
|
50
|
-
expect(Parser.new.parse('1984%')).to be_uncertain
|
|
51
|
-
expect(Parser.new.parse('1984%')).to be_approximate
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it 'parses draft spec unspecified dates' do
|
|
55
|
-
expect(Parser.new.parse('199u')).to be_unspecified
|
|
56
|
-
expect(Parser.new.parse('1999-uu-uu')).to be_unspecified
|
|
57
|
-
expect(Parser.new.parse('199u-01')).to be_unspecified
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it 'parses final spec unspecified dates' do
|
|
61
|
-
expect(Parser.new.parse('199X')).to be_unspecified
|
|
62
|
-
expect(Parser.new.parse('1999-XX-XX')).to be_unspecified
|
|
63
|
-
expect(Parser.new.parse('199X-01')).to be_unspecified
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
it 'parses draft spec negative unspecified dates' do
|
|
67
|
-
expect(Parser.new.parse('-199u')).to be_unspecified
|
|
68
|
-
expect(Parser.new.parse('-1999-uu-uu')).to be_unspecified
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it 'parses final spec negative unspecified dates' do
|
|
72
|
-
expect(Parser.new.parse('-199X')).to be_unspecified
|
|
73
|
-
expect(Parser.new.parse('-1999-XX-XX')).to be_unspecified
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
it 'parses open intervals' do
|
|
77
|
-
expect(Parser.new.parse('2004-01-01/open')).to be_open
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
it 'parses unknown intervals' do
|
|
81
|
-
expect(Parser.new.parse('2004-01-01/unknown')).to be_unknown_end
|
|
82
|
-
expect(Parser.new.parse('unknown/2004-01-01')).to be_unknown_start
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it 'parses intervals with uncertain or approximate dates' do
|
|
86
|
-
expect(Parser.new.parse('1984-06-02?/2004-08-08~').from).to be_uncertain
|
|
87
|
-
expect(Parser.new.parse('1984-06-02?/2004-08-08~').to).to be_approximate
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
it 'parses positive long years' do
|
|
91
|
-
expect(Parser.new.parse('y170000002').year).to eq(170000002)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
it 'parses negative long years' do
|
|
95
|
-
expect(Parser.new.parse('y-170000002').year).to eq(-170000002)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
it 'parses season codes' do
|
|
99
|
-
expect(Parser.new.parse('2003-23')).to be_autumn
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
it 'parses calendar names' do
|
|
103
|
-
expect(Parser.new.parse('2001-02-03^xyz').calendar).to eq('xyz')
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
it 'parses season qualifiers' do
|
|
107
|
-
d = Parser.new.parse('2003-23^european')
|
|
108
|
-
expect(d).to be_autumn
|
|
109
|
-
expect(d).to be_qualified
|
|
110
|
-
expect(d.qualifier).to eq('european')
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
it 'parses uncertain seasons' do
|
|
114
|
-
expect(Parser.new.parse!('2003-23?')).to be_uncertain
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
it 'parses approximate seasons' do
|
|
118
|
-
expect(Parser.new.parse!('2003-23~')).to be_approximate
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
it 'parses draft spec uncertain and approximate seasons' do
|
|
122
|
-
expect(Parser.new.parse!('2003-23?~')).to be_uncertain
|
|
123
|
-
expect(Parser.new.parse!('2003-23?~')).to be_approximate
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
it 'parses final spec uncertain and approximate seasons' do
|
|
127
|
-
expect(Parser.new.parse!('2003-23%')).to be_uncertain
|
|
128
|
-
expect(Parser.new.parse!('2003-23%')).to be_approximate
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
it 'parses positive scientific long years' do
|
|
132
|
-
expect(Parser.new.parse('y17e7').year).to eq(170000000)
|
|
133
|
-
expect(Parser.new.parse('Y17E7').year).to eq(170000000)
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
it 'parses negative scientific long years' do
|
|
137
|
-
expect(Parser.new.parse('y-17e7').year).to eq(-170000000)
|
|
138
|
-
expect(Parser.new.parse('Y-17E7').year).to eq(-170000000)
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
it 'parses masked precision date strings (decades)' do
|
|
142
|
-
d = Parser.new.parse!('198x')
|
|
143
|
-
expect(d).to be_cover(Date.new(1983,3,12))
|
|
144
|
-
expect(d).not_to be_cover(Date.new(1990,1,1))
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
it 'parses masked precision date strings (centuries)' do
|
|
148
|
-
d = Parser.new.parse!('18xx')
|
|
149
|
-
expect(d).to be_cover(Date.new(1848,1,14))
|
|
150
|
-
expect(d).not_to be_cover(Date.new(1799,12,31))
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
it 'parses multiple dates (years)' do
|
|
154
|
-
d = Parser.new.parse!('{1667,1668, 1670..1672}')
|
|
155
|
-
expect(d.map(&:year)).to eq([1667,1668,1670,1671,1672])
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
it 'parses multiple dates (mixed years and months)' do
|
|
159
|
-
d = Parser.new.parse!('{1960, 1961-12}')
|
|
160
|
-
expect(d.map { |x| [x.year,x.month] }).to eq([[1960,1],[1961,12]])
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
it 'parses choice lists (One of the years 1667, 1668, 1670, 1671, 1672)' do
|
|
164
|
-
d = Parser.new.parse!('[1667,1668, 1670..1672]')
|
|
165
|
-
expect(d.map(&:year)).to eq([1667,1668,1670,1671,1672])
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
it 'parses choice lists (December 3, 1760 or some earlier date)' do
|
|
169
|
-
d = Parser.new.parse!('[..1760-12-03]')
|
|
170
|
-
expect(d.map(&:to_s)).to eq(['1760-12-03'])
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
it 'parses choice lists (December 1760 or some later month)' do
|
|
174
|
-
d = Parser.new.parse!('[1760-12..]')
|
|
175
|
-
expect(d.map { |x| [x.year,x.month] }).to eq([[1760,12]])
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
it 'parses choice lists (January or February of 1760 or December 1760 or some later month)' do
|
|
179
|
-
d = Parser.new.parse!('[1760-01, 1760-02, 1760-12..]')
|
|
180
|
-
expect(d.length).to eq(3)
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
it 'parses intern unspecified "199u-01-01"' do
|
|
184
|
-
expect(Parser.new.parse!('199u-01-01').unspecified.to_s).to eq('sssX-ss-ss')
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
it 'parses intern unspecified "19uu-01-01"' do
|
|
188
|
-
expect(Parser.new.parse!('19uu-01-01').unspecified.to_s).to eq('ssXX-ss-ss')
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
it 'parses intern unspecified "199u-uu-01"' do
|
|
192
|
-
expect(Parser.new.parse!('199u-uu-01').unspecified.to_s).to eq('sssX-XX-ss')
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
it 'parses intern unspecified "19uu-uu-01"' do
|
|
196
|
-
expect(Parser.new.parse!('19uu-uu-01').unspecified.to_s).to eq('ssXX-XX-ss')
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
it 'parses intern unspecified "199u-uu-uu"' do
|
|
200
|
-
expect(Parser.new.parse!('199u-uu-uu').unspecified.to_s).to eq('sssX-XX-XX')
|
|
201
|
-
end
|
|
202
|
-
|
|
203
|
-
it 'parses intern unspecified "19uu-uu-uu"' do
|
|
204
|
-
expect(Parser.new.parse!('19uu-uu-uu').unspecified.to_s).to eq('ssXX-XX-XX')
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
it 'parses intern unspecified "199u-01-uu"' do
|
|
208
|
-
expect(Parser.new.parse!('199u-01-uu').unspecified.to_s).to eq('sssX-ss-XX')
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
it 'parses intern unspecified "19uu-01-uu"' do
|
|
212
|
-
expect(Parser.new.parse!('19uu-01-uu').unspecified.to_s).to eq('ssXX-ss-XX')
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
it 'parses intern unspecified "1999-uu-01"' do
|
|
216
|
-
expect(Parser.new.parse!('1999-uu-01').unspecified.to_s).to eq('ssss-XX-ss')
|
|
217
|
-
end
|
|
218
|
-
|
|
219
|
-
it 'parses intern unspecified "2004-06-uu"' do
|
|
220
|
-
expect(Parser.new.parse!('2004-06-uu').unspecified.to_s).to eq('ssss-ss-XX')
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
it 'parses internal unspecified interval "2004-06-uu/2004-07-03"' do
|
|
224
|
-
expect(Parser.new.parse!('2004-06-uu/2004-07-03').from).to eq(Date.new(2004,6,1))
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
it 'parses intern unspecified "199X-01-01"' do
|
|
228
|
-
expect(Parser.new.parse!('199X-01-01').unspecified.to_s).to eq('sssX-ss-ss')
|
|
229
|
-
end
|
|
230
|
-
|
|
231
|
-
it 'parses intern unspecified "19XX-01-01"' do
|
|
232
|
-
expect(Parser.new.parse!('19XX-01-01').unspecified.to_s).to eq('ssXX-ss-ss')
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
it 'parses intern unspecified "199X-XX-01"' do
|
|
236
|
-
expect(Parser.new.parse!('199X-XX-01').unspecified.to_s).to eq('sssX-XX-ss')
|
|
237
|
-
end
|
|
238
|
-
|
|
239
|
-
it 'parses intern unspecified "19XX-XX-01"' do
|
|
240
|
-
expect(Parser.new.parse!('19XX-XX-01').unspecified.to_s).to eq('ssXX-XX-ss')
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
it 'parses intern unspecified "199X-XX-XX"' do
|
|
244
|
-
expect(Parser.new.parse!('199X-XX-XX').unspecified.to_s).to eq('sssX-XX-XX')
|
|
245
|
-
end
|
|
246
|
-
|
|
247
|
-
it 'parses intern unspecified "19XX-XX-XX"' do
|
|
248
|
-
expect(Parser.new.parse!('19XX-XX-XX').unspecified.to_s).to eq('ssXX-XX-XX')
|
|
249
|
-
end
|
|
250
|
-
|
|
251
|
-
it 'parses intern unspecified "199X-01-XX"' do
|
|
252
|
-
expect(Parser.new.parse!('199X-01-XX').unspecified.to_s).to eq('sssX-ss-XX')
|
|
253
|
-
end
|
|
254
|
-
|
|
255
|
-
it 'parses intern unspecified "19XX-01-XX"' do
|
|
256
|
-
expect(Parser.new.parse!('19XX-01-XX').unspecified.to_s).to eq('ssXX-ss-XX')
|
|
257
|
-
end
|
|
258
|
-
|
|
259
|
-
it 'parses intern unspecified "1999-XX-01"' do
|
|
260
|
-
expect(Parser.new.parse!('1999-XX-01').unspecified.to_s).to eq('ssss-XX-ss')
|
|
261
|
-
end
|
|
262
|
-
|
|
263
|
-
it 'parses intern unspecified "2004-06-XX"' do
|
|
264
|
-
expect(Parser.new.parse!('2004-06-XX').unspecified.to_s).to eq('ssss-ss-XX')
|
|
265
|
-
end
|
|
266
|
-
|
|
267
|
-
it 'parses internal unspecified interval "2004-06-XX/2004-07-03"' do
|
|
268
|
-
expect(Parser.new.parse!('2004-06-XX/2004-07-03').from).to eq(Date.new(2004,6,1))
|
|
269
|
-
end
|
|
270
|
-
|
|
271
|
-
it 'parses "2004?-06-11": uncertain year; month, day known' do
|
|
272
|
-
d = Parser.new.parse!('2004?-06-11')
|
|
273
|
-
expect(d.uncertain?(:year)).to be true
|
|
274
|
-
expect(d.uncertain?([:month, :day])).to be false
|
|
275
|
-
end
|
|
276
|
-
|
|
277
|
-
it 'parses "2004-06~-11": year and month are approximate; day known' do
|
|
278
|
-
d = Parser.new.parse!('2004-06~-11')
|
|
279
|
-
expect(d.approximate?(:year)).to be true
|
|
280
|
-
expect(d.approximate?(:month)).to be true
|
|
281
|
-
expect(d.approximate?(:day)).to be false
|
|
282
|
-
end
|
|
283
|
-
|
|
284
|
-
it 'parses "2004-(06)?-11": uncertain month, year and day known' do
|
|
285
|
-
d = Parser.new.parse!('2004-(06)?-11')
|
|
286
|
-
|
|
287
|
-
expect(d.uncertain?(:year)).to be false
|
|
288
|
-
expect(d.approximate?(:year)).to be false
|
|
289
|
-
|
|
290
|
-
expect(d.uncertain?(:month)).to be true
|
|
291
|
-
expect(d.approximate?(:month)).to be false
|
|
292
|
-
|
|
293
|
-
expect(d.uncertain?(:day)).to be false
|
|
294
|
-
expect(d.approximate?(:day)).to be false
|
|
295
|
-
end
|
|
296
|
-
|
|
297
|
-
it 'parses "2004-06-(11)~": day is approximate; year, month known' do
|
|
298
|
-
d = Parser.new.parse!('2004-06-(11)~')
|
|
299
|
-
expect(d.approximate?(:year)).to be false
|
|
300
|
-
expect(d.approximate?(:month)).to be false
|
|
301
|
-
expect(d.approximate?(:day)).to be true
|
|
302
|
-
end
|
|
303
|
-
|
|
304
|
-
it 'parses "2004-(06)?~": year known, month within year is approximate and uncertain' do
|
|
305
|
-
d = Parser.new.parse!('2004-(06)?~')
|
|
306
|
-
|
|
307
|
-
expect(d.approximate?(:year)).to be false
|
|
308
|
-
expect(d.uncertain?(:year)).to be false
|
|
309
|
-
|
|
310
|
-
expect(d.approximate?(:month)).to be true
|
|
311
|
-
expect(d.uncertain?(:month)).to be true
|
|
312
|
-
|
|
313
|
-
expect(d.approximate?(:day)).to be false
|
|
314
|
-
expect(d.uncertain?(:day)).to be false
|
|
315
|
-
end
|
|
316
|
-
|
|
317
|
-
it 'parses "2004-(06-11)?": year known, month and day uncertain' do
|
|
318
|
-
d = Parser.new.parse!('2004-(06-11)?')
|
|
319
|
-
|
|
320
|
-
expect(d.approximate?(:year)).to be false
|
|
321
|
-
expect(d.uncertain?(:year)).to be false
|
|
322
|
-
|
|
323
|
-
expect(d.approximate?(:month)).to be false
|
|
324
|
-
expect(d.uncertain?(:month)).to be true
|
|
325
|
-
|
|
326
|
-
expect(d.approximate?(:day)).to be false
|
|
327
|
-
expect(d.uncertain?(:day)).to be true
|
|
328
|
-
end
|
|
329
|
-
|
|
330
|
-
it 'parses "2004?-06-(11)~": year uncertain, month known, day approximate' do
|
|
331
|
-
d = Parser.new.parse('2004?-06-(11)~')
|
|
332
|
-
|
|
333
|
-
expect(d.approximate?(:year)).to be false
|
|
334
|
-
expect(d.uncertain?(:year)).to be true
|
|
335
|
-
|
|
336
|
-
expect(d.approximate?(:month)).to be false
|
|
337
|
-
expect(d.uncertain?(:month)).to be false
|
|
338
|
-
|
|
339
|
-
expect(d.approximate?(:day)).to be true
|
|
340
|
-
expect(d.uncertain?(:day)).to be false
|
|
341
|
-
end
|
|
342
|
-
|
|
343
|
-
it 'parses "(2004-(06)~)?": year uncertain and month is both uncertain and approximate' do
|
|
344
|
-
d = Parser.new.parse!('(2004-(06)~)?')
|
|
345
|
-
|
|
346
|
-
expect(d.approximate?(:year)).to be false
|
|
347
|
-
expect(d.uncertain?(:year)).to be true
|
|
348
|
-
|
|
349
|
-
expect(d.approximate?(:month)).to be true
|
|
350
|
-
expect(d.uncertain?(:month)).to be true
|
|
351
|
-
|
|
352
|
-
expect(d.approximate?(:day)).to be false
|
|
353
|
-
expect(d.uncertain?(:day)).to be false
|
|
354
|
-
end
|
|
355
|
-
|
|
356
|
-
it 'parses "2004~-(06)?-01~": year and day approximate, month uncertain' do
|
|
357
|
-
d = Parser.new.parse!("2004~-(06)?-01~")
|
|
358
|
-
|
|
359
|
-
expect(d.approximate?(:year)).to be true
|
|
360
|
-
expect(d.uncertain?(:year)).to be false
|
|
361
|
-
|
|
362
|
-
expect(d.approximate?(:month)).to be false
|
|
363
|
-
expect(d.uncertain?(:month)).to be true
|
|
364
|
-
|
|
365
|
-
expect(d.approximate?(:day)).to be true
|
|
366
|
-
expect(d.uncertain?(:day)).to be false
|
|
367
|
-
end
|
|
368
|
-
|
|
369
|
-
it 'parses "2004~-(06-(01)~)?": year and day approximate, month and day uncertain' do
|
|
370
|
-
d = Parser.new.parse!("2004~-(06-(01)~)?")
|
|
371
|
-
|
|
372
|
-
expect(d.approximate?(:year)).to be true
|
|
373
|
-
expect(d.uncertain?(:year)).to be false
|
|
374
|
-
|
|
375
|
-
expect(d.approximate?(:month)).to be false
|
|
376
|
-
expect(d.uncertain?(:month)).to be true
|
|
377
|
-
|
|
378
|
-
expect(d.approximate?(:day)).to be true
|
|
379
|
-
expect(d.uncertain?(:day)).to be true
|
|
380
|
-
end
|
|
381
|
-
|
|
382
|
-
it 'parses "2004~-(06)?-01?~": year and day approximate, month and day uncertain' do
|
|
383
|
-
d = Parser.new.parse!("2004~-(06)?-01?~")
|
|
384
|
-
|
|
385
|
-
expect(d.approximate?(:year)).to be true
|
|
386
|
-
expect(d.uncertain?(:year)).to be false
|
|
387
|
-
|
|
388
|
-
expect(d.approximate?(:month)).to be false
|
|
389
|
-
expect(d.uncertain?(:month)).to be true
|
|
390
|
-
|
|
391
|
-
expect(d.approximate?(:day)).to be true
|
|
392
|
-
expect(d.uncertain?(:day)).to be true
|
|
393
|
-
end
|
|
394
|
-
|
|
395
|
-
it 'parses "2004~-(06)?": year approximate, month uncertain' do
|
|
396
|
-
d = Parser.new.parse!("2004~-(06)?")
|
|
397
|
-
|
|
398
|
-
expect(d.approximate?(:year)).to be true
|
|
399
|
-
expect(d.uncertain?(:year)).to be false
|
|
400
|
-
|
|
401
|
-
expect(d.approximate?(:month)).to be false
|
|
402
|
-
expect(d.uncertain?(:month)).to be true
|
|
403
|
-
|
|
404
|
-
expect(d.approximate?(:day)).to be false
|
|
405
|
-
expect(d.uncertain?(:day)).to be false
|
|
406
|
-
end
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
it 'parses "2004~-06?": year approximate, year and month uncertain' do
|
|
410
|
-
d = Parser.new.parse!("2004~-06?")
|
|
411
|
-
|
|
412
|
-
expect(d.approximate?(:year)).to be true
|
|
413
|
-
expect(d.uncertain?(:year)).to be true
|
|
414
|
-
|
|
415
|
-
expect(d.approximate?(:month)).to be false
|
|
416
|
-
expect(d.uncertain?(:month)).to be true
|
|
417
|
-
|
|
418
|
-
expect(d.approximate?(:day)).to be false
|
|
419
|
-
expect(d.uncertain?(:day)).to be false
|
|
420
|
-
|
|
421
|
-
end
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
end
|
|
426
|
-
end
|
|
427
|
-
end
|
data/spec/edtf/season_spec.rb
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
module EDTF
|
|
2
|
-
describe 'Seasons' do
|
|
3
|
-
let(:subject) { Season.new }
|
|
4
|
-
let(:summer) { Season.new(:summer) }
|
|
5
|
-
let(:winter) { Season.new(:winter) }
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
describe 'uncertain/approximate' do
|
|
9
|
-
|
|
10
|
-
it 'is certain by default' do
|
|
11
|
-
expect(subject).to be_certain
|
|
12
|
-
expect(subject).not_to be_uncertain
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it 'is precise by default' do
|
|
16
|
-
expect(subject).to be_precise
|
|
17
|
-
expect(subject).not_to be_approximate
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
describe '#approximate!' do
|
|
21
|
-
it 'makes the season approximate' do
|
|
22
|
-
expect(subject.approximate!).to be_approximate
|
|
23
|
-
expect(subject.approximate!).not_to be_precise
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
describe '#uncertain!' do
|
|
28
|
-
it 'makes the season uncertain' do
|
|
29
|
-
expect(subject.uncertain!).to be_uncertain
|
|
30
|
-
expect(subject.uncertain!).not_to be_certain
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
describe '#succ' do
|
|
37
|
-
|
|
38
|
-
it 'returns a season' do
|
|
39
|
-
expect(summer.succ).to be_instance_of(Season)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it 'it returns a season that is greater than the original one' do
|
|
43
|
-
expect(summer.succ).to be > summer
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it 'the successor of the winter season is spring of the following year' do
|
|
47
|
-
spring = winter.succ
|
|
48
|
-
expect(spring).to be_spring
|
|
49
|
-
expect(spring.year).to eq(winter.year + 1)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
describe '#season?' do
|
|
55
|
-
it 'returns true by default' do
|
|
56
|
-
expect(subject).to be_season
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
describe '#season' do
|
|
61
|
-
before(:each) { subject.season = :summer }
|
|
62
|
-
|
|
63
|
-
it 'returns the season code' do
|
|
64
|
-
expect(subject.season).to eq(:summer)
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
describe '#season=' do
|
|
69
|
-
it 'sets the season code when called with a valid season code' do
|
|
70
|
-
expect {
|
|
71
|
-
(21..22).each do |i|
|
|
72
|
-
subject.season = i
|
|
73
|
-
end
|
|
74
|
-
}.not_to raise_error
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
it 'throws an exception if given invalid season code' do
|
|
78
|
-
expect { subject.season = 13 }.to raise_error(NoMethodError)
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
describe '#summer!' do
|
|
83
|
-
it 'sets the season to :summer' do
|
|
84
|
-
subject.season = :spring
|
|
85
|
-
expect { subject.summer! }.to change { subject.season }.to(:summer)
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
describe '#winter?' do
|
|
90
|
-
it 'returns true if the season is set to :winter' do
|
|
91
|
-
subject.season = :winter
|
|
92
|
-
expect(subject).to be_winter
|
|
93
|
-
end
|
|
94
|
-
it 'returns false if the season is not set to :winter' do
|
|
95
|
-
subject.season = :summer
|
|
96
|
-
expect(subject).not_to be_winter
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
describe '#include?' do
|
|
101
|
-
|
|
102
|
-
context 'for summer' do
|
|
103
|
-
it 'returns true for August 24' do
|
|
104
|
-
expect(Season.new(1980, :summer)).to include(Date.new(1980,8,24))
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
end
|
|
111
|
-
end
|
data/spec/edtf/set_spec.rb
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
module EDTF
|
|
2
|
-
describe 'Sets' do
|
|
3
|
-
|
|
4
|
-
describe 'constructor' do
|
|
5
|
-
|
|
6
|
-
it 'creates a new empty set by default' do
|
|
7
|
-
expect(Set.new).to be_empty
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
describe '#edtf' do
|
|
13
|
-
|
|
14
|
-
it 'returns {} by default' do
|
|
15
|
-
expect(Set.new.edtf).to eq('{}')
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it 'returns [] for empty choice lists' do
|
|
19
|
-
expect(Set.new.choice!.edtf).to eq('[]')
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it 'returns {1984} if the set contains the year 1984' do
|
|
23
|
-
expect(Set.new(Date.edtf('1984')).edtf).to eq('{1984}')
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it 'returns {1984, 1985-10} for the set containing these dates' do
|
|
27
|
-
expect(Set.new(Date.edtf('1984'), Date.new(1984,10).month_precision).edtf).to eq('{1984,1984-10}')
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it 'returns {..1984, 1985-10} for the set containing these dates and earlier == true' do
|
|
31
|
-
expect(Set.new(Date.edtf('1984'), Date.new(1984,10).month_precision).earlier!.edtf).to eq('{..1984,1984-10}')
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it 'returns {1984, 1985-10..} for the set containing these dates and later == true' do
|
|
35
|
-
expect(Set.new(Date.edtf('1984'), Date.new(1984,10).month_precision).later!.edtf).to eq('{1984,1984-10..}')
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it 'returns [1667, 1668, 1670..1672] for the years 1667, 1668 and the interval 1670..1672' do
|
|
39
|
-
s = Set.new.choice!
|
|
40
|
-
s << Date.edtf('1667') << Date.edtf('1668')
|
|
41
|
-
s << (Date.edtf('1670') .. Date.edtf('1672'))
|
|
42
|
-
expect(s.edtf).to eq('[1667,1668,1670..1672]')
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
describe 'the set [1667, 1668, 1670..1672]' do
|
|
48
|
-
let(:set) { Set.new(Date.edtf('1667'), Date.edtf('1668'), Date.edtf('1670')..Date.edtf('1672')).choice! }
|
|
49
|
-
|
|
50
|
-
it 'includes the year 1671' do
|
|
51
|
-
expect(set).to include(Date.new(1671).year_precision!)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it 'does not include the date 1671-01-01' do
|
|
55
|
-
expect(set.include?(Date.new(1671))).to be false
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it 'does not include the year 1669' do
|
|
59
|
-
expect(set.include?(Date.new(1669).year_precision!)).to be false
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
it 'has a length of 3' do
|
|
63
|
-
expect(set.size).to eq(3)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
it 'maps to the year array [1667,1668,1670,1671,1672]' do
|
|
67
|
-
expect(set.map(&:year)).to eq([1667, 1668, 1670, 1671, 1672])
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
describe 'the set [1984,1985-10-01..]' do
|
|
72
|
-
let(:s1) { Set.new(Date.edtf('1984'), Date.edtf('1985-10-01')).later! }
|
|
73
|
-
let(:s2) { Date.edtf('[1984,1985-10-01..]') }
|
|
74
|
-
|
|
75
|
-
it 'has varying precision' do
|
|
76
|
-
expect(s1.map(&:precision)).to eq([:year, :day])
|
|
77
|
-
expect(s2.map(&:precision)).to eq([:year, :day])
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
describe 'the set [1760-12..1761-03]' do
|
|
82
|
-
let(:set) { Date.edtf('[1760-12..1761-03]') }
|
|
83
|
-
|
|
84
|
-
it "is a choice" do
|
|
85
|
-
expect(set).to be_choice
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
it "maps to the 4 months 1760-12 through 1761-03" do
|
|
89
|
-
expected_months = %w[1760-12 1761-01 1761-02 1761-03].map { |m| Date.edtf(m) }
|
|
90
|
-
expect(set.to_a).to eq(expected_months)
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
describe 'the set {1760-12..1761-03}' do
|
|
95
|
-
let(:set) { Date.edtf('{1760-12..1761-03}') }
|
|
96
|
-
|
|
97
|
-
it "is not a choice" do
|
|
98
|
-
expect(set).not_to be_choice
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
it "maps to the 4 months 1760-12 through 1761-03" do
|
|
102
|
-
expected_months = %w[1760-12 1761-01 1761-02 1761-03].map { |m| Date.edtf(m) }
|
|
103
|
-
expect(set.to_a).to eq(expected_months)
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
end
|