calendarium-romanum 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/calendariumrom +1 -1
- data/config/locales/cs.yml +1 -0
- data/config/locales/en.yml +1 -0
- data/config/locales/fr.yml +1 -0
- data/config/locales/it.yml +1 -0
- data/config/locales/la.yml +1 -0
- data/data/czech-cs.txt +2 -1
- data/data/universal-la.txt +2 -0
- data/lib/calendarium-romanum.rb +24 -22
- data/lib/calendarium-romanum/calendar.rb +66 -16
- data/lib/calendarium-romanum/cli.rb +84 -52
- data/lib/calendarium-romanum/data.rb +12 -12
- data/lib/calendarium-romanum/day.rb +35 -14
- data/lib/calendarium-romanum/enum.rb +2 -4
- data/lib/calendarium-romanum/enums.rb +1 -1
- data/lib/calendarium-romanum/errors.rb +4 -0
- data/lib/calendarium-romanum/ordinalizer.rb +13 -1
- data/lib/calendarium-romanum/rank.rb +5 -5
- data/lib/calendarium-romanum/sanctorale.rb +2 -2
- data/lib/calendarium-romanum/sanctoraleloader.rb +31 -24
- data/lib/calendarium-romanum/temporale.rb +64 -83
- data/lib/calendarium-romanum/temporale/celebration_factory.rb +48 -0
- data/lib/calendarium-romanum/temporale/dates.rb +14 -14
- data/lib/calendarium-romanum/util.rb +22 -1
- data/lib/calendarium-romanum/version.rb +4 -1
- data/spec/calendar_spec.rb +232 -3
- data/spec/celebration_factory_spec.rb +16 -0
- data/spec/celebration_spec.rb +20 -0
- data/spec/cli_spec.rb +140 -11
- data/spec/date_parser_spec.rb +68 -0
- data/spec/date_spec.rb +8 -8
- data/spec/day_spec.rb +57 -8
- data/spec/i18n_spec.rb +0 -1
- data/spec/ordinalizer_spec.rb +29 -15
- data/spec/readme_spec.rb +4 -0
- data/spec/sanctorale_spec.rb +3 -3
- data/spec/sanctoraleloader_spec.rb +16 -11
- data/spec/spec_helper.rb +11 -0
- data/spec/temporale_spec.rb +56 -3
- metadata +6 -2
data/spec/celebration_spec.rb
CHANGED
@@ -20,4 +20,24 @@ describe CR::Celebration do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
|
+
|
24
|
+
describe '#change' do
|
25
|
+
let(:c) { described_class.new('title') }
|
26
|
+
|
27
|
+
it 'produces a new instance' do
|
28
|
+
c2 = c.change rank: CR::Ranks::SOLEMNITY_GENERAL
|
29
|
+
expect(c2).not_to be c
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'sets specified properties' do
|
33
|
+
c2 = c.change rank: CR::Ranks::SOLEMNITY_GENERAL
|
34
|
+
expect(c2.rank).not_to eq c.rank
|
35
|
+
expect(c2.rank).to be CR::Ranks::SOLEMNITY_GENERAL
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'copies the rest' do
|
39
|
+
c2 = c.change rank: CR::Ranks::SOLEMNITY_GENERAL
|
40
|
+
expect(c2.title).to be c.title # reference copying is no problem, Celebrations are immutable
|
41
|
+
end
|
42
|
+
end
|
23
43
|
end
|
data/spec/cli_spec.rb
CHANGED
@@ -1,26 +1,155 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'calendarium-romanum/cli'
|
3
3
|
|
4
|
-
describe CalendariumRomanum::CLI do
|
5
|
-
let(:path_universal_la) {
|
6
|
-
let(:path_universal_en) {
|
4
|
+
describe CalendariumRomanum::CLI, type: :aruba do
|
5
|
+
let(:path_universal_la) { CR::Data::GENERAL_ROMAN_LATIN.path }
|
6
|
+
let(:path_universal_en) { CR::Data::GENERAL_ROMAN_ENGLISH.path }
|
7
|
+
|
8
|
+
before :each do
|
9
|
+
prepend_environment_variable('RUBYLIB', File.expand_path('../../lib', __FILE__) + ':')
|
10
|
+
end
|
11
|
+
|
7
12
|
describe 'subcommands' do
|
8
13
|
describe 'errors' do
|
9
|
-
|
10
|
-
|
14
|
+
describe 'no errors detected' do
|
15
|
+
before(:each) { run "calendariumrom errors #{path_universal_la}" }
|
16
|
+
it { expect(last_command).to be_successfully_executed }
|
17
|
+
it { expect(all_output).to be_empty }
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'non-existent file' do
|
21
|
+
before(:each) { run 'calendariumrom errors does-not-exist.txt' }
|
22
|
+
it { expect(all_output).to include 'No such file or directory' }
|
23
|
+
it { expect(last_command).to have_exit_status 1 }
|
11
24
|
end
|
12
25
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
26
|
+
describe 'errors detected' do
|
27
|
+
before(:each) do
|
28
|
+
write_file 'data.txt', file_content
|
29
|
+
run 'calendariumrom errors data.txt'
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'completely broken record' do
|
33
|
+
let(:file_content) { 'invalid content' }
|
34
|
+
|
35
|
+
it { expect(all_output).to eq "L1: Syntax error, line skipped 'invalid content'\n" }
|
36
|
+
it { expect(last_command).to have_exit_status 1 }
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'wrong month title (month does not exist)' do
|
40
|
+
let(:file_content) { "= 13\n" }
|
41
|
+
|
42
|
+
it { expect(all_output).to start_with 'L1: Invalid month' }
|
43
|
+
it { expect(last_command).to have_exit_status 1 }
|
44
|
+
end
|
17
45
|
end
|
18
46
|
end
|
19
47
|
|
20
48
|
describe 'cmp' do
|
21
|
-
|
22
|
-
|
49
|
+
describe 'contents match' do
|
50
|
+
before(:each) { run "calendariumrom cmp #{path_universal_la} #{path_universal_en}" }
|
51
|
+
|
52
|
+
it { expect(all_output).to be_empty }
|
53
|
+
it { expect(last_command).to be_successfully_executed }
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'contents do not match' do
|
57
|
+
before(:each) do
|
58
|
+
write_file 'cal1.txt', content1
|
59
|
+
write_file 'cal2.txt', content2
|
60
|
+
run 'calendariumrom cmp cal1.txt cal2.txt'
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'in rank' do
|
64
|
+
let(:content1) { '1/11 : St. None, abbot' }
|
65
|
+
let(:content2) { '1/11 m : St. None, abbot' }
|
66
|
+
|
67
|
+
it { expect(all_output).to include '1/11' }
|
68
|
+
it { expect(all_output).to include 'St. None, abbot' }
|
69
|
+
it { expect(all_output).to include 'differs in rank' }
|
70
|
+
it { expect(last_command).to be_successfully_executed }
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'in colour' do
|
74
|
+
let(:content1) { '1/11 : St. None, abbot' }
|
75
|
+
let(:content2) { '1/11 R : St. None, abbot and martyr' }
|
76
|
+
|
77
|
+
it { expect(all_output).to include '1/11' }
|
78
|
+
it { expect(all_output).to include 'St. None, abbot' }
|
79
|
+
it { expect(all_output).to include 'differs in colour' }
|
80
|
+
it { expect(last_command).to be_successfully_executed }
|
81
|
+
end
|
82
|
+
|
83
|
+
describe 'in optional memorial count' do
|
84
|
+
let(:content1) { '1/11 : St. None, abbot' }
|
85
|
+
let(:content2) { "1/11 : St. None, abbot\n1/11 : St. Nulla, abbess" }
|
86
|
+
|
87
|
+
it { expect(all_output).to include '1/11' }
|
88
|
+
it { expect(all_output).to include 'St. Nulla, abbess' }
|
89
|
+
it { expect(all_output).to include 'only in cal2.txt' }
|
90
|
+
it { expect(last_command).to be_successfully_executed }
|
91
|
+
end
|
92
|
+
|
93
|
+
describe 'only in one source' do
|
94
|
+
let(:content1) { '' }
|
95
|
+
let(:content2) { '1/11 : St. None, abbot' }
|
96
|
+
|
97
|
+
it { expect(all_output).to include '1/11' }
|
98
|
+
it { expect(all_output).to include 'St. None, abbot' }
|
99
|
+
it { expect(all_output).to include 'only in cal2.txt' }
|
100
|
+
it { expect(last_command).to be_successfully_executed }
|
101
|
+
end
|
23
102
|
end
|
24
103
|
end
|
104
|
+
|
105
|
+
describe 'query' do
|
106
|
+
describe 'invalid data file from file system' do
|
107
|
+
before(:each) do
|
108
|
+
write_file 'invalid.txt', 'Foo bar baz'
|
109
|
+
run 'calendariumrom query --calendar invalid.txt 2017-10-03'
|
110
|
+
end
|
111
|
+
|
112
|
+
it { expect(all_output).to include 'Invalid file format.' }
|
113
|
+
it { expect(last_command).to have_exit_status 1 }
|
114
|
+
end
|
115
|
+
|
116
|
+
describe 'correct data file from file system' do
|
117
|
+
before(:each) { run "calendariumrom query --calendar #{path_universal_la} 2017-10-03" }
|
118
|
+
|
119
|
+
it { expect(all_output).to include 'season: Ordinary Time' }
|
120
|
+
it { expect(last_command).to be_successfully_executed }
|
121
|
+
end
|
122
|
+
|
123
|
+
describe 'correct season naming' do
|
124
|
+
before(:each) { run 'calendariumrom query 2017-10-03' }
|
125
|
+
|
126
|
+
it { expect(all_output).to include 'season: Ordinary Time' }
|
127
|
+
it { expect(last_command).to be_successfully_executed }
|
128
|
+
end
|
129
|
+
|
130
|
+
describe 'correct month querying' do
|
131
|
+
before(:each) { run 'calendariumrom query 2015-06' }
|
132
|
+
|
133
|
+
it { expect(all_output).to include 'Saint Cyril of Alexandria' }
|
134
|
+
it { expect(all_output).to include 'Saint Anthony of Padua, priest and doctor' }
|
135
|
+
it { expect(last_command).to be_successfully_executed }
|
136
|
+
end
|
137
|
+
|
138
|
+
describe 'correct year querying' do
|
139
|
+
before(:each) { run 'calendariumrom query 2013' }
|
140
|
+
|
141
|
+
it { expect(all_output).to include 'Saint John the Apostle and evangelist' }
|
142
|
+
it { expect(all_output).to include 'Saint Paul of the Cross, priest' }
|
143
|
+
it { expect(last_command).to be_successfully_executed }
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe 'calendars' do
|
148
|
+
before(:each) { run 'calendariumrom calendars' }
|
149
|
+
|
150
|
+
it { expect(all_output).to include 'universal-en' }
|
151
|
+
it { expect(all_output).to include 'czech-praha-cs' }
|
152
|
+
it { expect(last_command).to be_successfully_executed }
|
153
|
+
end
|
25
154
|
end
|
26
155
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CR::Util::DateParser do
|
4
|
+
describe 'new' do
|
5
|
+
it 'should accept a full date YYYY/MM/DD' do
|
6
|
+
date_str = '2017/10/06'
|
7
|
+
expect do
|
8
|
+
described_class.new(date_str)
|
9
|
+
end.not_to raise_exception
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should accept a full date YYYY-MM-DD' do
|
13
|
+
date_str = '2017-10-06'
|
14
|
+
expect do
|
15
|
+
described_class.new(date_str)
|
16
|
+
end.not_to raise_exception
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should accept a month range YYYY/MM' do
|
20
|
+
date_str = '2017/10'
|
21
|
+
expect do
|
22
|
+
described_class.new(date_str)
|
23
|
+
end.not_to raise_exception
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should accept a month range YYYY-MM' do
|
27
|
+
date_str = '2017-10'
|
28
|
+
expect do
|
29
|
+
described_class.new(date_str)
|
30
|
+
end.not_to raise_exception
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should accept a year range YYYY' do
|
34
|
+
date_str = '2017'
|
35
|
+
expect do
|
36
|
+
described_class.new(date_str)
|
37
|
+
end.not_to raise_exception
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should not accept an invalid month' do
|
41
|
+
date_str = '2017-15'
|
42
|
+
expect do
|
43
|
+
described_class.new(date_str)
|
44
|
+
end.to raise_exception(ArgumentError)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should not accept an invalid day' do
|
48
|
+
date_str = '2017-10-48'
|
49
|
+
expect do
|
50
|
+
described_class.new(date_str)
|
51
|
+
end.to raise_exception(ArgumentError)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should not accept a not-matching string' do
|
55
|
+
date_str = 'foobar'
|
56
|
+
expect do
|
57
|
+
described_class.new(date_str)
|
58
|
+
end.to raise_exception(ArgumentError)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should not accept an empty string' do
|
62
|
+
date_str = ''
|
63
|
+
expect do
|
64
|
+
described_class.new(date_str)
|
65
|
+
end.to raise_exception(ArgumentError)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/spec/date_spec.rb
CHANGED
@@ -4,14 +4,14 @@ require 'spec_helper'
|
|
4
4
|
describe Date do
|
5
5
|
describe '#-' do
|
6
6
|
it 'returns Rational' do
|
7
|
-
date_diff = Date.new(2013,5,5) - Date.new(2013,5,1)
|
7
|
+
date_diff = Date.new(2013, 5, 5) - Date.new(2013, 5, 1)
|
8
8
|
expect(date_diff).to be_a Rational
|
9
9
|
expect(date_diff.numerator).to eq 4
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
describe 'range' do
|
14
|
-
let(:range) { (Date.new(2000,1,1) .. Date.new(2010,1,1)) }
|
14
|
+
let(:range) { (Date.new(2000, 1, 1) .. Date.new(2010, 1, 1)) }
|
15
15
|
|
16
16
|
# please note that the RSpec 'include' matcher cannot
|
17
17
|
# be used here, because it does't simply test
|
@@ -20,11 +20,11 @@ describe Date do
|
|
20
20
|
# of DateTime in a Date range.
|
21
21
|
describe 'test Date inclusion' do
|
22
22
|
it 'includes' do
|
23
|
-
expect(range.include?(Date.new(2005,3,3))).to be true
|
23
|
+
expect(range.include?(Date.new(2005, 3, 3))).to be true
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'excludes' do
|
27
|
-
expect(range.include?(Date.new(1995,3,3))).to be false
|
27
|
+
expect(range.include?(Date.new(1995, 3, 3))).to be false
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -32,22 +32,22 @@ describe Date do
|
|
32
32
|
# DateTime without time details is treated just like Date
|
33
33
|
describe 'without time specified' do
|
34
34
|
it 'excludes' do
|
35
|
-
expect(range.include?(DateTime.new(1995,3,3))).to be false
|
35
|
+
expect(range.include?(DateTime.new(1995, 3, 3))).to be false
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'includes' do
|
39
|
-
expect(range.include?(DateTime.new(2005,3,3))).to be true
|
39
|
+
expect(range.include?(DateTime.new(2005, 3, 3))).to be true
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
# treatment of a DateTime with time details is different
|
44
44
|
describe 'with time specified' do
|
45
45
|
it 'excludes a DateTime not falling in the range' do
|
46
|
-
expect(range.include?(DateTime.new(1995,3,3,1,1,1))).to be false
|
46
|
+
expect(range.include?(DateTime.new(1995, 3, 3, 1, 1, 1))).to be false
|
47
47
|
end
|
48
48
|
|
49
49
|
it '... but also one *falling* in the range!' do
|
50
|
-
expect(range.include?(DateTime.new(2005,3,3,1,1,1))).to be false
|
50
|
+
expect(range.include?(DateTime.new(2005, 3, 3, 1, 1, 1))).to be false
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
data/spec/day_spec.rb
CHANGED
@@ -1,16 +1,37 @@
|
|
1
1
|
require_relative 'spec_helper'
|
2
2
|
|
3
3
|
describe CR::Day do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
let(:d) do
|
5
|
+
described_class.new(
|
6
|
+
date: Date.today,
|
7
|
+
season: CR::Seasons::ORDINARY,
|
8
|
+
season_week: 1,
|
9
|
+
celebrations: [CR::Celebration.new],
|
10
|
+
vespers: vespers
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:vespers) { nil }
|
15
|
+
|
16
|
+
describe '.new' do
|
17
|
+
it 'works without arguments' do
|
18
|
+
expect do
|
19
|
+
described_class.new
|
20
|
+
end.not_to raise_exception
|
12
21
|
end
|
13
22
|
|
23
|
+
it 'makes a shallow copy of celebrations' do
|
24
|
+
celebrations = [CR::Celebration.new]
|
25
|
+
day = described_class.new celebrations: celebrations
|
26
|
+
|
27
|
+
expect(day.celebrations).to eq celebrations
|
28
|
+
expect(day.celebrations).not_to be celebrations
|
29
|
+
|
30
|
+
expect(day.celebrations[0]).to be celebrations[0]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#==' do
|
14
35
|
describe 'same content' do
|
15
36
|
let(:d2) do
|
16
37
|
described_class.new(
|
@@ -55,5 +76,33 @@ describe CR::Day do
|
|
55
76
|
expect(d).not_to eq d2
|
56
77
|
end
|
57
78
|
end
|
79
|
+
|
80
|
+
describe 'different Vespers' do
|
81
|
+
let(:d2) do
|
82
|
+
described_class.new(
|
83
|
+
date: Date.today,
|
84
|
+
season: CR::Seasons::ORDINARY,
|
85
|
+
season_week: 1,
|
86
|
+
celebrations: [CR::Celebration.new],
|
87
|
+
vespers: CR::Temporale::CelebrationFactory.palm_sunday
|
88
|
+
)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'is different' do
|
92
|
+
expect(d).not_to eq d2
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '#vespers_from_following?' do
|
98
|
+
describe 'vespers not set' do
|
99
|
+
it { expect(d.vespers_from_following?).to be false }
|
100
|
+
end
|
101
|
+
|
102
|
+
describe 'vespers set' do
|
103
|
+
let(:vespers) { CR::Celebration.new }
|
104
|
+
|
105
|
+
it { expect(d.vespers_from_following?).to be true }
|
106
|
+
end
|
58
107
|
end
|
59
108
|
end
|
data/spec/i18n_spec.rb
CHANGED
data/spec/ordinalizer_spec.rb
CHANGED
@@ -1,21 +1,35 @@
|
|
1
1
|
require_relative 'spec_helper'
|
2
2
|
|
3
3
|
describe CalendariumRomanum::Ordinalizer do
|
4
|
-
describe '#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
4
|
+
describe '#ordinal' do
|
5
|
+
describe 'English' do
|
6
|
+
{
|
7
|
+
1 => '1st',
|
8
|
+
2 => '2nd',
|
9
|
+
3 => '3rd',
|
10
|
+
4 => '4th',
|
11
|
+
11 => '11th',
|
12
|
+
12 => '12th',
|
13
|
+
13 => '13th',
|
14
|
+
21 => '21st',
|
15
|
+
22 => '22nd',
|
16
|
+
23 => '23rd',
|
17
|
+
}.each_pair do |number, ordinal|
|
18
|
+
it number do
|
19
|
+
expect(described_class.ordinal(number, locale: :en)).to eq ordinal
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'French' do
|
25
|
+
{
|
26
|
+
1 => '1er',
|
27
|
+
2 => '2ème',
|
28
|
+
3 => '3ème',
|
29
|
+
}.each_pair do |number, ordinal|
|
30
|
+
it number do
|
31
|
+
expect(described_class.ordinal(number, locale: :fr)).to eq ordinal
|
32
|
+
end
|
19
33
|
end
|
20
34
|
end
|
21
35
|
end
|