edtf 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/Gemfile +8 -3
- data/README.md +8 -8
- data/features/parser/date_times.feature +3 -3
- data/features/print/level_0_edtf.feature +61 -61
- data/features/step_definitions/edtf_steps.rb +25 -25
- data/features/support/env.rb +1 -1
- data/lib/edtf/date.rb +6 -3
- data/lib/edtf/date_time.rb +10 -1
- data/lib/edtf/parser.rb +344 -343
- data/lib/edtf/parser.y +29 -28
- data/lib/edtf/set.rb +3 -1
- data/lib/edtf/version.rb +1 -1
- data/spec/edtf/date_spec.rb +39 -39
- data/spec/edtf/epoch_spec.rb +15 -15
- data/spec/edtf/interval_spec.rb +35 -35
- data/spec/edtf/parser_spec.rb +123 -123
- data/spec/edtf/season_spec.rb +22 -21
- data/spec/edtf/set_spec.rb +71 -71
- data/spec/edtf/uncertainty_spec.rb +42 -42
- data/spec/spec_helper.rb +1 -1
- metadata +5 -4
data/spec/edtf/season_spec.rb
CHANGED
@@ -8,26 +8,26 @@ module EDTF
|
|
8
8
|
describe 'uncertain/approximate' do
|
9
9
|
|
10
10
|
it 'is certain by default' do
|
11
|
-
subject.
|
12
|
-
subject.
|
11
|
+
expect(subject).to be_certain
|
12
|
+
expect(subject).not_to be_uncertain
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'is precise by default' do
|
16
|
-
subject.
|
17
|
-
subject.
|
16
|
+
expect(subject).to be_precise
|
17
|
+
expect(subject).not_to be_approximate
|
18
18
|
end
|
19
19
|
|
20
20
|
describe '#approximate!' do
|
21
21
|
it 'makes the season approximate' do
|
22
|
-
subject.approximate
|
23
|
-
subject.approximate
|
22
|
+
expect(subject.approximate!).to be_approximate
|
23
|
+
expect(subject.approximate!).not_to be_precise
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
describe '#uncertain!' do
|
28
28
|
it 'makes the season uncertain' do
|
29
|
-
subject.uncertain
|
30
|
-
subject.uncertain
|
29
|
+
expect(subject.uncertain!).to be_uncertain
|
30
|
+
expect(subject.uncertain!).not_to be_certain
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -36,24 +36,24 @@ module EDTF
|
|
36
36
|
describe '#succ' do
|
37
37
|
|
38
38
|
it 'returns a season' do
|
39
|
-
summer.succ.
|
39
|
+
expect(summer.succ).to be_instance_of(Season)
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'it returns a season that is greater than the original one' do
|
43
|
-
summer.succ.
|
43
|
+
expect(summer.succ).to be > summer
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'the successor of the winter season is spring of the following year' do
|
47
47
|
spring = winter.succ
|
48
|
-
spring.
|
49
|
-
spring.year.
|
48
|
+
expect(spring).to be_spring
|
49
|
+
expect(spring.year).to eq(winter.year + 1)
|
50
50
|
end
|
51
51
|
|
52
52
|
end
|
53
53
|
|
54
54
|
describe '#season?' do
|
55
55
|
it 'returns true by default' do
|
56
|
-
subject.
|
56
|
+
expect(subject).to be_season
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -61,38 +61,39 @@ module EDTF
|
|
61
61
|
before(:each) { subject.season = :summer }
|
62
62
|
|
63
63
|
it 'returns the season code' do
|
64
|
-
subject.season.
|
64
|
+
expect(subject.season).to eq(:summer)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
describe '#season=' do
|
69
69
|
it 'sets the season code when called with a valid season code' do
|
70
|
-
|
70
|
+
expect {
|
71
71
|
(21..22).each do |i|
|
72
72
|
subject.season = i
|
73
73
|
end
|
74
|
-
}.
|
74
|
+
}.not_to raise_error
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'throws an exception if given invalid season code' do
|
78
|
-
|
78
|
+
expect { subject.season = 13 }.to raise_error
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
82
|
describe '#summer!' do
|
83
83
|
it 'sets the season to :summer' do
|
84
|
-
|
84
|
+
subject.season = :spring
|
85
|
+
expect { subject.summer! }.to change { subject.season }.to(:summer)
|
85
86
|
end
|
86
87
|
end
|
87
88
|
|
88
89
|
describe '#winter?' do
|
89
90
|
it 'returns true if the season is set to :winter' do
|
90
91
|
subject.season = :winter
|
91
|
-
subject.
|
92
|
+
expect(subject).to be_winter
|
92
93
|
end
|
93
94
|
it 'returns false if the season is not set to :winter' do
|
94
95
|
subject.season = :summer
|
95
|
-
subject.
|
96
|
+
expect(subject).not_to be_winter
|
96
97
|
end
|
97
98
|
end
|
98
99
|
|
@@ -100,7 +101,7 @@ module EDTF
|
|
100
101
|
|
101
102
|
context 'for summer' do
|
102
103
|
it 'returns true for August 24' do
|
103
|
-
Season.new(1980, :summer).
|
104
|
+
expect(Season.new(1980, :summer)).to include(Date.new(1980,8,24))
|
104
105
|
end
|
105
106
|
end
|
106
107
|
|
data/spec/edtf/set_spec.rb
CHANGED
@@ -1,73 +1,73 @@
|
|
1
1
|
module EDTF
|
2
2
|
describe 'Sets' do
|
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
|
-
end
|
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
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
@@ -6,36 +6,36 @@ module EDTF
|
|
6
6
|
|
7
7
|
describe '#uncertain?' do
|
8
8
|
|
9
|
-
it {
|
9
|
+
it { is_expected.to be_certain }
|
10
10
|
|
11
11
|
it 'should be uncertain if at least one part is uncertain' do
|
12
|
-
Uncertainty.new(false, false, true).
|
12
|
+
expect(Uncertainty.new(false, false, true)).to be_uncertain
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'should not be uncertain if all parts are certain' do
|
16
|
-
Uncertainty.new(false, false, false).
|
16
|
+
expect(Uncertainty.new(false, false, false)).to be_certain
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should be uncertain if all parts are uncertain' do
|
20
|
-
Uncertainty.new(true, true, true).
|
20
|
+
expect(Uncertainty.new(true, true, true)).to be_uncertain
|
21
21
|
end
|
22
22
|
|
23
23
|
# [:year, :month, :day, :hour, :minute, :second].each do |part|
|
24
24
|
[:year, :month, :day].each do |part|
|
25
25
|
it "#{ part } should not be uncertain by default" do
|
26
|
-
uncertainty.uncertain?(part).
|
26
|
+
expect(uncertainty.uncertain?(part)).to be false
|
27
27
|
end
|
28
28
|
|
29
29
|
it "#{ part } should be uncertain if set to uncertain" do
|
30
30
|
uncertainty.send("#{part}=", true)
|
31
|
-
uncertainty.uncertain?(part).
|
31
|
+
expect(uncertainty.uncertain?(part)).to be true
|
32
32
|
end
|
33
33
|
|
34
34
|
# ([:year, :month, :day, :hour, :minute, :second] - [part]).each do |other|
|
35
35
|
([:year, :month, :day] - [part]).each do |other|
|
36
36
|
it "#{other} should not be uncertain if #{part} is uncertain" do
|
37
37
|
uncertainty.send("#{part}=", true)
|
38
|
-
uncertainty.uncertain?(other).
|
38
|
+
expect(uncertainty.uncertain?(other)).to be false
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -46,35 +46,35 @@ module EDTF
|
|
46
46
|
describe 'with the default hash base (1)' do
|
47
47
|
|
48
48
|
it 'returns 0 by default' do
|
49
|
-
Uncertainty.new.hash.
|
49
|
+
expect(Uncertainty.new.hash).to eq(0)
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'returns 1 for uncertain year' do
|
53
|
-
Uncertainty.new.hash.
|
53
|
+
expect(Uncertainty.new.hash).to eq(0)
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'returns 2 for uncertain month' do
|
57
|
-
Uncertainty.new.hash.
|
57
|
+
expect(Uncertainty.new.hash).to eq(0)
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'returns 4 for uncertain day' do
|
61
|
-
Uncertainty.new.hash.
|
61
|
+
expect(Uncertainty.new.hash).to eq(0)
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'returns 3 for uncertain year, month' do
|
65
|
-
Uncertainty.new(true, true).hash.
|
65
|
+
expect(Uncertainty.new(true, true).hash).to eq(3)
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'returns 7 for uncertain year, month, day' do
|
69
|
-
Uncertainty.new(true, true, true).hash.
|
69
|
+
expect(Uncertainty.new(true, true, true).hash).to eq(7)
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'returns 5 for uncertain year, day' do
|
73
|
-
Uncertainty.new(true, nil, true).hash.
|
73
|
+
expect(Uncertainty.new(true, nil, true).hash).to eq(5)
|
74
74
|
end
|
75
75
|
|
76
76
|
it 'returns 6 for uncertain month, day' do
|
77
|
-
Uncertainty.new(nil, true, true).hash.
|
77
|
+
expect(Uncertainty.new(nil, true, true).hash).to eq(6)
|
78
78
|
end
|
79
79
|
|
80
80
|
end
|
@@ -85,7 +85,7 @@ module EDTF
|
|
85
85
|
|
86
86
|
describe '#uncertain!' do
|
87
87
|
it 'should make all parts certain when no part given' do
|
88
|
-
|
88
|
+
expect { uncertainty.uncertain! }.to change { uncertainty.certain? }
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
@@ -97,56 +97,56 @@ module EDTF
|
|
97
97
|
|
98
98
|
describe '#unspecified?' do
|
99
99
|
it 'should return false by default' do
|
100
|
-
u.
|
100
|
+
expect(u).not_to be_unspecified
|
101
101
|
end
|
102
102
|
|
103
103
|
it 'should return true if the day is unspecified' do
|
104
|
-
u.unspecified!(:day).
|
104
|
+
expect(u.unspecified!(:day)).to be_unspecified
|
105
105
|
end
|
106
106
|
|
107
107
|
it 'should return true if the month is unspecified' do
|
108
|
-
u.unspecified!(:month).
|
108
|
+
expect(u.unspecified!(:month)).to be_unspecified
|
109
109
|
end
|
110
110
|
|
111
111
|
it 'should return true if the year is unspecified' do
|
112
|
-
u.unspecified!(:year).
|
112
|
+
expect(u.unspecified!(:year)).to be_unspecified
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
116
|
describe '#year' do
|
117
117
|
it 'returns the year values' do
|
118
|
-
u.year.
|
118
|
+
expect(u.year).to eq([nil,nil,nil,nil])
|
119
119
|
end
|
120
120
|
|
121
121
|
it 'allows you to set individual offsets' do
|
122
122
|
u.year[1] = true
|
123
|
-
u.to_s.
|
123
|
+
expect(u.to_s).to eq('suss-ss-ss')
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
127
|
describe '#to_s' do
|
128
128
|
it 'should be return "ssss-ss-ss" by default' do
|
129
|
-
u.to_s.
|
129
|
+
expect(u.to_s).to eq('ssss-ss-ss')
|
130
130
|
end
|
131
131
|
|
132
132
|
it 'should return "ssss-ss-uu" if the day is unspecified' do
|
133
|
-
u.unspecified!(:day).to_s.
|
133
|
+
expect(u.unspecified!(:day).to_s).to eq('ssss-ss-uu')
|
134
134
|
end
|
135
135
|
|
136
136
|
it 'should return "ssss-uu-ss" if the month is unspecified' do
|
137
|
-
u.unspecified!(:month).to_s.
|
137
|
+
expect(u.unspecified!(:month).to_s).to eq('ssss-uu-ss')
|
138
138
|
end
|
139
139
|
|
140
140
|
it 'should return "ssss-uu-uu" if month and day are unspecified' do
|
141
|
-
u.unspecified!([:day, :month]).to_s.
|
141
|
+
expect(u.unspecified!([:day, :month]).to_s).to eq('ssss-uu-uu')
|
142
142
|
end
|
143
143
|
|
144
144
|
it 'should return "uuuu-ss-ss" if the year is unspecified' do
|
145
|
-
u.unspecified!(:year).to_s.
|
145
|
+
expect(u.unspecified!(:year).to_s).to eq('uuuu-ss-ss')
|
146
146
|
end
|
147
147
|
|
148
148
|
it 'should return "uuuu-uu-uu" if the date is unspecified' do
|
149
|
-
u.unspecified!.to_s.
|
149
|
+
expect(u.unspecified!.to_s).to eq('uuuu-uu-uu')
|
150
150
|
end
|
151
151
|
|
152
152
|
end
|
@@ -155,7 +155,7 @@ module EDTF
|
|
155
155
|
|
156
156
|
context 'when passed an empty array' do
|
157
157
|
it 'should return an empty array' do
|
158
|
-
u.mask([]).
|
158
|
+
expect(u.mask([])).to eq([])
|
159
159
|
end
|
160
160
|
end
|
161
161
|
|
@@ -163,14 +163,14 @@ module EDTF
|
|
163
163
|
let(:date) { ['1994'] }
|
164
164
|
|
165
165
|
it 'should return the array with the year by default' do
|
166
|
-
u.mask(date).
|
166
|
+
expect(u.mask(date)).to eq(['1994'])
|
167
167
|
end
|
168
168
|
|
169
169
|
context 'when the year is unspecified' do
|
170
170
|
before(:each) { u.year[3] = true }
|
171
171
|
|
172
172
|
it 'should return the array with the year and the fourth digit masked' do
|
173
|
-
u.mask(date).
|
173
|
+
expect(u.mask(date)).to eq(['199u'])
|
174
174
|
end
|
175
175
|
|
176
176
|
end
|
@@ -179,7 +179,7 @@ module EDTF
|
|
179
179
|
before(:each) { u.year[2,2] = [true,true] }
|
180
180
|
|
181
181
|
it 'should return the array with the year and the third and fourth digit masked' do
|
182
|
-
u.mask(date).
|
182
|
+
expect(u.mask(date)).to eq(['19uu'])
|
183
183
|
end
|
184
184
|
|
185
185
|
end
|
@@ -190,21 +190,21 @@ module EDTF
|
|
190
190
|
let(:date) { ['1994', '01'] }
|
191
191
|
|
192
192
|
it 'should return the array with the year by default' do
|
193
|
-
u.mask(date).
|
193
|
+
expect(u.mask(date)).to eq(['1994', '01'])
|
194
194
|
end
|
195
195
|
|
196
196
|
context 'when the year is unspecified' do
|
197
197
|
before(:each) { u.year[3] = true }
|
198
198
|
|
199
199
|
it 'should return the array with the year and the fourth digit masked' do
|
200
|
-
u.mask(date).
|
200
|
+
expect(u.mask(date)).to eq(['199u', '01'])
|
201
201
|
end
|
202
202
|
|
203
203
|
context 'when the month is unspecified' do
|
204
204
|
before(:each) { u.unspecified! :month }
|
205
205
|
|
206
206
|
it 'should return the array with the month masked' do
|
207
|
-
u.mask(date).
|
207
|
+
expect(u.mask(date)).to eq(['199u', 'uu'])
|
208
208
|
end
|
209
209
|
end
|
210
210
|
end
|
@@ -213,14 +213,14 @@ module EDTF
|
|
213
213
|
before(:each) { u.year[2,2] = [true,true] }
|
214
214
|
|
215
215
|
it 'should return the array with the year and the third and fourth digit masked' do
|
216
|
-
u.mask(date).
|
216
|
+
expect(u.mask(date)).to eq(['19uu', '01'])
|
217
217
|
end
|
218
218
|
|
219
219
|
context 'when the month is unspecified' do
|
220
220
|
before(:each) { u.unspecified! :month }
|
221
221
|
|
222
222
|
it 'should return the array with the month masked' do
|
223
|
-
u.mask(date).
|
223
|
+
expect(u.mask(date)).to eq(['19uu', 'uu'])
|
224
224
|
end
|
225
225
|
end
|
226
226
|
end
|
@@ -229,7 +229,7 @@ module EDTF
|
|
229
229
|
before(:each) { u.unspecified! :month }
|
230
230
|
|
231
231
|
it 'should return the array with the month masked' do
|
232
|
-
u.mask(date).
|
232
|
+
expect(u.mask(date)).to eq(['1994', 'uu'])
|
233
233
|
end
|
234
234
|
end
|
235
235
|
|
@@ -239,28 +239,28 @@ module EDTF
|
|
239
239
|
let(:date) { ['1994', '01', '27'] }
|
240
240
|
|
241
241
|
it 'should return the array with the date by default' do
|
242
|
-
u.mask(date).
|
242
|
+
expect(u.mask(date)).to eq(['1994', '01', '27'])
|
243
243
|
end
|
244
244
|
|
245
245
|
context 'when the year is unspecified' do
|
246
246
|
before(:each) { u.year[3] = true }
|
247
247
|
|
248
248
|
it 'should return the array with the year and the fourth digit masked' do
|
249
|
-
u.mask(date).
|
249
|
+
expect(u.mask(date)).to eq(['199u', '01', '27'])
|
250
250
|
end
|
251
251
|
|
252
252
|
context 'when the month is unspecified' do
|
253
253
|
before(:each) { u.unspecified! :month }
|
254
254
|
|
255
255
|
it 'should return the array with the month masked' do
|
256
|
-
u.mask(date).
|
256
|
+
expect(u.mask(date)).to eq(['199u', 'uu', '27'])
|
257
257
|
end
|
258
258
|
|
259
259
|
context 'when the day is unspecified' do
|
260
260
|
before(:each) { u.unspecified! :day }
|
261
261
|
|
262
262
|
it 'should return the array with the month masked' do
|
263
|
-
u.mask(date).
|
263
|
+
expect(u.mask(date)).to eq(['199u', 'uu', 'uu'])
|
264
264
|
end
|
265
265
|
end
|
266
266
|
end
|