citeproc 1.0.1 → 1.0.2
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/Gemfile +11 -5
- data/features/step_definitions/processor.rb +9 -9
- data/features/support/env.rb +6 -4
- data/lib/citeproc/item.rb +5 -0
- data/lib/citeproc/version.rb +1 -1
- data/spec/citeproc/abbreviate_spec.rb +5 -5
- data/spec/citeproc/assets_spec.rb +8 -8
- data/spec/citeproc/attributes_spec.rb +3 -3
- data/spec/citeproc/bibliography_spec.rb +10 -10
- data/spec/citeproc/citation_data_spec.rb +12 -12
- data/spec/citeproc/date_spec.rb +89 -89
- data/spec/citeproc/engine_spec.rb +2 -2
- data/spec/citeproc/extensions_spec.rb +20 -20
- data/spec/citeproc/item_spec.rb +15 -15
- data/spec/citeproc/names_spec.rb +130 -130
- data/spec/citeproc/processor_spec.rb +8 -8
- data/spec/citeproc/selector_spec.rb +12 -12
- data/spec/citeproc/utilities_spec.rb +1 -1
- data/spec/citeproc/variable_spec.rb +46 -46
- data/spec/spec_helper.rb +3 -2
- data/tasks/testsuite.rb +0 -3
- metadata +11 -11
@@ -4,14 +4,14 @@ module CiteProc
|
|
4
4
|
describe Engine do
|
5
5
|
|
6
6
|
it 'cannot be instantiated' do
|
7
|
-
|
7
|
+
expect { Engine.new }.to raise_error(NoMethodError)
|
8
8
|
end
|
9
9
|
|
10
10
|
describe 'subclasses' do
|
11
11
|
let(:subject) { Class.new(Engine).new }
|
12
12
|
|
13
13
|
it 'can be instantiated' do
|
14
|
-
subject.
|
14
|
+
expect(subject).not_to be nil
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -5,29 +5,29 @@ describe Hash do
|
|
5
5
|
|
6
6
|
|
7
7
|
describe '#deep_copy' do
|
8
|
-
it { hash.
|
8
|
+
it { expect(hash).to respond_to(:deep_copy) }
|
9
9
|
|
10
10
|
it 'returns a copy equal to the hash' do
|
11
|
-
hash.deep_copy.
|
11
|
+
expect(hash.deep_copy).to eq(hash)
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'returns a copy that is not identical to the hash' do
|
15
|
-
hash.deep_copy.
|
15
|
+
expect(hash.deep_copy).not_to equal(hash)
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'returns a deep copy' do
|
19
|
-
hash.deep_copy[:a].
|
20
|
-
hash.deep_copy[:a].
|
21
|
-
hash.deep_copy[:a][:b].
|
22
|
-
hash.deep_copy[:a][:b].
|
23
|
-
hash.deep_copy[:a][:b][:c].
|
19
|
+
expect(hash.deep_copy[:a]).to eq(hash[:a])
|
20
|
+
expect(hash.deep_copy[:a]).not_to equal(hash[:a])
|
21
|
+
expect(hash.deep_copy[:a][:b]).to eq(hash[:a][:b])
|
22
|
+
expect(hash.deep_copy[:a][:b]).not_to equal(hash[:a][:b])
|
23
|
+
expect(hash.deep_copy[:a][:b][:c]).to eq(hash[:a][:b][:c])
|
24
24
|
end
|
25
25
|
|
26
26
|
context 'when given nested arrays' do
|
27
27
|
let(:hash) {{:a => [[1,2]]}}
|
28
28
|
it 'it returns a deep copy' do
|
29
|
-
hash.deep_copy[:a].
|
30
|
-
hash.deep_copy[:a].
|
29
|
+
expect(hash.deep_copy[:a]).to eq(hash[:a])
|
30
|
+
expect(hash.deep_copy[:a]).not_to equal(hash[:a])
|
31
31
|
end
|
32
32
|
|
33
33
|
end
|
@@ -43,13 +43,13 @@ describe Hash do
|
|
43
43
|
# end
|
44
44
|
|
45
45
|
it 'returns the value of all the arguments applied as keys' do
|
46
|
-
hash.deep_fetch(:a, :b, :c).
|
46
|
+
expect(hash.deep_fetch(:a, :b, :c)).to eq(:d)
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'returns nil if any of the values did not exist' do
|
50
|
-
hash.deep_fetch(:x, :b, :c).
|
51
|
-
hash.deep_fetch(:a, :x, :c).
|
52
|
-
hash.deep_fetch(:a, :b, :x).
|
50
|
+
expect(hash.deep_fetch(:x, :b, :c)).to be nil
|
51
|
+
expect(hash.deep_fetch(:a, :x, :c)).to be nil
|
52
|
+
expect(hash.deep_fetch(:a, :b, :x)).to be nil
|
53
53
|
end
|
54
54
|
|
55
55
|
end
|
@@ -61,27 +61,27 @@ describe Array do
|
|
61
61
|
describe '#compact_join' do
|
62
62
|
|
63
63
|
it 'is equivalent to #join when there are no blank elements' do
|
64
|
-
[1,2,3].compact_join(' ').
|
64
|
+
expect([1,2,3].compact_join(' ')).to eq([1,2,3].join(' '))
|
65
65
|
end
|
66
66
|
|
67
67
|
it 'is equivalent to #compact and #join when there are no empty elements' do
|
68
|
-
[1,2,3,nil,nil,4].compact_join(' ').
|
68
|
+
expect([1,2,3,nil,nil,4].compact_join(' ')).to eq([1,2,3,nil,nil,4].compact.join(' '))
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'returns an empty string if the array is empty' do
|
72
|
-
[].compact_join(' ').
|
72
|
+
expect([].compact_join(' ')).to eq('')
|
73
73
|
end
|
74
74
|
|
75
75
|
it 'returns an empty string if there are only nil elements' do
|
76
|
-
[nil,nil,nil].compact_join(' ').
|
76
|
+
expect([nil,nil,nil].compact_join(' ')).to eq('')
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'returns an empty string if there are only empty elements' do
|
80
|
-
['','',''].compact_join(' ').
|
80
|
+
expect(['','',''].compact_join(' ')).to eq('')
|
81
81
|
end
|
82
82
|
|
83
83
|
it 'returns an empty string if there are only blank elements' do
|
84
|
-
['','',nil,'',nil].compact_join(' ').
|
84
|
+
expect(['','',nil,'',nil].compact_join(' ')).to eq('')
|
85
85
|
end
|
86
86
|
|
87
87
|
end
|
data/spec/citeproc/item_spec.rb
CHANGED
@@ -8,26 +8,26 @@ module CiteProc
|
|
8
8
|
it { should_not be nil }
|
9
9
|
|
10
10
|
it 'creates number variables for number fields' do
|
11
|
-
Item.new(:edition => 23).edition.
|
11
|
+
expect(Item.new(:edition => 23).edition).to be_a(Number)
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'creates text variable for text fields' do
|
15
|
-
Item.new(:ISBN => 23).isbn.
|
15
|
+
expect(Item.new(:ISBN => 23).isbn).to be_a(Text)
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'creates date variables for date fields' do
|
19
|
-
Item.new(:accessed => Time.now).accessed.
|
19
|
+
expect(Item.new(:accessed => Time.now).accessed).to be_a(CiteProc::Date)
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'creates names variables for name fields' do
|
23
|
-
Item.new(:editor => { :given => 'Jane' }).editor.
|
24
|
-
Item.new(:editor => 'Plato and Socrates').editor.
|
23
|
+
expect(Item.new(:editor => { :given => 'Jane' }).editor).to be_a(Names)
|
24
|
+
expect(Item.new(:editor => 'Plato and Socrates').editor.names.size).to eq(2)
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'creates text variables for unknown fields' do
|
28
28
|
v = Item.new(:unknown => 42)[:unknown]
|
29
|
-
v.
|
30
|
-
v.
|
29
|
+
expect(v).to be_a(Variable)
|
30
|
+
expect(v).to eq('42')
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -35,44 +35,44 @@ module CiteProc
|
|
35
35
|
it { should be_empty }
|
36
36
|
|
37
37
|
it 'returns false when there is at least one variable in the item' do
|
38
|
-
Item.new(:title => 'foo').
|
38
|
+
expect(Item.new(:title => 'foo')).not_to be_empty
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
describe '#each' do
|
43
43
|
it 'yields each variable to the given block' do
|
44
|
-
Item.new(:title => 'foo', :edition => 2).each.map {|kv| kv.join('-') }.sort.
|
44
|
+
expect(Item.new(:title => 'foo', :edition => 2).each.map {|kv| kv.join('-') }.sort).to eq(%w{edition-2 title-foo})
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
describe '#each_value' do
|
49
49
|
it "yields each variable's value to the given block" do
|
50
|
-
Item.new(:title => 'foo', :edition => 2).each_value.map(&:to_s).sort.
|
50
|
+
expect(Item.new(:title => 'foo', :edition => 2).each_value.map(&:to_s).sort).to eq(%w{2 foo})
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
describe '#to_citeproc' do
|
55
55
|
it 'returns an empty hash by default' do
|
56
|
-
Item.new.to_citeproc.
|
56
|
+
expect(Item.new.to_citeproc).to eq({})
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'returns a hash with stringified keys' do
|
60
|
-
Item.new(:issue => 42).to_citeproc.
|
60
|
+
expect(Item.new(:issue => 42).to_citeproc).to have_key('issue')
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'returns a hash with stringified values' do
|
64
|
-
Item.new(:issue => 42).to_citeproc.values[0].
|
64
|
+
expect(Item.new(:issue => 42).to_citeproc.values[0]).to eq('42')
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
68
|
describe '#dup' do
|
69
69
|
it 'returns a copy' do
|
70
70
|
item = Item.new
|
71
|
-
item.dup.
|
71
|
+
expect(item.dup).not_to equal(item)
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'copies all variables' do
|
75
|
-
Item.new(:issued => 1976).dup[:issued].year.
|
75
|
+
expect(Item.new(:issued => 1976).dup[:issued].year).to eq(1976)
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
data/spec/citeproc/names_spec.rb
CHANGED
@@ -75,44 +75,44 @@ module CiteProc
|
|
75
75
|
describe 'formatting options' do
|
76
76
|
|
77
77
|
it 'does not always demote particle by default' do
|
78
|
-
Name.new.always_demote_particle
|
79
|
-
Name.new.always_demote_non_dropping_particle
|
78
|
+
expect(Name.new.always_demote_particle?).to be false
|
79
|
+
expect(Name.new.always_demote_non_dropping_particle?).to be false
|
80
80
|
end
|
81
81
|
|
82
82
|
it 'does not demote particle by default' do
|
83
|
-
Name.new.demote_particle
|
84
|
-
Name.new.demote_non_dropping_particle
|
83
|
+
expect(Name.new.demote_particle?).to be false
|
84
|
+
expect(Name.new.demote_non_dropping_particle?).to be false
|
85
85
|
end
|
86
86
|
|
87
87
|
it 'does not demote particle in sort order by default' do
|
88
|
-
Name.new.sort_order!.demote_particle
|
89
|
-
Name.new.sort_order!.demote_non_dropping_particle
|
88
|
+
expect(Name.new.sort_order!.demote_particle?).to be false
|
89
|
+
expect(Name.new.sort_order!.demote_non_dropping_particle?).to be false
|
90
90
|
end
|
91
91
|
|
92
92
|
it 'always demotes particle if option is set' do
|
93
|
-
Name.new({}, :'demote-non-dropping-particle' => 'display-and-sort').always_demote_particle
|
94
|
-
Name.new({}, :'demote-non-dropping-particle' => 'display-and-sort').always_demote_non_dropping_particle
|
93
|
+
expect(Name.new({}, :'demote-non-dropping-particle' => 'display-and-sort').always_demote_particle?).to be true
|
94
|
+
expect(Name.new({}, :'demote-non-dropping-particle' => 'display-and-sort').always_demote_non_dropping_particle?).to be true
|
95
95
|
end
|
96
96
|
|
97
97
|
it 'demotes particle in sort order if option is set to sort-only' do
|
98
|
-
Name.new({}, :'demote-non-dropping-particle' => 'display-and-sort').sort_order!.demote_particle
|
98
|
+
expect(Name.new({}, :'demote-non-dropping-particle' => 'display-and-sort').sort_order!.demote_particle?).to be true
|
99
99
|
end
|
100
100
|
|
101
101
|
it 'never demotes particle by default' do
|
102
|
-
Name.new.never_demote_particle
|
103
|
-
Name.new.never_demote_non_dropping_particle
|
102
|
+
expect(Name.new.never_demote_particle?).to be true
|
103
|
+
expect(Name.new.never_demote_non_dropping_particle?).to be true
|
104
104
|
end
|
105
105
|
|
106
106
|
it 'is not in sort order by default' do
|
107
|
-
Name.new.sort_order
|
107
|
+
expect(Name.new.sort_order?).to be false
|
108
108
|
end
|
109
109
|
|
110
110
|
it 'uses the long form by default' do
|
111
|
-
Name.new.
|
111
|
+
expect(Name.new).to be_long_form
|
112
112
|
end
|
113
113
|
|
114
114
|
it 'does not use short form by default' do
|
115
|
-
Name.new.
|
115
|
+
expect(Name.new).not_to be_short_form
|
116
116
|
end
|
117
117
|
|
118
118
|
end
|
@@ -122,41 +122,41 @@ module CiteProc
|
|
122
122
|
|
123
123
|
it 'returns the given name initials' do
|
124
124
|
name.given = 'Edgar A'
|
125
|
-
name.initials.
|
125
|
+
expect(name.initials).to eq('E. A.')
|
126
126
|
|
127
127
|
name.options[:initialize] = 'false'
|
128
|
-
name.initials.
|
128
|
+
expect(name.initials).to eq('Edgar A.')
|
129
129
|
end
|
130
130
|
|
131
131
|
describe 'private helpers' do
|
132
132
|
it '#initials_of initializes the given string' do
|
133
|
-
name.send(:initials_of, 'James T.').
|
134
|
-
name.send(:initials_of, 'JT').
|
135
|
-
name.send(:initials_of, 'James T').
|
136
|
-
name.send(:initials_of, 'Jean-Luc').
|
137
|
-
name.send(:initials_of, 'Vérité Äpfel').
|
133
|
+
expect(name.send(:initials_of, 'James T.')).to eq('J. T.')
|
134
|
+
expect(name.send(:initials_of, 'JT')).to eq('J. T.')
|
135
|
+
expect(name.send(:initials_of, 'James T')).to eq('J. T.')
|
136
|
+
expect(name.send(:initials_of, 'Jean-Luc')).to eq('J.-L.')
|
137
|
+
expect(name.send(:initials_of, 'Vérité Äpfel')).to eq('V. Ä.')
|
138
138
|
|
139
139
|
name.initialize_without_hyphen!
|
140
|
-
name.send(:initials_of, 'Jean-Luc').
|
140
|
+
expect(name.send(:initials_of, 'Jean-Luc')).to eq('J. L.')
|
141
141
|
|
142
142
|
name.options[:'initialize-with'] = '.'
|
143
|
-
name.send(:initials_of, 'James T.').
|
144
|
-
name.send(:initials_of, 'James T').
|
145
|
-
name.send(:initials_of, 'Jean-Luc').
|
143
|
+
expect(name.send(:initials_of, 'James T.')).to eq('J.T.')
|
144
|
+
expect(name.send(:initials_of, 'James T')).to eq('J.T.')
|
145
|
+
expect(name.send(:initials_of, 'Jean-Luc')).to eq('J.L.')
|
146
146
|
|
147
147
|
name.options[:'initialize-with-hyphen'] = true
|
148
|
-
name.send(:initials_of, 'Jean-Luc').
|
148
|
+
expect(name.send(:initials_of, 'Jean-Luc')).to eq('J.-L.')
|
149
149
|
end
|
150
150
|
|
151
151
|
it '#initialize_existing_only initializes only current initials' do
|
152
|
-
name.send(:existing_initials_of, 'James T. Kirk').
|
153
|
-
name.send(:existing_initials_of, 'James T.Kirk').
|
154
|
-
name.send(:existing_initials_of, 'James T').
|
155
|
-
name.send(:existing_initials_of, 'Jean-Luc').
|
156
|
-
name.send(:existing_initials_of, 'J.-L.M.').
|
157
|
-
name.send(:existing_initials_of, 'J-L').
|
158
|
-
name.send(:existing_initials_of, 'J-LM').
|
159
|
-
name.send(:existing_initials_of, 'JT').
|
152
|
+
expect(name.send(:existing_initials_of, 'James T. Kirk')).to eq('James T. Kirk')
|
153
|
+
expect(name.send(:existing_initials_of, 'James T.Kirk')).to eq('James T. Kirk')
|
154
|
+
expect(name.send(:existing_initials_of, 'James T')).to eq('James T.')
|
155
|
+
expect(name.send(:existing_initials_of, 'Jean-Luc')).to eq('Jean-Luc')
|
156
|
+
expect(name.send(:existing_initials_of, 'J.-L.M.')).to eq('J.-L. M.')
|
157
|
+
expect(name.send(:existing_initials_of, 'J-L')).to eq('J.-L.')
|
158
|
+
expect(name.send(:existing_initials_of, 'J-LM')).to eq('J.-L. M.')
|
159
|
+
expect(name.send(:existing_initials_of, 'JT')).to eq('J. T.')
|
160
160
|
end
|
161
161
|
end
|
162
162
|
end
|
@@ -166,11 +166,11 @@ module CiteProc
|
|
166
166
|
describe '.new' do
|
167
167
|
|
168
168
|
it 'accepts a symbolized hash' do
|
169
|
-
Name.new(:family => 'Doe').format.
|
169
|
+
expect(Name.new(:family => 'Doe').format).to eq('Doe')
|
170
170
|
end
|
171
171
|
|
172
172
|
it 'accepts a stringified hash' do
|
173
|
-
Name.new('family' => 'Doe').format.
|
173
|
+
expect(Name.new('family' => 'Doe').format).to eq('Doe')
|
174
174
|
end
|
175
175
|
|
176
176
|
end
|
@@ -180,7 +180,7 @@ module CiteProc
|
|
180
180
|
describe '#dup' do
|
181
181
|
|
182
182
|
it 'returns a new name copied by value' do
|
183
|
-
poe.dup.upcase!.format.
|
183
|
+
expect(poe.dup.upcase!.format).not_to eq(poe.format)
|
184
184
|
end
|
185
185
|
|
186
186
|
end
|
@@ -188,31 +188,31 @@ module CiteProc
|
|
188
188
|
describe 'script awareness' do
|
189
189
|
|
190
190
|
it 'english names are romanesque' do
|
191
|
-
frank.
|
191
|
+
expect(frank).to be_romanesque
|
192
192
|
end
|
193
193
|
|
194
194
|
it 'ancient greek names are romanesque' do
|
195
|
-
aristotle.
|
195
|
+
expect(aristotle).to be_romanesque
|
196
196
|
end
|
197
197
|
|
198
198
|
it 'russian names are romanesque' do
|
199
|
-
dostoyevksy.
|
199
|
+
expect(dostoyevksy).to be_romanesque
|
200
200
|
end
|
201
201
|
|
202
202
|
it 'japanese names are not romanesque' do
|
203
|
-
japanese.
|
203
|
+
expect(japanese).not_to be_romanesque
|
204
204
|
end
|
205
205
|
|
206
206
|
it 'german names are romanesque' do
|
207
|
-
Name.new(:given => 'Friedrich', :family => 'Hölderlin').
|
207
|
+
expect(Name.new(:given => 'Friedrich', :family => 'Hölderlin')).to be_romanesque
|
208
208
|
end
|
209
209
|
|
210
210
|
it 'french names are romanesque' do
|
211
|
-
utf.
|
211
|
+
expect(utf).to be_romanesque
|
212
212
|
end
|
213
213
|
|
214
214
|
it 'markup does not interfere with romanesque test' do
|
215
|
-
markup.
|
215
|
+
expect(markup).to be_romanesque
|
216
216
|
end
|
217
217
|
|
218
218
|
end
|
@@ -220,15 +220,15 @@ module CiteProc
|
|
220
220
|
describe 'literals' do
|
221
221
|
|
222
222
|
it 'is a literal if the literal attribute is set' do
|
223
|
-
Name.new(:literal => 'GNU/Linux').
|
223
|
+
expect(Name.new(:literal => 'GNU/Linux')).to be_literal
|
224
224
|
end
|
225
225
|
|
226
226
|
it 'is not literal by default' do
|
227
|
-
Name.new.
|
227
|
+
expect(Name.new).not_to be_literal
|
228
228
|
end
|
229
229
|
|
230
230
|
it 'is literal even if other name parts are set' do
|
231
|
-
Name.new(:family => 'Tux', :literal => 'GNU/Linux').
|
231
|
+
expect(Name.new(:family => 'Tux', :literal => 'GNU/Linux')).to be_literal
|
232
232
|
end
|
233
233
|
|
234
234
|
end
|
@@ -236,27 +236,27 @@ module CiteProc
|
|
236
236
|
describe 'in-place manipulation (bang! methods)' do
|
237
237
|
|
238
238
|
it 'delegates to string for family name' do
|
239
|
-
plato.swapcase!.format.
|
239
|
+
expect(plato.swapcase!.format).to eq('pLATO')
|
240
240
|
end
|
241
241
|
|
242
242
|
it 'delegates to string for given name' do
|
243
|
-
humboldt.gsub!(/^Alex\w*/, 'Wilhelm').format.
|
243
|
+
expect(humboldt.gsub!(/^Alex\w*/, 'Wilhelm').format).to eq('Wilhelm von Humboldt')
|
244
244
|
end
|
245
245
|
|
246
246
|
it 'delegates to string for dropping particle' do
|
247
|
-
humboldt.upcase!.dropping_particle.
|
247
|
+
expect(humboldt.upcase!.dropping_particle).to eq('VON')
|
248
248
|
end
|
249
249
|
|
250
250
|
it 'delegates to string for non dropping particle' do
|
251
|
-
van_gogh.upcase!.non_dropping_particle.
|
251
|
+
expect(van_gogh.upcase!.non_dropping_particle).to eq('VAN')
|
252
252
|
end
|
253
253
|
|
254
254
|
it 'delegates to string for suffix' do
|
255
|
-
frank.sub!(/jr./i, 'Sr.').format.
|
255
|
+
expect(frank.sub!(/jr./i, 'Sr.').format).to eq('Frank G. Bennett, Sr.')
|
256
256
|
end
|
257
257
|
|
258
258
|
it 'returns the name object' do
|
259
|
-
poe.upcase
|
259
|
+
expect(poe.upcase!).to be_a(Name)
|
260
260
|
end
|
261
261
|
|
262
262
|
end
|
@@ -265,19 +265,19 @@ module CiteProc
|
|
265
265
|
describe '#format' do
|
266
266
|
|
267
267
|
it 'returns an empty string by default' do
|
268
|
-
Name.new.format.
|
268
|
+
expect(Name.new.format).to be_empty
|
269
269
|
end
|
270
270
|
|
271
271
|
it 'returns the last name if only last name is set' do
|
272
|
-
Name.new(:family => 'Doe').format.
|
272
|
+
expect(Name.new(:family => 'Doe').format).to eq('Doe')
|
273
273
|
end
|
274
274
|
|
275
275
|
it 'returns the first name if only the first name is set' do
|
276
|
-
Name.new(:given => 'John').format.
|
276
|
+
expect(Name.new(:given => 'John').format).to eq('John')
|
277
277
|
end
|
278
278
|
|
279
279
|
it 'prints japanese names using static ordering' do
|
280
|
-
japanese.format.
|
280
|
+
expect(japanese.format).to eq('穂積 陳重')
|
281
281
|
end
|
282
282
|
|
283
283
|
it 'returns the literal if the name is a literal' do
|
@@ -285,45 +285,45 @@ module CiteProc
|
|
285
285
|
end
|
286
286
|
|
287
287
|
it 'returns the name in display order by default' do
|
288
|
-
Name.new(:family => 'Doe', :given => 'John').format.
|
288
|
+
expect(Name.new(:family => 'Doe', :given => 'John').format).to eq('John Doe')
|
289
289
|
end
|
290
290
|
|
291
291
|
it 'returns the name in sort order if the sort order option is active' do
|
292
|
-
Name.new(:family => 'Doe', :given => 'John').sort_order!.format.
|
292
|
+
expect(Name.new(:family => 'Doe', :given => 'John').sort_order!.format).to eq('Doe, John')
|
293
293
|
end
|
294
294
|
|
295
295
|
it 'returns the full given name' do
|
296
|
-
saunders.format.
|
296
|
+
expect(saunders.format).to eq('John Bertrand de Cusance Morant Saunders')
|
297
297
|
end
|
298
298
|
|
299
299
|
it 'includes dropping particles' do
|
300
|
-
humboldt.format.
|
300
|
+
expect(humboldt.format).to eq('Alexander von Humboldt')
|
301
301
|
end
|
302
302
|
|
303
303
|
it 'includes non dropping particles' do
|
304
|
-
van_gogh.format.
|
304
|
+
expect(van_gogh.format).to eq('Vincent van Gogh')
|
305
305
|
end
|
306
306
|
|
307
307
|
it 'includes suffices' do
|
308
|
-
jr.format.
|
308
|
+
expect(jr.format).to eq('James Stephens Jr.')
|
309
309
|
end
|
310
310
|
|
311
311
|
it 'uses the comma suffix option' do
|
312
|
-
frank.format.
|
312
|
+
expect(frank.format).to eq('Frank G. Bennett, Jr.')
|
313
313
|
end
|
314
314
|
|
315
315
|
it 'prints unicode characters' do
|
316
|
-
utf.format.
|
316
|
+
expect(utf.format).to eq("Gérard de la Martinière III")
|
317
317
|
end
|
318
318
|
|
319
319
|
it 'prints russian names normally' do
|
320
|
-
dostoyevksy.format.
|
320
|
+
expect(dostoyevksy.format).to eq('Фёдор Михайлович Достоевский')
|
321
321
|
end
|
322
322
|
|
323
323
|
describe 'when static ordering is active' do
|
324
324
|
|
325
325
|
it 'always prints the family name first' do
|
326
|
-
poe.static_order!.format.
|
326
|
+
expect(poe.static_order!.format).to eq('Poe Edgar Allen')
|
327
327
|
end
|
328
328
|
|
329
329
|
end
|
@@ -331,19 +331,19 @@ module CiteProc
|
|
331
331
|
describe 'when the sort order option is active' do
|
332
332
|
|
333
333
|
it 'returns an empty string by default' do
|
334
|
-
Name.new.sort_order!.format.
|
334
|
+
expect(Name.new.sort_order!.format).to be_empty
|
335
335
|
end
|
336
336
|
|
337
337
|
it 'returns the last name if only last name is set' do
|
338
|
-
Name.new({:family => 'Doe'}, { :'name-as-sort-order' => true }).format.
|
338
|
+
expect(Name.new({:family => 'Doe'}, { :'name-as-sort-order' => true }).format).to eq('Doe')
|
339
339
|
end
|
340
340
|
|
341
341
|
it 'returns the first name if only the first name is set' do
|
342
|
-
Name.new(:given => 'John').sort_order!.format.
|
342
|
+
expect(Name.new(:given => 'John').sort_order!.format).to eq('John')
|
343
343
|
end
|
344
344
|
|
345
345
|
it 'prints japanese names using static ordering' do
|
346
|
-
japanese.sort_order!.format.
|
346
|
+
expect(japanese.sort_order!.format).to eq('穂積 陳重')
|
347
347
|
end
|
348
348
|
|
349
349
|
it 'returns the literal if the name is a literal' do
|
@@ -351,31 +351,31 @@ module CiteProc
|
|
351
351
|
end
|
352
352
|
|
353
353
|
it 'uses comma for suffix if comma suffix is set' do
|
354
|
-
frank.sort_order!.format.
|
354
|
+
expect(frank.sort_order!.format).to eq('Bennett, Frank G., Jr.')
|
355
355
|
end
|
356
356
|
|
357
357
|
it 'also uses comma for suffix if comma suffix is *not* set' do
|
358
|
-
jr.sort_order!.format.
|
358
|
+
expect(jr.sort_order!.format).to eq('Stephens, James, Jr.')
|
359
359
|
end
|
360
360
|
|
361
361
|
it 'for normal names it prints them as "family, given"' do
|
362
|
-
poe.sort_order!.format.
|
362
|
+
expect(poe.sort_order!.format).to eq('Poe, Edgar Allen')
|
363
363
|
end
|
364
364
|
|
365
365
|
it 'particles come after given name by default' do
|
366
|
-
van_gogh.sort_order!.format.
|
366
|
+
expect(van_gogh.sort_order!.format).to eq('van Gogh, Vincent')
|
367
367
|
end
|
368
368
|
|
369
369
|
it 'particles come after given name if demote option is active' do
|
370
|
-
van_gogh.sort_order!.demote_particle!.format.
|
370
|
+
expect(van_gogh.sort_order!.demote_particle!.format).to eq('Gogh, Vincent van')
|
371
371
|
end
|
372
372
|
|
373
373
|
it 'dropping particles come after given name' do
|
374
|
-
humboldt.sort_order!.format.
|
374
|
+
expect(humboldt.sort_order!.format).to eq('Humboldt, Alexander von')
|
375
375
|
end
|
376
376
|
|
377
377
|
it 'by default if all parts are set they are returned as "particle family, first dropping-particle, suffix"' do
|
378
|
-
utf.sort_order!.format.
|
378
|
+
expect(utf.sort_order!.format).to eq('la Martinière, Gérard de, III')
|
379
379
|
end
|
380
380
|
|
381
381
|
end
|
@@ -385,52 +385,52 @@ module CiteProc
|
|
385
385
|
describe '#sort_order' do
|
386
386
|
|
387
387
|
it 'returns only a single token for literal names' do
|
388
|
-
Name.new(:literal => 'ACME Corp.').sort_order.
|
388
|
+
expect(Name.new(:literal => 'ACME Corp.').sort_order.size).to eq(1)
|
389
389
|
end
|
390
390
|
|
391
391
|
it 'strips leading "the" off literal names' do
|
392
|
-
Name.new(:literal => 'The ACME Corp.').sort_order[0].
|
392
|
+
expect(Name.new(:literal => 'The ACME Corp.').sort_order[0]).to eq('ACME Corp.')
|
393
393
|
end
|
394
394
|
|
395
395
|
it 'strips leading "a" off literal names' do
|
396
|
-
Name.new(:literal => 'A Company').sort_order[0].
|
396
|
+
expect(Name.new(:literal => 'A Company').sort_order[0]).to eq('Company')
|
397
397
|
end
|
398
398
|
|
399
399
|
it 'strips leading "an" off literal names' do
|
400
|
-
Name.new(:literal => 'an ACME Corp.').sort_order[0].
|
400
|
+
expect(Name.new(:literal => 'an ACME Corp.').sort_order[0]).to eq('ACME Corp.')
|
401
401
|
end
|
402
402
|
|
403
403
|
it 'strips leading "l\'" off literal names' do
|
404
|
-
Name.new(:literal => "L'Augustine").sort_order[0].
|
404
|
+
expect(Name.new(:literal => "L'Augustine").sort_order[0]).to eq('Augustine')
|
405
405
|
end
|
406
406
|
|
407
407
|
it 'always returns four tokens for non literal names' do
|
408
|
-
poe.sort_order.
|
409
|
-
joe.sort_order.
|
410
|
-
aristotle.sort_order.
|
411
|
-
utf.sort_order.
|
412
|
-
frank.sort_order.
|
413
|
-
japanese.sort_order.
|
408
|
+
expect(poe.sort_order.size).to eq(4)
|
409
|
+
expect(joe.sort_order.size).to eq(4)
|
410
|
+
expect(aristotle.sort_order.size).to eq(4)
|
411
|
+
expect(utf.sort_order.size).to eq(4)
|
412
|
+
expect(frank.sort_order.size).to eq(4)
|
413
|
+
expect(japanese.sort_order.size).to eq(4)
|
414
414
|
end
|
415
415
|
|
416
416
|
it 'demotes non dropping particles if option is set' do
|
417
|
-
van_gogh.demote_particle!.sort_order.
|
417
|
+
expect(van_gogh.demote_particle!.sort_order).to eq(['Gogh', 'van', 'Vincent', ''])
|
418
418
|
end
|
419
419
|
|
420
420
|
it 'does not demote non dropping particles by default' do
|
421
|
-
van_gogh.sort_order.
|
421
|
+
expect(van_gogh.sort_order).to eq(['van Gogh', '', 'Vincent', ''])
|
422
422
|
end
|
423
423
|
|
424
424
|
it 'does not demote non dropping particles by default but dropping particles are demoted' do
|
425
|
-
utf.sort_order.
|
425
|
+
expect(utf.sort_order).to eq(['la Martinière', 'de', 'Gérard', 'III'])
|
426
426
|
end
|
427
427
|
|
428
428
|
it 'demotes dropping particles' do
|
429
|
-
humboldt.sort_order.
|
429
|
+
expect(humboldt.sort_order).to eq(['Humboldt', 'von', 'Alexander', ''])
|
430
430
|
end
|
431
431
|
|
432
432
|
it 'combines non dropping particles with family name if option demote-non-dropping-particles is not active' do
|
433
|
-
van_gogh.never_demote_particle!.sort_order.
|
433
|
+
expect(van_gogh.never_demote_particle!.sort_order).to eq(['van Gogh', '', 'Vincent', ''])
|
434
434
|
end
|
435
435
|
|
436
436
|
end
|
@@ -438,7 +438,7 @@ module CiteProc
|
|
438
438
|
describe 'sorting' do
|
439
439
|
|
440
440
|
it 'sorts by sort order by default' do
|
441
|
-
[poe, utf, joe, plato].sort.
|
441
|
+
expect([poe, utf, joe, plato].sort).to eq([joe, plato, utf, poe])
|
442
442
|
end
|
443
443
|
|
444
444
|
end
|
@@ -458,43 +458,43 @@ module CiteProc
|
|
458
458
|
describe 'constructing' do
|
459
459
|
|
460
460
|
it 'accepts a single name' do
|
461
|
-
|
461
|
+
expect { Names.new(joe) }.not_to raise_error
|
462
462
|
end
|
463
463
|
|
464
464
|
it 'accepts a single name as hash' do
|
465
|
-
Names.new(:given => 'Jim').
|
465
|
+
expect(Names.new(:given => 'Jim').names.size).to eq(1)
|
466
466
|
end
|
467
467
|
|
468
468
|
it 'accepts two names' do
|
469
|
-
Names.new(joe, poe).
|
469
|
+
expect(Names.new(joe, poe).names.size).to eq(2)
|
470
470
|
end
|
471
471
|
|
472
472
|
it 'accepts two names as hash' do
|
473
|
-
Names.new({:given => 'Jim'}, {:family => 'Jameson'}).
|
473
|
+
expect(Names.new({:given => 'Jim'}, {:family => 'Jameson'}).names.size).to eq(2)
|
474
474
|
end
|
475
475
|
|
476
476
|
it 'accepts an array of names' do
|
477
|
-
Names.new([joe, poe]).
|
477
|
+
expect(Names.new([joe, poe]).names.size).to eq(2)
|
478
478
|
end
|
479
479
|
|
480
480
|
end
|
481
481
|
|
482
482
|
describe 'parsing' do
|
483
483
|
it 'accepts a single name as a string' do
|
484
|
-
Names.parse('Edgar A. Poe').
|
484
|
+
expect(Names.parse('Edgar A. Poe').names.size).to eq(1)
|
485
485
|
end
|
486
486
|
|
487
487
|
it 'accepts multiple names as a string' do
|
488
|
-
Names.parse('Edgar A. Poe and Hawthorne, Nathaniel and Herman Melville').
|
488
|
+
expect(Names.parse('Edgar A. Poe and Hawthorne, Nathaniel and Herman Melville').names.size).to eq(3)
|
489
489
|
end
|
490
490
|
|
491
491
|
it 'parses the passed-in family names' do
|
492
|
-
Names.parse('Edgar A. Poe and Hawthorne, Nathaniel and Herman Melville').map { |n|
|
493
|
-
n.values_at(:family) }.flatten.
|
492
|
+
expect(Names.parse('Edgar A. Poe and Hawthorne, Nathaniel and Herman Melville').map { |n|
|
493
|
+
n.values_at(:family) }.flatten).to eq(%w{ Poe Hawthorne Melville })
|
494
494
|
end
|
495
495
|
|
496
496
|
it '#parse returns nil on error' do
|
497
|
-
Names.parse(23).
|
497
|
+
expect(Names.parse(23)).to be_nil
|
498
498
|
end
|
499
499
|
|
500
500
|
it '#parse! raises an error on bad input' do
|
@@ -506,11 +506,11 @@ module CiteProc
|
|
506
506
|
describe '#strip_markup' do
|
507
507
|
|
508
508
|
it 'strips markup off string representation' do
|
509
|
-
Names.new(markup).strip_markup.
|
509
|
+
expect(Names.new(markup).strip_markup).to eq(utf.to_s)
|
510
510
|
end
|
511
511
|
|
512
512
|
it 'when using the bang! version, strips markup off each name part' do
|
513
|
-
Names.new(markup).strip_markup![0].
|
513
|
+
expect(Names.new(markup).strip_markup![0]).to eq(utf)
|
514
514
|
end
|
515
515
|
|
516
516
|
|
@@ -518,7 +518,7 @@ module CiteProc
|
|
518
518
|
|
519
519
|
describe 'bang! methods' do
|
520
520
|
it 'delegate to the individual names and return self' do
|
521
|
-
Names.new(poe, plato, joe).upcase!.map(&:given).
|
521
|
+
expect(Names.new(poe, plato, joe).upcase!.map(&:given)).to eq(['EDGAR ALLEN', 'PLATO', 'JOE'])
|
522
522
|
end
|
523
523
|
end
|
524
524
|
|
@@ -528,34 +528,34 @@ module CiteProc
|
|
528
528
|
|
529
529
|
describe "##{setter}" do
|
530
530
|
it 'sets the delimiter precedes last option accordingly' do
|
531
|
-
Names.new.send(setter).send(predicate).
|
531
|
+
expect(Names.new.send(setter).send(predicate)).to eq(true)
|
532
532
|
end
|
533
533
|
end
|
534
534
|
end
|
535
535
|
|
536
536
|
describe '#delimiter_precedes_last' do
|
537
537
|
it 'returns false by default' do
|
538
|
-
Names.new(joe).
|
538
|
+
expect(Names.new(joe)).not_to be_delimiter_precedes_last
|
539
539
|
end
|
540
540
|
|
541
541
|
it 'returns false by default for a single name' do
|
542
|
-
Names.new(joe).
|
542
|
+
expect(Names.new(joe)).not_to be_delimiter_precedes_last
|
543
543
|
end
|
544
544
|
|
545
545
|
it 'returns false by default for two names' do
|
546
|
-
Names.new(joe, poe).
|
546
|
+
expect(Names.new(joe, poe)).not_to be_delimiter_precedes_last
|
547
547
|
end
|
548
548
|
|
549
549
|
it 'returns true for two names when option set to always' do
|
550
|
-
Names.new(joe, poe).delimiter_always_precedes_last
|
550
|
+
expect(Names.new(joe, poe).delimiter_always_precedes_last!).to be_delimiter_precedes_last
|
551
551
|
end
|
552
552
|
|
553
553
|
it 'returns true by default for three names' do
|
554
|
-
Names.new(joe, poe, plato).
|
554
|
+
expect(Names.new(joe, poe, plato)).to be_delimiter_precedes_last
|
555
555
|
end
|
556
556
|
|
557
557
|
it 'returns false for three names when option set to :never' do
|
558
|
-
Names.new(joe, poe, plato).delimiter_never_precedes_last
|
558
|
+
expect(Names.new(joe, poe, plato).delimiter_never_precedes_last!).not_to be_delimiter_precedes_last
|
559
559
|
end
|
560
560
|
end
|
561
561
|
|
@@ -563,13 +563,13 @@ module CiteProc
|
|
563
563
|
|
564
564
|
describe 'when there is only a single name' do
|
565
565
|
it 'prints the name in sort order' do
|
566
|
-
Names.new(poe).to_bibtex.
|
566
|
+
expect(Names.new(poe).to_bibtex).to eq('Poe, Edgar Allen')
|
567
567
|
end
|
568
568
|
end
|
569
569
|
|
570
570
|
describe 'when there are two or more names' do
|
571
571
|
it 'prints the names in sort order connected with the word "and"' do
|
572
|
-
Names.new(poe, plato, humboldt).to_bibtex.
|
572
|
+
expect(Names.new(poe, plato, humboldt).to_bibtex).to eq('Poe, Edgar Allen and Plato and Humboldt, Alexander von')
|
573
573
|
end
|
574
574
|
end
|
575
575
|
|
@@ -585,57 +585,57 @@ module CiteProc
|
|
585
585
|
end
|
586
586
|
|
587
587
|
it 'prints only the et-al-use-first names' do
|
588
|
-
gang_of_four.to_s.
|
589
|
-
gang_of_four.to_s.
|
588
|
+
expect(gang_of_four.to_s).to match(/gamma.+helm/i)
|
589
|
+
expect(gang_of_four.to_s).not_to match(/johnson|vlissides/i)
|
590
590
|
end
|
591
591
|
|
592
592
|
it 'adds et-al at the end' do
|
593
|
-
gang_of_four.to_s.
|
593
|
+
expect(gang_of_four.to_s).to end_with('FOO')
|
594
594
|
end
|
595
595
|
|
596
596
|
it 'adds the delimiter before et-al when multiple names are printed' do
|
597
|
-
gang_of_four.to_s.
|
597
|
+
expect(gang_of_four.to_s).to end_with(', FOO')
|
598
598
|
end
|
599
599
|
|
600
600
|
it 'does not add the delimiter before et-al when only one name is printed' do
|
601
601
|
gang_of_four.options[:'et-al-use-first'] = 1
|
602
|
-
gang_of_four.to_s.
|
602
|
+
expect(gang_of_four.to_s).not_to end_with(', FOO')
|
603
603
|
end
|
604
604
|
|
605
605
|
end
|
606
606
|
|
607
607
|
it 'squeezes multiple whitespace between delimiter and connector' do
|
608
|
-
Names.new(poe, humboldt, van_gogh, joe).to_s.
|
608
|
+
expect(Names.new(poe, humboldt, van_gogh, joe).to_s).not_to match(/\s{2}/)
|
609
609
|
end
|
610
610
|
end
|
611
611
|
|
612
612
|
describe '#each' do
|
613
613
|
it 'returns an enumerator when no block given' do
|
614
|
-
gang_of_four.each.
|
614
|
+
expect(gang_of_four.each).to respond_to(:each)
|
615
615
|
end
|
616
616
|
end
|
617
617
|
|
618
618
|
describe '#to_citeproc' do
|
619
619
|
it 'returns a list of hashes' do
|
620
|
-
gang_of_four.to_citeproc.map(&:class).uniq.
|
620
|
+
expect(gang_of_four.to_citeproc.map(&:class).uniq).to eq([Hash])
|
621
621
|
end
|
622
622
|
end
|
623
623
|
|
624
624
|
describe 'sorting' do
|
625
625
|
it 'accepts other Names instance' do
|
626
|
-
(Names.new(poe, plato) <=> Names.new(plato)).
|
627
|
-
(Names.new(plato) <=> Names.new(poe, plato)).
|
626
|
+
expect(Names.new(poe, plato) <=> Names.new(plato)).to equal(1)
|
627
|
+
expect(Names.new(plato) <=> Names.new(poe, plato)).to equal(-1)
|
628
628
|
end
|
629
629
|
|
630
630
|
it 'accepts other list of names' do
|
631
|
-
(Names.new(poe, plato) <=> [plato]).
|
632
|
-
(Names.new(plato) <=> [poe, plato]).
|
631
|
+
expect(Names.new(poe, plato) <=> [plato]).to equal(1)
|
632
|
+
expect(Names.new(plato) <=> [poe, plato]).to equal(-1)
|
633
633
|
end
|
634
634
|
end
|
635
635
|
|
636
636
|
describe '#inspect' do
|
637
637
|
it 'returns a string' do
|
638
|
-
gang_of_four.inspect.
|
638
|
+
expect(gang_of_four.inspect).to be_a(String)
|
639
639
|
end
|
640
640
|
end
|
641
641
|
|