calendarium-romanum 0.2.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/bin/calendariumrom +4 -1
- data/config/locales/cs.yml +54 -2
- data/config/locales/en.yml +64 -14
- data/config/locales/es.yml +90 -0
- data/config/locales/fr.yml +90 -0
- data/config/locales/it.yml +54 -4
- data/config/locales/la.yml +52 -2
- data/data/README.md +105 -5
- data/data/czech-brno-cs.txt +11 -5
- data/data/czech-budejovice-cs.txt +11 -5
- data/data/czech-cechy-cs.txt +11 -5
- data/data/czech-cs.txt +243 -234
- data/data/czech-hradec-cs.txt +10 -4
- data/data/czech-litomerice-cs.txt +12 -6
- data/data/czech-morava-cs.txt +11 -5
- data/data/czech-olomouc-cs.txt +9 -3
- data/data/czech-ostrava-cs.txt +10 -4
- data/data/czech-plzen-cs.txt +10 -4
- data/data/czech-praha-cs.txt +10 -3
- data/data/universal-en.txt +218 -212
- data/data/universal-es.txt +243 -0
- data/data/universal-fr.txt +243 -0
- data/data/universal-it.txt +218 -212
- data/data/universal-la.txt +218 -211
- data/lib/calendarium-romanum.rb +30 -18
- data/lib/calendarium-romanum/abstract_date.rb +12 -0
- data/lib/calendarium-romanum/calendar.rb +210 -48
- data/lib/calendarium-romanum/cli.rb +101 -52
- data/lib/calendarium-romanum/cr.rb +16 -0
- data/lib/calendarium-romanum/data.rb +46 -18
- data/lib/calendarium-romanum/day.rb +200 -21
- data/lib/calendarium-romanum/enum.rb +24 -5
- data/lib/calendarium-romanum/enums.rb +123 -37
- data/lib/calendarium-romanum/errors.rb +4 -0
- data/lib/calendarium-romanum/ordinalizer.rb +61 -0
- data/lib/calendarium-romanum/perpetual_calendar.rb +97 -0
- data/lib/calendarium-romanum/rank.rb +43 -6
- data/lib/calendarium-romanum/sanctorale.rb +142 -22
- data/lib/calendarium-romanum/sanctorale_factory.rb +74 -3
- data/lib/calendarium-romanum/sanctorale_loader.rb +176 -0
- data/lib/calendarium-romanum/temporale.rb +296 -251
- data/lib/calendarium-romanum/temporale/celebration_factory.rb +106 -0
- data/lib/calendarium-romanum/temporale/dates.rb +232 -0
- data/lib/calendarium-romanum/temporale/extensions/christ_eternal_priest.rb +37 -0
- data/lib/calendarium-romanum/transfers.rb +43 -6
- data/lib/calendarium-romanum/util.rb +36 -3
- data/lib/calendarium-romanum/version.rb +5 -1
- data/spec/abstract_date_spec.rb +11 -3
- data/spec/calendar_spec.rb +645 -188
- data/spec/celebration_factory_spec.rb +40 -0
- data/spec/celebration_spec.rb +67 -0
- data/spec/cli_spec.rb +154 -11
- data/spec/colour_spec.rb +22 -0
- data/spec/data_spec.rb +26 -3
- data/spec/date_parser_spec.rb +68 -0
- data/spec/date_spec.rb +8 -8
- data/spec/dates_spec.rb +73 -0
- data/spec/day_spec.rb +151 -0
- data/spec/i18n_spec.rb +11 -2
- data/spec/ordinalizer_spec.rb +44 -0
- data/spec/perpetual_calendar_spec.rb +125 -0
- data/spec/rank_spec.rb +42 -7
- data/spec/readme_spec.rb +18 -10
- data/spec/sanctorale_factory_spec.rb +113 -9
- data/spec/sanctorale_loader_spec.rb +229 -0
- data/spec/sanctorale_spec.rb +176 -62
- data/spec/season_spec.rb +22 -0
- data/spec/spec_helper.rb +27 -1
- data/spec/temporale_spec.rb +473 -154
- data/spec/year_spec.rb +25 -0
- metadata +42 -7
- data/lib/calendarium-romanum/sanctoraleloader.rb +0 -104
- data/spec/sanctoraleloader_spec.rb +0 -171
data/spec/readme_spec.rb
CHANGED
@@ -34,16 +34,24 @@ class MarkdownDocument
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
37
|
+
%w(README.md data/README.md).each do |path|
|
38
|
+
describe path do
|
39
|
+
before :each do
|
40
|
+
# README examples sometimes print, but we don't want them
|
41
|
+
# to distort test output
|
42
|
+
allow(STDERR).to receive :puts
|
43
|
+
end
|
44
|
+
|
45
|
+
readme_path = File.expand_path('../../' + path, __FILE__)
|
46
|
+
readme = File.read readme_path
|
47
|
+
doc = MarkdownDocument.new readme
|
48
|
+
|
49
|
+
doc.each_ruby_example do |code, line|
|
50
|
+
describe "example L#{line}" do
|
51
|
+
it 'executes without failure' do
|
52
|
+
cls = Class.new
|
53
|
+
cls.class_eval(code, readme_path, line)
|
54
|
+
end
|
47
55
|
end
|
48
56
|
end
|
49
57
|
end
|
@@ -2,18 +2,100 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe CR::SanctoraleFactory do
|
5
|
-
describe '.create_layered'
|
5
|
+
describe '.create_layered' do
|
6
|
+
describe 'metadata handling' do
|
7
|
+
let(:metadata_a) { {'title' => 'Calendar', 'foo' => 'bar'} }
|
8
|
+
let(:metadata_b) { {'title' => 'Second calendar', 'some' => 'handsome', 'extends' => ['with_a']} }
|
9
|
+
let(:metadata_nonhash) { [:something] }
|
10
|
+
let(:with_a) { CR::Sanctorale.new.tap {|s| s.metadata = metadata_a }}
|
11
|
+
let(:with_b) { CR::Sanctorale.new.tap {|s| s.metadata = metadata_b } }
|
12
|
+
let(:without) { CR::Sanctorale.new }
|
13
|
+
let(:with_nonhash) { CR::Sanctorale.new.tap {|s| s.metadata = metadata_nonhash } }
|
6
14
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
15
|
+
it 'creates merged metadata' do
|
16
|
+
merged = {
|
17
|
+
# conflicting key - later wins
|
18
|
+
'title' => 'Second calendar',
|
19
|
+
# non-conflicting key from the first
|
20
|
+
'foo' => 'bar',
|
21
|
+
# non-conflicting key from the second
|
22
|
+
'some' => 'handsome',
|
23
|
+
}
|
24
|
+
|
25
|
+
result = described_class.create_layered(with_a, with_b)
|
26
|
+
|
27
|
+
expect(merged).to be < result.metadata
|
28
|
+
|
29
|
+
# key 'extends' has special meaning and is therefore
|
30
|
+
# always deleted from merged metadata
|
31
|
+
expect(result.metadata).not_to have_key 'extends'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'stores original metadata' do
|
35
|
+
result = described_class.create_layered(with_a, with_b)
|
36
|
+
expect(result.metadata['components'])
|
37
|
+
.to eq [metadata_a, metadata_b]
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'overwrites key "components" if it exists' do
|
41
|
+
result = described_class.create_layered(
|
42
|
+
with_a,
|
43
|
+
# this calendar's metadata have key 'components',
|
44
|
+
# but that key is special and we always set it's contents
|
45
|
+
# when merging
|
46
|
+
CR::Sanctorale.new.tap {|s| s.metadata = {'components' => :c} }
|
47
|
+
)
|
48
|
+
expect(result.metadata['components'])
|
49
|
+
.to eq [metadata_a, {'components' => :c}]
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'copes with nil metadata on the first place' do
|
53
|
+
result = described_class.create_layered(without, with_a)
|
54
|
+
|
55
|
+
expect(metadata_a).to be < result.metadata
|
56
|
+
expect(result.metadata['components'])
|
57
|
+
.to eq [nil, metadata_a] # nils are preserved in 'components'
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'copes with nil metadata on the last place' do
|
61
|
+
result = described_class.create_layered(with_a, without)
|
62
|
+
|
63
|
+
expect(metadata_a).to be < result.metadata
|
64
|
+
expect(result.metadata['components'])
|
65
|
+
.to eq [metadata_a, nil]
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'copes with all nil' do
|
69
|
+
result = described_class.create_layered(without, without)
|
70
|
+
|
71
|
+
expect(result.metadata['components'])
|
72
|
+
.to eq [nil, nil]
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'copes with non-Hash metadata' do
|
76
|
+
result = described_class.create_layered(
|
77
|
+
with_a,
|
78
|
+
with_nonhash
|
79
|
+
)
|
80
|
+
# non-Hash metadata are not merged, but they do appear
|
81
|
+
# in 'components'
|
82
|
+
expect(metadata_a).to be < result.metadata
|
83
|
+
expect(result.metadata['components'])
|
84
|
+
.to eq [metadata_a, metadata_nonhash]
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'copes with all non-Hash' do
|
88
|
+
result = described_class.create_layered(with_nonhash)
|
89
|
+
|
90
|
+
expect(result.metadata['components'])
|
91
|
+
.to eq [metadata_nonhash]
|
11
92
|
end
|
12
|
-
@s = described_class.load_layered_from_files(*files)
|
13
93
|
end
|
94
|
+
end
|
14
95
|
|
96
|
+
shared_examples 'calendar layering České Budějovice' do
|
15
97
|
it 'has celebrations from the first file' do
|
16
|
-
dd =
|
98
|
+
dd = layered_sanctorale.get 9, 28
|
17
99
|
expect(dd.size).to eq 1
|
18
100
|
|
19
101
|
d = dd.first
|
@@ -22,7 +104,7 @@ describe CR::SanctoraleFactory do
|
|
22
104
|
end
|
23
105
|
|
24
106
|
it 'has celebrations from the second file' do
|
25
|
-
dd =
|
107
|
+
dd = layered_sanctorale.get 7, 4
|
26
108
|
expect(dd.size).to eq 1
|
27
109
|
|
28
110
|
d = dd.first
|
@@ -31,7 +113,7 @@ describe CR::SanctoraleFactory do
|
|
31
113
|
end
|
32
114
|
|
33
115
|
it 'celebrations from the last file win' do
|
34
|
-
dd =
|
116
|
+
dd = layered_sanctorale.get 12, 22
|
35
117
|
expect(dd.size).to eq 1
|
36
118
|
|
37
119
|
d = dd.first
|
@@ -39,4 +121,26 @@ describe CR::SanctoraleFactory do
|
|
39
121
|
expect(d.title).to eq 'Výročí posvěcení katedrály sv. Mikuláše'
|
40
122
|
end
|
41
123
|
end
|
124
|
+
|
125
|
+
describe '.load_layered_from_files' do
|
126
|
+
let(:layered_sanctorale) do
|
127
|
+
files = %w(czech-cs.txt czech-cechy-cs.txt czech-budejovice-cs.txt).collect do |f|
|
128
|
+
File.join(File.expand_path('../data', File.dirname(__FILE__)), f)
|
129
|
+
end
|
130
|
+
|
131
|
+
described_class.load_layered_from_files(*files)
|
132
|
+
end
|
133
|
+
|
134
|
+
include_examples 'calendar layering České Budějovice'
|
135
|
+
end
|
136
|
+
|
137
|
+
describe '.load_with_parents' do
|
138
|
+
let(:layered_sanctorale) do
|
139
|
+
path = File.join(File.expand_path('../data', File.dirname(__FILE__)), 'czech-budejovice-cs.txt')
|
140
|
+
|
141
|
+
described_class.load_with_parents path
|
142
|
+
end
|
143
|
+
|
144
|
+
include_examples 'calendar layering České Budějovice'
|
145
|
+
end
|
42
146
|
end
|
@@ -0,0 +1,229 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CR::SanctoraleLoader do
|
4
|
+
let(:s) { CR::Sanctorale.new }
|
5
|
+
let(:l) { CR::SanctoraleLoader.new }
|
6
|
+
|
7
|
+
describe 'data sources' do
|
8
|
+
describe '#load_from_string' do
|
9
|
+
before :each do
|
10
|
+
str = '1/3 : Ss.mi Nominis Iesu'
|
11
|
+
l.load_from_string str, s
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'loads one entry' do
|
15
|
+
expect(s.size).to eq 1
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#load_from_file' do
|
20
|
+
it 'loads something from file' do
|
21
|
+
l.load_from_file(File.join(%w(data universal-la.txt)), s)
|
22
|
+
expect(s.size).to be > 190
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'record/file format' do
|
28
|
+
let(:record) { '4/25 f R : S. Marci, evangelistae' }
|
29
|
+
let(:result) { l.send :load_line, record }
|
30
|
+
|
31
|
+
describe 'title' do
|
32
|
+
it 'loads it' do
|
33
|
+
expect(result.title).to eq 'S. Marci, evangelistae'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'date' do
|
38
|
+
describe 'full date as part of the record' do
|
39
|
+
it 'loads date' do
|
40
|
+
expect(result.date).to eq CR::AbstractDate.new(4, 25)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'month as heading' do
|
45
|
+
before :each do
|
46
|
+
str = [
|
47
|
+
# month heading + day-only record
|
48
|
+
'= 1',
|
49
|
+
'25 f : In conversione S. Pauli, apostoli',
|
50
|
+
# record with full date specified
|
51
|
+
'4/25 f r : S. Marci, evangelistae',
|
52
|
+
].join "\n"
|
53
|
+
l.load_from_string str, s
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'loads a month heading and uses the month for subsequent records' do
|
57
|
+
expect(s.get(1, 25)).not_to be_empty
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'still allows full date specified in the record' do
|
61
|
+
expect(s.get(4, 25)).not_to be_empty
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'colour' do
|
67
|
+
describe 'not specified - sets default' do
|
68
|
+
let(:record) { '4/25 : S. Marci, evangelistae' }
|
69
|
+
it { expect(result.colour).to eq CR::Colours::WHITE }
|
70
|
+
end
|
71
|
+
|
72
|
+
describe 'sets colour if specified' do
|
73
|
+
let(:record) { '4/25 f R : S. Marci, evangelistae' }
|
74
|
+
it { expect(result.colour).to eq CR::Colours::RED }
|
75
|
+
end
|
76
|
+
|
77
|
+
describe 'sets colour if specified (lowercase)' do
|
78
|
+
let(:record) { '4/25 f r : S. Marci, evangelistae' }
|
79
|
+
it { expect(result.colour).to eq CR::Colours::RED }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe 'rank' do
|
84
|
+
# say we specify a proper calendar of a church dedicated to St. George
|
85
|
+
describe 'not specified - sets default' do
|
86
|
+
let(:record) { '4/23 : S. Georgii, martyris' }
|
87
|
+
it { expect(result.rank).to eq CR::Ranks::MEMORIAL_OPTIONAL }
|
88
|
+
end
|
89
|
+
|
90
|
+
describe 'sets rank if specified' do
|
91
|
+
let(:record) { '4/23 s R : S. Georgii, martyris' }
|
92
|
+
it { expect(result.rank).to eq CR::Ranks::SOLEMNITY_GENERAL }
|
93
|
+
end
|
94
|
+
|
95
|
+
describe 'sets rank if specified (uppercase)' do
|
96
|
+
let(:record) { '4/23 S R : S. Georgii, martyris' }
|
97
|
+
it { expect(result.rank).to eq CR::Ranks::SOLEMNITY_GENERAL }
|
98
|
+
end
|
99
|
+
|
100
|
+
describe 'sets exact rank if specified' do
|
101
|
+
let(:record) { '4/23 s1.4 R : S. Georgii, martyris' }
|
102
|
+
it { expect(result.rank).to eq CR::Ranks::SOLEMNITY_PROPER }
|
103
|
+
end
|
104
|
+
|
105
|
+
describe 'sets exact rank if specified only by number' do
|
106
|
+
let(:record) { '4/23 1.4 R : S. Georgii, martyris' }
|
107
|
+
it { expect(result.rank).to eq CR::Ranks::SOLEMNITY_PROPER }
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe 'symbol' do
|
112
|
+
describe 'not specified - sets default' do
|
113
|
+
let(:record) { '4/23 : S. Georgii, martyris' }
|
114
|
+
it { expect(result.symbol).to be nil }
|
115
|
+
end
|
116
|
+
|
117
|
+
describe 'specified - uses it' do
|
118
|
+
let(:record) { '4/23 george : S. Georgii, martyris' }
|
119
|
+
it { expect(result.symbol).to be :george }
|
120
|
+
end
|
121
|
+
|
122
|
+
describe 'supported characters' do
|
123
|
+
let(:record) { '4/29 none_123 : S. Nullius, abbatis' }
|
124
|
+
it { expect(result.symbol).to be :none_123 }
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe 'Celebration properties set regardless of the loaded data' do
|
130
|
+
describe 'cycle' do
|
131
|
+
it 'always sets it to :sanctorale' do
|
132
|
+
str = '4/23 1.4 R : S. Georgii, martyris'
|
133
|
+
record = l.send :load_line, str
|
134
|
+
expect(record.cycle).to be :sanctorale
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe 'invalid input' do
|
140
|
+
describe 'syntax errors' do
|
141
|
+
it 'invalid syntax' do
|
142
|
+
str = 'line without standard beginning'
|
143
|
+
expect do
|
144
|
+
l.load_from_string str, s
|
145
|
+
end.to raise_exception(CR::InvalidDataError, /Syntax error/)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe 'syntactically correct data making no sense' do
|
150
|
+
it 'invalid month heading' do
|
151
|
+
str = '= 13'
|
152
|
+
expect do
|
153
|
+
l.load_from_string str, s
|
154
|
+
end.to raise_exception(CR::InvalidDataError, /Invalid month/)
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'one more invalid month heading' do
|
158
|
+
str = '= 0'
|
159
|
+
expect do
|
160
|
+
l.load_from_string str, s
|
161
|
+
end.to raise_exception(CR::InvalidDataError, /Invalid month/)
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'invalid month' do
|
165
|
+
str = '100/25 f : In conversione S. Pauli, apostoli'
|
166
|
+
expect do
|
167
|
+
l.load_from_string str, s
|
168
|
+
end.to raise_exception(CR::InvalidDataError, /Invalid month/)
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'line with day only, without preceding month heading' do
|
172
|
+
str = '25 f : In conversione S. Pauli, apostoli'
|
173
|
+
expect do
|
174
|
+
l.load_from_string str, s
|
175
|
+
end.to raise_exception(CR::InvalidDataError, /Invalid month/)
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'invalid day' do
|
179
|
+
str = '1/250 f : In conversione S. Pauli, apostoli'
|
180
|
+
expect do
|
181
|
+
l.load_from_string str, s
|
182
|
+
end.to raise_exception(CR::InvalidDataError, /Invalid day/)
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'invalid rank' do
|
186
|
+
str = '1/25 X : In conversione S. Pauli, apostoli'
|
187
|
+
expect do
|
188
|
+
l.load_from_string str, s
|
189
|
+
end.to raise_exception(CR::InvalidDataError, /Syntax error/)
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'invalid numeric rank' do
|
193
|
+
str = '4/23 s8.4 R : S. Georgii, martyris'
|
194
|
+
expect do
|
195
|
+
l.load_from_string str, s
|
196
|
+
end.to raise_exception(CR::InvalidDataError, /rank/)
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'invalid combination of rank latter and number' do
|
200
|
+
str = '4/23 m2.5 R : S. Georgii, martyris'
|
201
|
+
expect do
|
202
|
+
l.load_from_string str, s
|
203
|
+
end.to raise_exception(CR::InvalidDataError, /rank/)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
describe 'YAML front matter (YFM)' do
|
209
|
+
it 'sets metadata nil if YFM is not provided' do
|
210
|
+
expect(l.load_from_string('').metadata)
|
211
|
+
.to be nil
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'loads metadata if provided' do
|
215
|
+
expect(l.load_from_string("---\nkey: value\n---").metadata)
|
216
|
+
.to eq({'key' => 'value'})
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'does not load metadata with no end' do
|
220
|
+
# Since YFM is being processed on encountering the closing
|
221
|
+
# triple-dash, YFM spanning the whole file and not properly
|
222
|
+
# closed will not be loaded.
|
223
|
+
# (Implementation detail and crazy edge case, may change
|
224
|
+
# in future without warning.)
|
225
|
+
expect(l.load_from_string("---\nkey: value").metadata)
|
226
|
+
.to be nil
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
data/spec/sanctorale_spec.rb
CHANGED
@@ -1,167 +1,281 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe CR::Sanctorale do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
let(:s) { described_class.new }
|
5
|
+
|
6
|
+
# example celebrations
|
7
|
+
let(:antonius) { CR::Celebration.new('S. Antonii, abbatis', CR::Ranks::MEMORIAL_GENERAL, CR::Colours::WHITE, :antonius) }
|
8
|
+
let(:nullus) { CR::Celebration.new('S. Nullius', CR::Ranks::MEMORIAL_OPTIONAL, CR::Colours::WHITE, :nullus) }
|
9
|
+
let(:ignotus) { CR::Celebration.new('S. Ignoti', CR::Ranks::MEMORIAL_OPTIONAL, CR::Colours::WHITE, :ignotus) }
|
10
|
+
let(:opt_memorial) { nullus }
|
11
|
+
let(:opt_memorial_2) { ignotus }
|
12
|
+
let(:solemnity) { CR::Celebration.new('S. Nullius', CR::Ranks::SOLEMNITY_PROPER, CR::Colours::WHITE, :nullus_solemnity) }
|
7
13
|
|
8
14
|
describe '#get' do
|
9
|
-
describe 'for empty day' do
|
15
|
+
describe 'for an empty day' do
|
10
16
|
it 'returns an Array' do
|
11
|
-
expect(
|
17
|
+
expect(s.get(1, 3)).to be_an Array
|
12
18
|
end
|
13
19
|
end
|
14
20
|
|
15
|
-
describe 'for unempty day' do
|
21
|
+
describe 'for an unempty day' do
|
16
22
|
before :each do
|
17
|
-
|
18
|
-
@s.add 1, 17, @c
|
23
|
+
s.add 1, 17, antonius
|
19
24
|
end
|
20
25
|
|
21
26
|
it 'get by month, day' do
|
22
|
-
expect(
|
27
|
+
expect(s.get(1, 17)).to eq [antonius]
|
23
28
|
end
|
24
29
|
|
25
30
|
it 'get by Date' do
|
26
|
-
expect(
|
31
|
+
expect(s.get(Date.new(2014, 1, 17))).to eq [antonius]
|
27
32
|
end
|
28
33
|
|
29
34
|
it 'may have more CR::Celebrations for a day' do
|
30
35
|
[
|
31
|
-
|
32
|
-
|
33
|
-
].each {|t|
|
34
|
-
expect(
|
36
|
+
'S. Fabiani, papae et martyris',
|
37
|
+
'S. Sebastiani, martyris'
|
38
|
+
].each {|t| s.add 1, 20, CR::Celebration.new(t, CR::Ranks::MEMORIAL_OPTIONAL) }
|
39
|
+
expect(s.get(1, 20).size).to eq 2
|
35
40
|
end
|
36
41
|
end
|
37
42
|
end
|
38
43
|
|
39
44
|
describe '#add' do
|
40
45
|
it 'adds a CR::Celebration to one month only' do
|
41
|
-
|
42
|
-
expect(
|
46
|
+
s.add 1, 17, antonius
|
47
|
+
expect(s.get(2, 17)).to be_empty
|
43
48
|
end
|
44
49
|
|
45
50
|
it 'does not allow month 0' do
|
46
|
-
expect {
|
51
|
+
expect { s.add 0, 1, opt_memorial }.to raise_exception RangeError
|
47
52
|
end
|
48
53
|
|
49
54
|
it 'does not allow month higher than 12' do
|
50
|
-
expect {
|
55
|
+
expect { s.add 13, 1, opt_memorial }.to raise_exception RangeError
|
51
56
|
end
|
52
57
|
|
53
58
|
it 'adds solemnity to a dedicated container' do
|
54
|
-
expect {
|
59
|
+
expect { s.add 1, 13, solemnity }.to change { s.solemnities.size }.by 1
|
55
60
|
end
|
56
61
|
|
57
62
|
it 'does not add non-solemnity to solemnities' do
|
58
|
-
expect {
|
63
|
+
expect { s.add 1, 13, opt_memorial }.not_to change { s.solemnities.size }
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'fails when adding second celebration with the same symbol' do
|
67
|
+
s.add 1, 13, antonius
|
68
|
+
|
69
|
+
expect do
|
70
|
+
s.add 1, 14, antonius
|
71
|
+
end.to raise_exception ArgumentError, /duplicate symbol :antonius/
|
59
72
|
end
|
60
73
|
|
61
74
|
describe 'multiple celebrations on a single day' do
|
62
75
|
it 'succeeds for any number of optional memorials' do
|
76
|
+
s.add 1, 13, opt_memorial
|
77
|
+
|
63
78
|
expect do
|
64
|
-
|
65
|
-
@s.add 1, 13, CR::Celebration.new('S. Ignoti', CR::Ranks::MEMORIAL_OPTIONAL)
|
79
|
+
s.add 1, 13, opt_memorial_2
|
66
80
|
end.not_to raise_exception
|
67
81
|
end
|
68
82
|
|
69
83
|
it 'fails when adding a non-optional memorial' do
|
84
|
+
s.add 1, 13, opt_memorial
|
85
|
+
|
70
86
|
expect do
|
71
|
-
|
72
|
-
@s.add 1, 13, CR::Celebration.new('S. Ignoti', CR::Ranks::MEMORIAL_GENERAL)
|
87
|
+
s.add 1, 13, CR::Celebration.new('S. Ignoti', CR::Ranks::MEMORIAL_GENERAL)
|
73
88
|
end.to raise_exception ArgumentError
|
74
89
|
end
|
75
90
|
|
76
91
|
it 'fails when adding to a non-optional memorial' do
|
92
|
+
s.add 1, 13, CR::Celebration.new('S. Nullius', CR::Ranks::MEMORIAL_GENERAL)
|
93
|
+
|
77
94
|
expect do
|
78
|
-
|
79
|
-
@s.add 1, 13, CR::Celebration.new('S. Ignoti', CR::Ranks::MEMORIAL_OPTIONAL)
|
95
|
+
s.add 1, 13, opt_memorial_2
|
80
96
|
end.to raise_exception ArgumentError
|
81
97
|
end
|
98
|
+
|
99
|
+
# there used to be a bug, registering a solemnity *before*
|
100
|
+
# checking if it can be added at all
|
101
|
+
it 'does not modify internal state when it fails' do
|
102
|
+
s.add 1, 13, opt_memorial
|
103
|
+
|
104
|
+
expect do
|
105
|
+
begin
|
106
|
+
s.add 1, 13, CR::Celebration.new('S. Nullius', CR::Ranks::SOLEMNITY_GENERAL)
|
107
|
+
rescue ArgumentError
|
108
|
+
end
|
109
|
+
end.not_to change { s.solemnities.size }
|
110
|
+
end
|
82
111
|
end
|
83
112
|
end
|
84
113
|
|
85
114
|
describe '#replace' do
|
86
115
|
it 'replaces the original celebration(s)' do
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
@s.add 1, 13, nemo
|
91
|
-
@s.replace 1, 13, [nonus]
|
116
|
+
s.add 1, 13, opt_memorial_2
|
117
|
+
s.replace 1, 13, [solemnity]
|
92
118
|
|
93
|
-
expect(
|
119
|
+
expect(s.get(1, 13)).to eq [solemnity]
|
94
120
|
end
|
95
121
|
|
96
122
|
it 'adds solemnity to a dedicated container' do
|
97
|
-
nonus = CR::Celebration.new('S. Noni', CR::Ranks::SOLEMNITY_PROPER)
|
98
123
|
expect do
|
99
|
-
|
100
|
-
end.to change {
|
124
|
+
s.replace 1, 13, [solemnity]
|
125
|
+
end.to change { s.solemnities.size }.by 1
|
101
126
|
end
|
102
127
|
|
103
128
|
it 'removes solemnity' do
|
104
|
-
|
105
|
-
nonus = CR::Celebration.new('S. Noni')
|
106
|
-
|
107
|
-
@s.add 1, 13, nemo
|
129
|
+
s.add 1, 13, solemnity
|
108
130
|
expect do
|
109
|
-
|
110
|
-
end.to change {
|
131
|
+
s.replace 1, 13, [opt_memorial_2]
|
132
|
+
end.to change { s.solemnities.size }.by(-1)
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'does not simply save the passed Array' do
|
136
|
+
array = [opt_memorial]
|
137
|
+
s.replace 1, 13, array
|
138
|
+
|
139
|
+
array << nil
|
140
|
+
|
141
|
+
expect(s.get(1, 13)).not_to include nil
|
142
|
+
end
|
143
|
+
|
144
|
+
describe 'duplicate symbol handling' do
|
145
|
+
it 'fails when adding second celebration with the same symbol' do
|
146
|
+
s.replace 1, 13, [nullus]
|
147
|
+
|
148
|
+
expect do
|
149
|
+
s.replace 1, 14, [nullus]
|
150
|
+
end.to raise_exception ArgumentError, /duplicate symbols \[:nullus\]/
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'failed attempts do not modify state of the internal symbol set' do
|
154
|
+
s.replace 1, 14, [nullus]
|
155
|
+
s.replace 1, 15, [ignotus]
|
156
|
+
|
157
|
+
expect do
|
158
|
+
s.replace 1, 14, [ignotus]
|
159
|
+
end.to raise_exception ArgumentError, /duplicate symbols \[:ignotus\]/
|
160
|
+
|
161
|
+
expect do
|
162
|
+
s.replace 1, 15, [nullus]
|
163
|
+
end.to raise_exception ArgumentError, /duplicate symbols \[:nullus\]/
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'succeeds when celebration with the same symbol is being replaced' do
|
167
|
+
s.replace 1, 13, [nullus]
|
168
|
+
|
169
|
+
expect do
|
170
|
+
s.replace 1, 13, [nullus]
|
171
|
+
end.not_to raise_exception
|
172
|
+
end
|
111
173
|
end
|
112
174
|
end
|
113
175
|
|
114
176
|
describe '#update' do
|
115
|
-
|
116
|
-
@s2 = described_class.new
|
117
|
-
end
|
177
|
+
let(:s2) { described_class.new }
|
118
178
|
|
119
179
|
it 'adds entries from the argument to receiver' do
|
120
|
-
|
180
|
+
s2.add 1, 17, antonius
|
121
181
|
|
122
|
-
expect(
|
123
|
-
|
124
|
-
expect(
|
182
|
+
expect(s).to be_empty
|
183
|
+
s.update s2
|
184
|
+
expect(s.size).to eq 1
|
125
185
|
end
|
126
186
|
|
127
187
|
it 'overwrites eventual previous content of the day' do
|
128
|
-
|
129
|
-
|
130
|
-
|
188
|
+
s.add 1, 17, antonius
|
189
|
+
s2.add 1, 17, opt_memorial
|
190
|
+
|
191
|
+
s.update s2
|
192
|
+
expect(s.get(1, 17)).to eq [opt_memorial]
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'does not overwrite content of days for which it does not have any' do
|
196
|
+
s.add 1, 17, antonius
|
131
197
|
|
132
|
-
|
133
|
-
expect(
|
198
|
+
s.update s2
|
199
|
+
expect(s.get(1, 17)).to eq [antonius]
|
134
200
|
end
|
135
201
|
end
|
136
202
|
|
137
203
|
describe '#size' do
|
138
204
|
it 'knows when the Sanctorale is empty' do
|
139
|
-
expect(
|
205
|
+
expect(s.size).to eq 0
|
140
206
|
end
|
141
207
|
|
142
208
|
it 'knows when there is something' do
|
143
|
-
|
144
|
-
expect(
|
209
|
+
s.add 1, 17, antonius
|
210
|
+
expect(s.size).to eq 1
|
145
211
|
end
|
146
212
|
end
|
147
213
|
|
148
214
|
describe '#empty?' do
|
149
215
|
it 'is empty at the beginning' do
|
150
|
-
expect(
|
216
|
+
expect(s).to be_empty
|
151
217
|
end
|
152
218
|
|
153
219
|
it 'is never more empty once a record is entered' do
|
154
|
-
|
155
|
-
expect(
|
220
|
+
s.add 1, 17, antonius
|
221
|
+
expect(s).not_to be_empty
|
156
222
|
end
|
157
223
|
end
|
158
224
|
|
159
225
|
describe '#each_day' do
|
226
|
+
before :each do
|
227
|
+
s.add 1, 17, antonius
|
228
|
+
end
|
229
|
+
|
160
230
|
it 'yields each date and corresponding CR::Celebrations' do
|
161
|
-
|
162
|
-
|
231
|
+
expect {|block| s.each_day(&block) }.to yield_with_args(CR::AbstractDate.new(1, 17), [antonius])
|
232
|
+
end
|
163
233
|
|
164
|
-
|
234
|
+
it 'can be called without a block' do
|
235
|
+
expect(s.each_day).to be_an Enumerator
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
describe '#freeze' do
|
240
|
+
it 'makes the instance frozen' do
|
241
|
+
expect(s).not_to be_frozen # make sure
|
242
|
+
s.freeze
|
243
|
+
expect(s).to be_frozen
|
244
|
+
end
|
245
|
+
|
246
|
+
it 'prevents modification' do
|
247
|
+
s.freeze
|
248
|
+
|
249
|
+
expect do
|
250
|
+
s.add 1, 17, antonius
|
251
|
+
end.to raise_exception(RuntimeError, /can't modify frozen/)
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
describe '#==' do
|
256
|
+
describe 'empty' do
|
257
|
+
it 'is equal' do
|
258
|
+
expect(described_class.new).to be == described_class.new
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
describe 'with content' do
|
263
|
+
let(:a) do
|
264
|
+
s = described_class.new
|
265
|
+
s.add 1, 17, antonius
|
266
|
+
s
|
267
|
+
end
|
268
|
+
|
269
|
+
it 'different' do
|
270
|
+
expect(a).not_to be == described_class.new
|
271
|
+
end
|
272
|
+
|
273
|
+
it 'same' do
|
274
|
+
b = described_class.new
|
275
|
+
b.add 1, 17, antonius
|
276
|
+
|
277
|
+
expect(a).to be == b
|
278
|
+
end
|
165
279
|
end
|
166
280
|
end
|
167
281
|
end
|