citeproc-ruby 1.1.8 → 1.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +10 -32
- data/lib/citeproc/ruby/renderer.rb +2 -1
- data/lib/citeproc/ruby/version.rb +1 -1
- metadata +14 -84
- data/.rspec +0 -3
- data/.rubocop.yml +0 -1156
- data/.simplecov +0 -4
- data/Guardfile +0 -14
- data/features/bibliography.feature +0 -25
- data/features/locale_overrides.feature +0 -31
- data/features/name_options.feature +0 -37
- data/features/names.feature +0 -198
- data/features/renderer.feature +0 -94
- data/features/sort.feature +0 -50
- data/features/step_definitions/engine.rb +0 -21
- data/features/step_definitions/renderer.rb +0 -85
- data/features/style_immanent_locale_terms.feature +0 -30
- data/features/support/env.rb +0 -35
- data/features/support/hooks.rb +0 -10
- data/spec/citeproc/ruby/engine_spec.rb +0 -120
- data/spec/citeproc/ruby/formats/default_spec.rb +0 -168
- data/spec/citeproc/ruby/formats/html_spec.rb +0 -167
- data/spec/citeproc/ruby/renderer/choose_spec.rb +0 -293
- data/spec/citeproc/ruby/renderer/date_spec.rb +0 -173
- data/spec/citeproc/ruby/renderer/group_spec.rb +0 -114
- data/spec/citeproc/ruby/renderer/history_spec.rb +0 -47
- data/spec/citeproc/ruby/renderer/label_spec.rb +0 -225
- data/spec/citeproc/ruby/renderer/layout_spec.rb +0 -41
- data/spec/citeproc/ruby/renderer/macro_spec.rb +0 -31
- data/spec/citeproc/ruby/renderer/names_spec.rb +0 -396
- data/spec/citeproc/ruby/renderer/number_spec.rb +0 -120
- data/spec/citeproc/ruby/renderer/text_spec.rb +0 -125
- data/spec/citeproc/ruby/renderer_spec.rb +0 -65
- data/spec/fixtures/items.rb +0 -113
- data/spec/fixtures/locales/locales-de-DE.xml +0 -298
- data/spec/fixtures/locales/locales-en-US.xml +0 -304
- data/spec/fixtures/locales/locales-fr-FR.xml +0 -317
- data/spec/fixtures/styles/apa-with-different-translations.csl +0 -451
- data/spec/fixtures/styles/apa.csl +0 -443
- data/spec/fixtures/styles/modern-language-association-8th-edition.csl +0 -293
- data/spec/spec_helper.rb +0 -73
@@ -1,173 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module CiteProc
|
4
|
-
module Ruby
|
5
|
-
|
6
|
-
describe 'Renderer#render_date' do
|
7
|
-
let(:renderer) { Renderer.new }
|
8
|
-
|
9
|
-
let(:item) {
|
10
|
-
i = CiteProc::CitationItem.new(:id => 'ID-1')
|
11
|
-
i.data = CiteProc::Item.new(:id => 'ID-1')
|
12
|
-
i
|
13
|
-
}
|
14
|
-
|
15
|
-
describe 'localized rendering' do
|
16
|
-
let(:node) { CSL::Style::Date.new(:variable => 'issued', :form => 'numeric') }
|
17
|
-
|
18
|
-
describe 'given an item issued on January 27th, 2012' do
|
19
|
-
before(:each) { item.data[:issued] = '2012-01-27' }
|
20
|
-
|
21
|
-
it "uses the locale's date parts to render the date" do
|
22
|
-
expect(renderer.render(item, node)).to eq('01/27/2012')
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe 'static rendering' do
|
28
|
-
let(:node) { CSL::Style::Date.new(:variable => 'issued') }
|
29
|
-
|
30
|
-
describe 'given an item issued on January 27th, 2012' do
|
31
|
-
before(:each) { item.data[:issued] = '2012-01-27' }
|
32
|
-
|
33
|
-
it 'returns an empty string by default' do
|
34
|
-
expect(renderer.render_date(item, node)).to eq('')
|
35
|
-
end
|
36
|
-
|
37
|
-
describe 'and given a node with a year part' do
|
38
|
-
before(:each) { node << CSL::Style::DatePart.new(:name => 'year') }
|
39
|
-
|
40
|
-
it 'returns the year as "2012"' do
|
41
|
-
expect(renderer.render_date(item, node)).to eq('2012')
|
42
|
-
end
|
43
|
-
|
44
|
-
describe 'and a day part' do
|
45
|
-
before(:each) { node << CSL::Style::DatePart.new(:name => 'day') }
|
46
|
-
|
47
|
-
it 'returns "201227"' do
|
48
|
-
expect(renderer.render_date(item, node)).to eq('201227')
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'applies delimiters when set on the node' do
|
52
|
-
node[:delimiter] = '/'
|
53
|
-
expect(renderer.render_date(item, node)).to eq('2012/27')
|
54
|
-
end
|
55
|
-
|
56
|
-
describe 'and a month part' do
|
57
|
-
before(:each) { node << CSL::Style::DatePart.new(:name => 'month') }
|
58
|
-
|
59
|
-
it 'returns "201227January"' do
|
60
|
-
expect(renderer.render_date(item, node)).to eq('201227January')
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'returns "2012/27/01" when the month form set to "numeric-leading-zeros" and the node has a delimiter "/"' do
|
64
|
-
node.parts.last[:form] = 'numeric-leading-zeros'
|
65
|
-
node[:delimiter] = '/'
|
66
|
-
expect(renderer.render_date(item, node)).to eq('2012/27/01')
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
describe 'Renderer#render_date_part' do
|
77
|
-
let(:renderer) { Renderer.new }
|
78
|
-
let(:node) { CSL::Style::DatePart.new }
|
79
|
-
|
80
|
-
let(:today) { CiteProc::Date.today }
|
81
|
-
|
82
|
-
let(:january) { CiteProc::Date.new([2012, 1]) }
|
83
|
-
let(:december) { CiteProc::Date.new([2012, 12]) }
|
84
|
-
let(:independence) { CiteProc::Date.new([1776, 7, 4]) }
|
85
|
-
|
86
|
-
it 'returns an empty string by default' do
|
87
|
-
expect(renderer.render_date_part(CiteProc::Date.today, node)).to eq('')
|
88
|
-
end
|
89
|
-
|
90
|
-
describe 'when the name is set to "day"' do
|
91
|
-
before(:each) { node[:name] = 'day' }
|
92
|
-
|
93
|
-
it 'renders the day as number by default' do
|
94
|
-
expect(renderer.render_date_part(today, node)).to eq(today.day.to_s)
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'renders the day as an ordinal number when the form is set to "ordinal"' do
|
98
|
-
node[:form] = 'ordinal'
|
99
|
-
expect(renderer.render_date_part(independence, node)).to eq('4th')
|
100
|
-
|
101
|
-
renderer.locale.limit_day_ordinals!
|
102
|
-
expect(renderer.render_date_part(independence, node)).to eq('4')
|
103
|
-
|
104
|
-
independence.day = 1
|
105
|
-
expect(renderer.render_date_part(independence, node)).to eq('1st')
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
describe 'when the name is set to "month"' do
|
110
|
-
before(:each) { node[:name] = 'month' }
|
111
|
-
|
112
|
-
it "renders the month's full name by default" do
|
113
|
-
expect(renderer.render_date_part(january, node)).to eq('January')
|
114
|
-
expect(renderer.render_date_part(december, node)).to eq('December')
|
115
|
-
end
|
116
|
-
|
117
|
-
it "renders the month's full name as the long form" do
|
118
|
-
node[:form] = 'long'
|
119
|
-
expect(renderer.render_date_part(january, node)).to eq('January')
|
120
|
-
end
|
121
|
-
|
122
|
-
it "renders the month's short name as the short form" do
|
123
|
-
node[:form] = 'short'
|
124
|
-
expect(renderer.render_date_part(january, node)).to eq('Jan.')
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'renders the month as number as the numeric form' do
|
128
|
-
node[:form] = 'numeric'
|
129
|
-
expect(renderer.render_date_part(january, node)).to eq('1')
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'renders the month as number with a leading zero when form is set to numeric-leading-zeros' do
|
133
|
-
node[:form] = 'numeric-leading-zeros'
|
134
|
-
expect(renderer.render_date_part(january, node)).to eq('01')
|
135
|
-
expect(renderer.render_date_part(december, node)).to eq('12')
|
136
|
-
end
|
137
|
-
|
138
|
-
it 'renders the name of the season when a season is set' do
|
139
|
-
january.season = 4
|
140
|
-
expect(renderer.render_date_part(january, node)).to eq('Winter')
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
describe 'when the name is set to "year"' do
|
145
|
-
before(:each) { node[:name] = 'year' }
|
146
|
-
|
147
|
-
it 'renders the full year by default' do
|
148
|
-
expect(renderer.render_date_part(today, node)).to eq(today.year.to_s)
|
149
|
-
end
|
150
|
-
|
151
|
-
it 'renders the full year when form is set to long' do
|
152
|
-
node[:form] = 'long'
|
153
|
-
expect(renderer.render_date_part(january, node)).to eq('2012')
|
154
|
-
end
|
155
|
-
|
156
|
-
it 'renders the short year when form is set to short' do
|
157
|
-
node[:form] = 'short'
|
158
|
-
expect(renderer.render_date_part(january, node)).to eq('12')
|
159
|
-
end
|
160
|
-
|
161
|
-
it 'adds AD if applicable' do
|
162
|
-
expect(renderer.render_date_part(CiteProc::Date.new([200]), node)).to eq('200AD')
|
163
|
-
end
|
164
|
-
|
165
|
-
it 'adds BC if applicable' do
|
166
|
-
expect(renderer.render_date_part(CiteProc::Date.new([-200]), node)).to eq('200BC')
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
end
|
171
|
-
|
172
|
-
end
|
173
|
-
end
|
@@ -1,114 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module CiteProc
|
4
|
-
module Ruby
|
5
|
-
describe 'Renderer#render_group' do
|
6
|
-
let(:renderer) { Renderer.new }
|
7
|
-
|
8
|
-
let(:item) {
|
9
|
-
i = CiteProc::CitationItem.new(:id => 'ID-1')
|
10
|
-
i.data = CiteProc::Item.new(:id => 'ID-1')
|
11
|
-
i
|
12
|
-
}
|
13
|
-
|
14
|
-
let(:node) { CSL::Style::Group.new }
|
15
|
-
|
16
|
-
it 'returns an empty string by default' do
|
17
|
-
expect(renderer.render(item, node)).to eq('')
|
18
|
-
|
19
|
-
node[:prefix] = '!'
|
20
|
-
expect(renderer.render(item, node)).to eq('')
|
21
|
-
end
|
22
|
-
|
23
|
-
describe 'when there is a text node in the group' do
|
24
|
-
before(:each) { node << CSL::Style::Text.new( :term => 'retrieved') }
|
25
|
-
|
26
|
-
it 'returns the content of the nested node' do
|
27
|
-
expect(renderer.render_group(item, node)).to eq('retrieved')
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'applies formatting options to the nested node' do
|
31
|
-
node[:'text-case'] = 'uppercase'
|
32
|
-
expect(renderer.render(item, node)).to eq('RETRIEVED')
|
33
|
-
end
|
34
|
-
|
35
|
-
describe 'when there is a second text node in the group' do
|
36
|
-
before(:each) { node << CSL::Style::Text.new( :term => 'from') }
|
37
|
-
|
38
|
-
it 'returns the content of both nested nodes' do
|
39
|
-
expect(renderer.render_group(item, node)).to eq('retrievedfrom')
|
40
|
-
end
|
41
|
-
|
42
|
-
describe 'when there is a delimter set on the group node' do
|
43
|
-
before(:each) { node[:delimiter] = ' ' }
|
44
|
-
|
45
|
-
it 'applies the delimiter to the output' do
|
46
|
-
expect(renderer.render_group(item, node)).to eq('retrieved from')
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'applies formatting options to the nested nodes only' do
|
50
|
-
node[:'text-case'] = 'uppercase'
|
51
|
-
node[:delimiter] = ' foo '
|
52
|
-
node[:prefix] = '('
|
53
|
-
node[:suffix] = ')'
|
54
|
-
expect(renderer.render(item, node)).to eq('(RETRIEVED FOO FROM)')
|
55
|
-
end
|
56
|
-
|
57
|
-
describe 'when a nested node produces no output' do
|
58
|
-
before(:each) do
|
59
|
-
node << CSL::Style::Text.new( :term => 'fooo')
|
60
|
-
node << CSL::Style::Text.new( :term => 'from')
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'the delimiter does not apply to it' do
|
64
|
-
expect(renderer.render_group(item, node)).to eq('retrieved from from')
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe 'when there is a variable-based node in the group' do
|
69
|
-
before(:each) { node << CSL::Style::Text.new( :variable => 'URL') }
|
70
|
-
|
71
|
-
it 'returns the empty string when the variable is not present in the item' do
|
72
|
-
expect(renderer.render_group(item, node)).to eq('')
|
73
|
-
end
|
74
|
-
|
75
|
-
describe 'when the variable is present' do
|
76
|
-
before(:each) { item.data[:URL] = 'http://example.org' };
|
77
|
-
|
78
|
-
it 'returns all nested renditions' do
|
79
|
-
expect(renderer.render_group(item, node)).to eq('retrieved from http://example.org')
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe 'when there is a names node with substitute in the group' do
|
88
|
-
|
89
|
-
before(:each) do
|
90
|
-
subst = CSL::Style::Substitute.new()
|
91
|
-
subst << CSL::Style::Text.new( :value => 'Anonymous')
|
92
|
-
names = CSL::Style::Names.new( :variable => 'author')
|
93
|
-
names << subst
|
94
|
-
node << names
|
95
|
-
end
|
96
|
-
|
97
|
-
describe 'when the variable is set' do
|
98
|
-
before(:each) { item.data.author = 'Some Author' }
|
99
|
-
|
100
|
-
it 'returns the content of the nested node' do
|
101
|
-
expect(renderer.render_group(item, node)).to eq('Some Author')
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
describe 'when the variable is not set' do
|
106
|
-
it 'returns the substitution of the nested node' do
|
107
|
-
expect(renderer.render_group(item, node)).to eq('Anonymous')
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module CiteProc
|
4
|
-
module Ruby
|
5
|
-
|
6
|
-
describe Renderer::History do
|
7
|
-
let(:state) { Renderer::State.new }
|
8
|
-
let(:history) { state.history }
|
9
|
-
|
10
|
-
it 'has an empty citation history' do
|
11
|
-
expect(history.memory['citation']).to eq([])
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'has an empty bibliography history' do
|
15
|
-
expect(history.memory['bibliogrpahy']).to eq([])
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '#update' do
|
19
|
-
it 'saves the passed in items for :store!' do
|
20
|
-
expect {
|
21
|
-
history.update :store!, 'citation', { :x => 1 }
|
22
|
-
}.to change { history.citation }.to([{ :x => 1 }])
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'drops remembered items when they are too old' do
|
26
|
-
expect {
|
27
|
-
history.update :store!, 'citation', { :x => 1 }
|
28
|
-
history.update :store!, 'citation', { :x => 2 }
|
29
|
-
history.update :store!, 'citation', { :x => 3 }
|
30
|
-
history.update :store!, 'citation', { :x => 4 }
|
31
|
-
history.update :store!, 'citation', { :x => 5 }
|
32
|
-
}.to change { history.citation.length }.to(3)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe '#discard' do
|
37
|
-
it 'clears the history' do
|
38
|
-
history.update :store!, 'bibliography', { :x => 1 }
|
39
|
-
expect(history.memory).not_to be_empty
|
40
|
-
history.discard
|
41
|
-
expect(history.memory).to be_empty
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
end
|
@@ -1,225 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module CiteProc
|
4
|
-
module Ruby
|
5
|
-
|
6
|
-
describe "Renderer#render_label" do
|
7
|
-
let(:renderer) { Renderer.new }
|
8
|
-
|
9
|
-
let(:node) { CSL::Style::Label.new }
|
10
|
-
|
11
|
-
let(:item) {
|
12
|
-
i = CiteProc::CitationItem.new(:id => 'ID-1')
|
13
|
-
i.data = CiteProc::Item.new(:id => 'ID-1')
|
14
|
-
i
|
15
|
-
}
|
16
|
-
|
17
|
-
describe 'given an empty node' do
|
18
|
-
it 'returns an empty string for an empty item' do
|
19
|
-
expect(renderer.render_label(item, node)).to eq('')
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'returns an empty string for an item with variables' do
|
23
|
-
item.data.edition = 'foo'
|
24
|
-
expect(renderer.render_label(item, node)).to eq('')
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
# page
|
30
|
-
|
31
|
-
describe "when the node's variable is set to :page" do
|
32
|
-
before(:each) { node[:variable] = :page }
|
33
|
-
|
34
|
-
describe "for an item with no page value" do
|
35
|
-
it 'returns an empty string' do
|
36
|
-
expect(renderer.render_label(item, node)).to eq('')
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe 'for an item with a page value' do
|
41
|
-
it 'returns the singular label for a number' do
|
42
|
-
item.write_attribute :page, '23'
|
43
|
-
expect(renderer.render_label(item, node)).to eq('page')
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'returns the plural label for a page-range' do
|
47
|
-
item.write_attribute :page, '23-24'
|
48
|
-
expect(renderer.render_label(item, node)).to eq('pages')
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'returns the plural label for multiple pages' do
|
52
|
-
item.write_attribute :page, '23 & 24'
|
53
|
-
expect(renderer.render_label(item, node)).to eq('pages')
|
54
|
-
|
55
|
-
item.write_attribute :page, '23, 24, 25'
|
56
|
-
expect(renderer.render_label(item, node)).to eq('pages')
|
57
|
-
end
|
58
|
-
|
59
|
-
describe 'when pluralization is contextual' do
|
60
|
-
before(:each) { node[:plural] = 'contextual' }
|
61
|
-
|
62
|
-
it 'returns the singular label for a number' do
|
63
|
-
item.write_attribute :page, '23'
|
64
|
-
expect(renderer.render_label(item, node)).to eq('page')
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'returns the plural label for a page-range' do
|
68
|
-
item.write_attribute :page, '23-24'
|
69
|
-
expect(renderer.render_label(item, node)).to eq('pages')
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe 'when pluralization is set to "always"' do
|
74
|
-
before(:each) { node[:plural] = 'always' }
|
75
|
-
|
76
|
-
it 'returns the singular label for a number' do
|
77
|
-
item.write_attribute :page, '1'
|
78
|
-
expect(renderer.render_label(item, node)).to eq('pages')
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'returns the plural label for a page-range' do
|
82
|
-
item.write_attribute :page, '1-3'
|
83
|
-
expect(renderer.render_label(item, node)).to eq('pages')
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe 'when pluralization is set to "never"' do
|
88
|
-
before(:each) { node[:plural] = 'never' }
|
89
|
-
|
90
|
-
it 'returns the singular label for a number' do
|
91
|
-
item.write_attribute :page, '1'
|
92
|
-
expect(renderer.render_label(item, node)).to eq('page')
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'returns the plural label for a page-range' do
|
96
|
-
item.write_attribute :page, '1-3'
|
97
|
-
expect(renderer.render_label(item, node)).to eq('page')
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
|
104
|
-
# number-of-pages variable
|
105
|
-
|
106
|
-
describe "when the node's variable is set to :'number-of-pages'" do
|
107
|
-
before(:each) { node[:variable] = 'number-of-pages' }
|
108
|
-
|
109
|
-
describe "for an item with no 'number-of-pages' value" do
|
110
|
-
it 'returns an empty string' do
|
111
|
-
expect(renderer.render_label(item, node)).to eq('')
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
describe "for an item with a 'number-of-pages' value" do
|
116
|
-
it 'returns the singular label for number 1' do
|
117
|
-
item.data[:'number-of-pages'] = 1
|
118
|
-
expect(renderer.render_label(item, node)).to eq('page')
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'returns the plural label for numbers higher than 1' do
|
122
|
-
item.data[:'number-of-pages'] = '2'
|
123
|
-
expect(renderer.render_label(item, node)).to eq('pages')
|
124
|
-
|
125
|
-
item.data[:'number-of-pages'] = 42
|
126
|
-
expect(renderer.render_label(item, node)).to eq('pages')
|
127
|
-
end
|
128
|
-
|
129
|
-
describe 'when pluralization is set to "contextual"' do
|
130
|
-
before(:each) { node[:plural] = 'contextual' }
|
131
|
-
|
132
|
-
it 'returns the singular label for number 1' do
|
133
|
-
item.data[:'number-of-pages'] = '1'
|
134
|
-
expect(renderer.render_label(item, node)).to eq('page')
|
135
|
-
end
|
136
|
-
|
137
|
-
it 'returns the plural label for numbers higher than 1' do
|
138
|
-
item.data[:'number-of-pages'] = '2'
|
139
|
-
expect(renderer.render_label(item, node)).to eq('pages')
|
140
|
-
|
141
|
-
item.data[:'number-of-pages'] = 42
|
142
|
-
expect(renderer.render_label(item, node)).to eq('pages')
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
describe 'when pluralization is set to "always"' do
|
147
|
-
before(:each) { node[:plural] = 'always' }
|
148
|
-
|
149
|
-
it 'returns the singular label for number 1' do
|
150
|
-
item.data[:'number-of-pages'] = 1
|
151
|
-
expect(renderer.render_label(item, node)).to eq('pages')
|
152
|
-
end
|
153
|
-
|
154
|
-
it 'returns the plural label for numbers higher than 1' do
|
155
|
-
item.data[:'number-of-pages'] = '2'
|
156
|
-
expect(renderer.render_label(item, node)).to eq('pages')
|
157
|
-
|
158
|
-
item.data[:'number-of-pages'] = 42
|
159
|
-
expect(renderer.render_label(item, node)).to eq('pages')
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
describe 'when pluralization is set to "never"' do
|
164
|
-
before(:each) { node[:plural] = 'never' }
|
165
|
-
|
166
|
-
it 'returns the singular label for number 1' do
|
167
|
-
item.data[:'number-of-pages'] = 1
|
168
|
-
expect(renderer.render_label(item, node)).to eq('page')
|
169
|
-
end
|
170
|
-
|
171
|
-
it 'returns the plural label for numbers higher than 1' do
|
172
|
-
item.data[:'number-of-pages'] = '2'
|
173
|
-
expect(renderer.render_label(item, node)).to eq('page')
|
174
|
-
|
175
|
-
item.data[:'number-of-pages'] = 42
|
176
|
-
expect(renderer.render_label(item, node)).to eq('page')
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
# number-of-volumes variable
|
183
|
-
|
184
|
-
describe "when the node's variable is set to :'number-of-volumes'" do
|
185
|
-
before(:each) { node[:variable] = 'number-of-volumes' }
|
186
|
-
|
187
|
-
describe "for an item with a 'number-of-volumes' value" do
|
188
|
-
it 'returns the singular label for number 1' do
|
189
|
-
item.data[:'number-of-volumes'] = 1
|
190
|
-
expect(renderer.render_label(item, node)).to eq('volume')
|
191
|
-
end
|
192
|
-
|
193
|
-
it 'returns the plural label for numbers higher than 1' do
|
194
|
-
item.data[:'number-of-volumes'] = '2'
|
195
|
-
expect(renderer.render_label(item, node)).to eq('volumes')
|
196
|
-
|
197
|
-
item.data[:'number-of-volumes'] = 42
|
198
|
-
expect(renderer.render_label(item, node)).to eq('volumes')
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
# locators
|
204
|
-
|
205
|
-
describe "when the node's variable is set to another locator" do
|
206
|
-
before(:each) { node[:variable] = 'locator' }
|
207
|
-
|
208
|
-
describe "for an item with a locator and label" do
|
209
|
-
it "returns the singular label for a single number" do
|
210
|
-
item.locator = 2
|
211
|
-
item.label = 'book'
|
212
|
-
expect(renderer.render_label(item, node)).to eq('book')
|
213
|
-
end
|
214
|
-
|
215
|
-
it "returns the plural label for multiple numbers" do
|
216
|
-
item.locator = '23 & 4'
|
217
|
-
item.label = 'book'
|
218
|
-
expect(renderer.render_label(item, node)).to eq('books')
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
end # render_label
|
224
|
-
end
|
225
|
-
end
|