bibtex-ruby 2.1.2 → 2.2.0
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.
Potentially problematic release.
This version of bibtex-ruby might be problematic. Click here for more details.
- data/Gemfile.lock +1 -1
- data/History.txt +6 -0
- data/lib/bibtex/bibliography.rb +76 -71
- data/lib/bibtex/elements.rb +12 -1
- data/lib/bibtex/entry.rb +166 -121
- data/lib/bibtex/value.rb +26 -3
- data/lib/bibtex/version.rb +2 -2
- data/test/bibtex/test_bibliography.rb +53 -38
- data/test/bibtex/test_entry.rb +90 -57
- data/test/bibtex/test_names.rb +14 -0
- data/test/bibtex/test_value.rb +22 -12
- metadata +4 -4
data/lib/bibtex/value.rb
CHANGED
@@ -77,6 +77,22 @@ module BibTeX
|
|
77
77
|
@tokens = other.tokens.dup
|
78
78
|
end
|
79
79
|
|
80
|
+
def merge(other)
|
81
|
+
dup.merge!(other)
|
82
|
+
end
|
83
|
+
|
84
|
+
def merge!(other)
|
85
|
+
other.tokens.each do |token|
|
86
|
+
add token unless include_token?(token)
|
87
|
+
end
|
88
|
+
|
89
|
+
self
|
90
|
+
end
|
91
|
+
|
92
|
+
def include_token?(token)
|
93
|
+
tokens.include?(token)
|
94
|
+
end
|
95
|
+
|
80
96
|
def add(argument)
|
81
97
|
case argument
|
82
98
|
when Value
|
@@ -127,10 +143,17 @@ module BibTeX
|
|
127
143
|
# Value.new('foo', 'bar').join #=> <'foobar'>
|
128
144
|
# Value.new(:foo, 'bar').join #=> <:foo, 'bar'>
|
129
145
|
#
|
130
|
-
#
|
131
|
-
|
146
|
+
# @param {String} separator
|
147
|
+
#
|
148
|
+
# @return {Value} the instance with all consecutive String tokens joined
|
149
|
+
def join(separator = '')
|
132
150
|
@tokens = @tokens.inject([]) do |a,b|
|
133
|
-
a[-1].is_a?(::String) && b.is_a?(::String)
|
151
|
+
if a[-1].is_a?(::String) && b.is_a?(::String)
|
152
|
+
a[-1] = [a[-1], b].join(separator)
|
153
|
+
else
|
154
|
+
a << b
|
155
|
+
end
|
156
|
+
a
|
134
157
|
end
|
135
158
|
self
|
136
159
|
end
|
data/lib/bibtex/version.rb
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
require 'helper'
|
4
4
|
|
5
5
|
module BibTeX
|
6
|
-
|
6
|
+
|
7
7
|
class BibliographyTest < MiniTest::Spec
|
8
|
-
|
8
|
+
|
9
9
|
describe 'when newly created' do
|
10
10
|
it 'should not be nil' do
|
11
11
|
assert Bibliography.new
|
@@ -20,11 +20,11 @@ module BibTeX
|
|
20
20
|
tmp = Tempfile.new('bibtex')
|
21
21
|
tmp.close
|
22
22
|
b = BibTeX.open(Test.fixtures(:bibdesk)).save_to(tmp.path)
|
23
|
-
|
23
|
+
|
24
24
|
BibTeX.open(tmp.path) do |bib|
|
25
25
|
bib.delete(:rails)
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
assert_equal b.length - 1, BibTeX.open(tmp.path).length
|
29
29
|
end
|
30
30
|
|
@@ -32,14 +32,14 @@ module BibTeX
|
|
32
32
|
|
33
33
|
describe '.parse' do
|
34
34
|
it 'accepts filters' do
|
35
|
-
Bibliography.parse("@misc{k, title = {\\''u}}", :filter => 'latex')[0].title.must_be :==, 'ü'
|
35
|
+
Bibliography.parse("@misc{k, title = {\\''u}}", :filter => 'latex')[0].title.must_be :==, 'ü'
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'accepts filters in an array' do
|
39
|
-
Bibliography.parse("@misc{k, title = {\\''u}}", :filter => ['latex'])[0].title.must_be :==, 'ü'
|
39
|
+
Bibliography.parse("@misc{k, title = {\\''u}}", :filter => ['latex'])[0].title.must_be :==, 'ü'
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
describe 'given a populated biliography' do
|
44
44
|
before do
|
45
45
|
@bib = BibTeX.parse <<-END
|
@@ -78,13 +78,13 @@ module BibTeX
|
|
78
78
|
}
|
79
79
|
END
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
describe '#entries_at' do
|
83
83
|
it 'returns a list of all entries identified by the passed-in keys' do
|
84
84
|
assert_equal [@bib['segaran2007'], @bib['rails']], @bib.entries_at('segaran2007', :rails)
|
85
85
|
end
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
describe '#extend_initials' do
|
89
89
|
it 'extends the initials in matching names' do
|
90
90
|
@bib.names.map(&:to_s).wont_include 'Flanagan, Dave'
|
@@ -92,41 +92,56 @@ module BibTeX
|
|
92
92
|
@bib.names.map(&:to_s).must_include 'Flanagan, Dave'
|
93
93
|
end
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
describe '#extend_initials!' do
|
97
97
|
it 'extends the initials of all names to the longest prototype' do
|
98
98
|
assert_equal "Ruby, Sam Thomas, Dave Hansson Heinemeier, David Flanagan, David Matsumoto, Y. Segaran, T.",
|
99
99
|
@bib.extend_initials!.names.map(&:sort_order).uniq.join(' ')
|
100
100
|
end
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
describe '#unify' do
|
104
104
|
it 'sets all fields matching the given pattern to the passed-in value' do
|
105
105
|
@bib.unify :publisher, /reilly/i, 'OReilly'
|
106
106
|
assert_equal 'OReilly', @bib['segaran2007'].publisher
|
107
107
|
assert_equal 'OReilly', @bib['flanagan2008'].publisher
|
108
108
|
end
|
109
|
-
|
109
|
+
|
110
110
|
it 'does not change the value of fields that do not match' do
|
111
111
|
@bib.unify :publisher, /reilly/i, 'OReilly'
|
112
112
|
assert_equal 'The Pragmatic Bookshelf', @bib['rails'].publisher
|
113
113
|
end
|
114
|
-
|
114
|
+
|
115
115
|
it 'passes each entry with matching fields to the block if given' do
|
116
116
|
years = []
|
117
117
|
@bib.unify(:publisher, /reilly/i) { |e| years << e.year.to_s }
|
118
118
|
assert_equal ['2007','2008'], years.sort
|
119
119
|
end
|
120
|
-
|
120
|
+
|
121
121
|
it 'returns the bibliography' do
|
122
122
|
assert_equal @bib, @bib.unify(:publisher, /reilly/i, 'OReilly')
|
123
123
|
end
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
|
+
describe '#group_by' do
|
127
|
+
it 'returns an empy hash by default' do
|
128
|
+
assert_equal({}, Bibliography.new.group_by)
|
129
|
+
assert_equal({}, Bibliography.new.group_by(:a, :b))
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'returns a hash with all the entries mapped to their default digest' do
|
133
|
+
assert_equal @bib.entries.length, @bib.group_by.length
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'uses the given block to determine the key' do
|
137
|
+
assert_equal @bib.entries.length, (@bib.group_by { 'x' })['x'].length
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
126
141
|
it 'supports access by index' do
|
127
|
-
assert_equal 'ruby', @bib[1].keywords
|
142
|
+
assert_equal 'ruby', @bib[1].keywords
|
128
143
|
end
|
129
|
-
|
144
|
+
|
130
145
|
it 'supports access by range' do
|
131
146
|
assert_equal %w{2008 2007}, @bib[1..2].map(&:year)
|
132
147
|
end
|
@@ -134,7 +149,7 @@ module BibTeX
|
|
134
149
|
it 'supports access by index and offset' do
|
135
150
|
assert_equal %w{2008 2007}, @bib[1,2].map(&:year)
|
136
151
|
end
|
137
|
-
|
152
|
+
|
138
153
|
it 'supports queries by symbol key' do
|
139
154
|
refute_nil @bib[:rails]
|
140
155
|
assert_nil @bib[:ruby]
|
@@ -145,7 +160,7 @@ module BibTeX
|
|
145
160
|
refute_nil @bib.q(:first, :rails)
|
146
161
|
assert_nil @bib.q(:first, :railss)
|
147
162
|
end
|
148
|
-
|
163
|
+
|
149
164
|
it 'supports queries by string key' do
|
150
165
|
refute_nil @bib['rails']
|
151
166
|
assert_nil @bib['ruby']
|
@@ -171,7 +186,7 @@ module BibTeX
|
|
171
186
|
assert_equal 0, @bib[/reilly/].length
|
172
187
|
assert_equal 2, @bib[/reilly/i].length
|
173
188
|
end
|
174
|
-
|
189
|
+
|
175
190
|
it 'supports queries by type string and conditions' do
|
176
191
|
assert_equal 1, @bib['@book[keywords=ruby]'].length
|
177
192
|
end
|
@@ -209,20 +224,20 @@ module BibTeX
|
|
209
224
|
entry.year = '2006'
|
210
225
|
assert_equal 0, @bib[entry].length
|
211
226
|
end
|
212
|
-
|
227
|
+
|
213
228
|
it 'supports query and additional block' do
|
214
229
|
assert_equal 1, @bib.q('@book') { |e| e.keywords.split(/,/).length > 1 }.length
|
215
230
|
end
|
216
|
-
|
231
|
+
|
217
232
|
it 'supports saving the bibliography to a file' do
|
218
233
|
tmp = Tempfile.new('bibtex')
|
219
234
|
tmp.close
|
220
235
|
@bib.save_to(tmp.path)
|
221
236
|
assert_equal @bib.length, BibTeX.open(tmp.path).length
|
222
237
|
end
|
223
|
-
|
238
|
+
|
224
239
|
describe '#query' do
|
225
|
-
|
240
|
+
|
226
241
|
it 'returns all elements when passed no arguments' do
|
227
242
|
@bib.query.length.must_be :==, 6
|
228
243
|
end
|
@@ -230,47 +245,47 @@ module BibTeX
|
|
230
245
|
it 'returns all elements when passed :all and an empty condition' do
|
231
246
|
@bib.query(:all, '').length.must_be :==, 6
|
232
247
|
end
|
233
|
-
|
248
|
+
|
234
249
|
it 'returns all entries when passed a * wildcard' do
|
235
250
|
@bib.query('@*').length.must_be :==, 5
|
236
251
|
end
|
237
|
-
|
252
|
+
|
238
253
|
end
|
239
|
-
|
254
|
+
|
240
255
|
describe 'given a filter' do
|
241
256
|
before do
|
242
257
|
@filter = Object
|
243
258
|
def @filter.apply (value); value.is_a?(::String) ? value.upcase : value; end
|
244
259
|
end
|
245
|
-
|
260
|
+
|
246
261
|
it 'supports arbitrary conversions' do
|
247
262
|
@bib.convert(@filter)
|
248
263
|
assert_equal 'RUBY, RAILS', @bib[:rails].keywords
|
249
264
|
end
|
250
|
-
|
265
|
+
|
251
266
|
it 'supports conditional arbitrary conversions' do
|
252
267
|
@bib.convert(@filter) { |e| e.key != 'rails' }
|
253
268
|
assert_equal 'ruby, rails', @bib[:rails].keywords
|
254
269
|
assert_equal 'RUBY', @bib[:flanagan2008].keywords
|
255
270
|
end
|
256
|
-
|
271
|
+
|
257
272
|
end
|
258
|
-
|
273
|
+
|
259
274
|
describe 'LaTeX filter' do
|
260
275
|
before do
|
261
276
|
@bib['rails'].keywords = 'r\\"uby'
|
262
277
|
end
|
263
|
-
|
278
|
+
|
264
279
|
it 'converts LaTeX umlauts' do
|
265
280
|
@bib.convert(:latex)['rails'].keywords.must_be :==, 'rüby'
|
266
281
|
end
|
267
|
-
|
282
|
+
|
268
283
|
end
|
269
|
-
|
284
|
+
|
270
285
|
describe 'BibTeXML export' do
|
271
286
|
before { @bibtexml = Tempfile.new('bibtexml') }
|
272
287
|
after { @bibtexml.unlink }
|
273
|
-
|
288
|
+
|
274
289
|
it 'supports exporting to BibTeXML' do
|
275
290
|
@bib.to_xml.write(@bibtexml, 2)
|
276
291
|
@bibtexml.rewind
|
@@ -286,10 +301,10 @@ module BibTeX
|
|
286
301
|
xml.root.namespace.must_be :==, 'http://bibtexml.sf.net/'
|
287
302
|
xml.root.get_elements('//bibtex:person').wont_be_empty
|
288
303
|
end
|
289
|
-
|
304
|
+
|
290
305
|
end
|
291
306
|
end
|
292
|
-
|
293
|
-
|
307
|
+
|
308
|
+
|
294
309
|
end
|
295
310
|
end
|
data/test/bibtex/test_entry.rb
CHANGED
@@ -23,12 +23,12 @@ module BibTeX
|
|
23
23
|
it 'has no cross-reference by default' do
|
24
24
|
assert_equal false, Entry.new.has_cross_reference?
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
it 'is not cross-referenced by default' do
|
28
28
|
assert_equal false, Entry.new.cross_referenced?
|
29
29
|
Entry.new.cross_referenced_by.must_be_empty
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
describe 'given a bibliography with cross referenced entries' do
|
33
33
|
before do
|
34
34
|
@bib = Bibliography.parse <<-END
|
@@ -37,7 +37,7 @@ module BibTeX
|
|
37
37
|
@incollection{b1, crossref = "b"}
|
38
38
|
END
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
describe '#has_cross_reference?' do
|
42
42
|
it 'returns true if the entry has a valid cross-reference' do
|
43
43
|
assert_equal true, @bib['a1'].has_cross_reference?
|
@@ -47,7 +47,7 @@ module BibTeX
|
|
47
47
|
assert_equal false, @bib['b1'].has_cross_reference?
|
48
48
|
end
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
describe '#cross_referenced?' do
|
52
52
|
it 'returns true if the entry is cross-referenced by another entry' do
|
53
53
|
assert_equal true, @bib['a'].cross_referenced?
|
@@ -56,23 +56,23 @@ module BibTeX
|
|
56
56
|
assert_equal false, @bib['a1'].cross_referenced?
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
describe '#cross_referenced_by' do
|
61
61
|
it 'returns a list of all entries that cross-reference this entry' do
|
62
62
|
@bib['a'].cross_referenced_by.must_include(@bib['a1'])
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
it 'returns an empty list if there are no cross-references to this entry' do
|
66
66
|
@bib['a1'].cross_referenced_by.must_be_empty
|
67
67
|
end
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
describe '#respond_to?' do
|
71
71
|
it 'takes into account the inherited attributes' do
|
72
72
|
@bib['a1'].respond_to?(:title)
|
73
73
|
end
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
describe 'resolve field values using array accessors #[]' do
|
77
77
|
describe 'when a "title" is set in the entry itself' do
|
78
78
|
before { @bib['a1'].title = 'A1' }
|
@@ -80,13 +80,13 @@ module BibTeX
|
|
80
80
|
@bib['a1'].title.must_be :==, 'A1'
|
81
81
|
end
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
describe 'when "title" is undefined for the entry but defined in the reference' do
|
85
85
|
it 'returns the referenced title' do
|
86
86
|
@bib['a1'].title.must_be :==, @bib['a'].title
|
87
87
|
end
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
describe 'when "booktitle" is undefined for the entry but defined in the reference' do
|
91
91
|
before { @bib['a'].booktitle = "A Booktitle" }
|
92
92
|
it 'returns the referenced booktitle' do
|
@@ -99,7 +99,7 @@ module BibTeX
|
|
99
99
|
@bib['a1'].booktitle.must_be :==, @bib['a'].title
|
100
100
|
end
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
it 'does not store referenced values permanently' do
|
104
104
|
refute_nil @bib['a1'].booktitle
|
105
105
|
assert_nil @bib['a1'].fields[:booktitle]
|
@@ -109,20 +109,20 @@ module BibTeX
|
|
109
109
|
it 'returns an empty list by default' do
|
110
110
|
Entry.new.inherited_fields.must_be_empty
|
111
111
|
end
|
112
|
-
|
112
|
+
|
113
113
|
it 'returns an empty list if this entry has no cross-reference' do
|
114
114
|
@bib['a'].inherited_fields.must_be_empty
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
it 'returns an empty list if this entry has a cross-reference but the reference does not exist in the bibliography' do
|
118
118
|
@bib['b1'].inherited_fields.must_be_empty
|
119
119
|
end
|
120
|
-
|
120
|
+
|
121
121
|
it 'returns a list of all fields not set in the field but in the reference' do
|
122
122
|
@bib['a1'].inherited_fields.must_be :==, [:booktitle, :editor, :title]
|
123
123
|
end
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
126
|
describe '#save_inherited_fields' do
|
127
127
|
it 'copies referenced values to the entry' do
|
128
128
|
@bib['a1'].title = 'a1'
|
@@ -132,15 +132,15 @@ module BibTeX
|
|
132
132
|
end
|
133
133
|
end
|
134
134
|
end
|
135
|
-
|
135
|
+
|
136
136
|
end
|
137
137
|
end
|
138
|
-
|
138
|
+
|
139
139
|
describe '#names' do
|
140
140
|
it 'returns an empty list by default' do
|
141
141
|
Entry.new.names.must_be :==, []
|
142
142
|
end
|
143
|
-
|
143
|
+
|
144
144
|
it 'returns the author (if set)' do
|
145
145
|
Entry.new(:author => 'A').names.must_be :==, %w{ A }
|
146
146
|
end
|
@@ -148,7 +148,7 @@ module BibTeX
|
|
148
148
|
it 'returns all authors (if set)' do
|
149
149
|
Entry.new(:author => 'A B and C D').parse_names.names.length.must_be :==, 2
|
150
150
|
end
|
151
|
-
|
151
|
+
|
152
152
|
it 'returns the editor (if set)' do
|
153
153
|
Entry.new(:editor => 'A').names.must_be :==, %w{ A }
|
154
154
|
end
|
@@ -156,14 +156,14 @@ module BibTeX
|
|
156
156
|
it 'returns the translator (if set)' do
|
157
157
|
Entry.new(:translator => 'A').names.must_be :==, %w{ A }
|
158
158
|
end
|
159
|
-
|
159
|
+
|
160
160
|
end
|
161
|
-
|
161
|
+
|
162
162
|
describe 'month conversion' do
|
163
163
|
before do
|
164
164
|
@entry = Entry.new
|
165
165
|
end
|
166
|
-
|
166
|
+
|
167
167
|
[[:jan,'January'], [:feb,'February'], [:sep,'September']].each do |m|
|
168
168
|
it 'should convert english months' do
|
169
169
|
@entry.month = m[1]
|
@@ -188,7 +188,41 @@ module BibTeX
|
|
188
188
|
assert_equal m[0], @entry.month.v
|
189
189
|
end
|
190
190
|
end
|
191
|
-
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
describe '#values_at' do
|
195
|
+
it 'returns an empty array by default' do
|
196
|
+
assert_equal [], Entry.new.values_at
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'returns an empty array when given no arguments' do
|
200
|
+
assert_equal [], Entry.new(:title => 'foo').values_at
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'returns a nil array if the passed in key is not set' do
|
204
|
+
assert_equal [nil], Entry.new.values_at(:title)
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'returns an array with the value of the passed in key' do
|
208
|
+
assert_equal ['x'], Entry.new(:title => 'x').values_at(:title)
|
209
|
+
assert_equal ['a', 'b'], Entry.new(:title => 'b', :year => 'a').values_at(:year, :title)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
describe '#digest' do
|
214
|
+
it 'returns an empty string by default' do
|
215
|
+
assert_equal '', Entry.new.digest
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'includes type and all defined fields' do
|
219
|
+
assert_equal 'book', Entry.new(:type => 'book').digest
|
220
|
+
assert_equal 'book|title:foo', Entry.new(:type => 'book', :title => 'foo').digest
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'accepts a filter' do
|
224
|
+
assert_equal 'book|year:2012', Entry.new(:type => 'book', :title => 'foo', :year => 2012).digest([:year])
|
225
|
+
end
|
192
226
|
end
|
193
227
|
|
194
228
|
describe 'given an entry' do
|
@@ -205,7 +239,7 @@ module BibTeX
|
|
205
239
|
e.parse_names
|
206
240
|
end
|
207
241
|
end
|
208
|
-
|
242
|
+
|
209
243
|
it 'supports renaming! of field attributes' do
|
210
244
|
@entry.rename!(:title => :foo)
|
211
245
|
refute @entry.has_field?(:title)
|
@@ -220,12 +254,11 @@ module BibTeX
|
|
220
254
|
|
221
255
|
assert e.has_field?(:foo)
|
222
256
|
refute e.has_field?(:title)
|
223
|
-
|
257
|
+
|
224
258
|
assert_equal 'Moby Dick', @entry[:title]
|
225
259
|
assert_equal 'Moby Dick', e[:foo]
|
226
260
|
end
|
227
261
|
|
228
|
-
|
229
262
|
it 'supports citeproc export' do
|
230
263
|
e = @entry.to_citeproc
|
231
264
|
assert_equal 'book', e['type']
|
@@ -235,13 +268,13 @@ module BibTeX
|
|
235
268
|
assert_equal 'Herman', e['author'][0]['given']
|
236
269
|
assert_equal 'Melville', e['author'][0]['family']
|
237
270
|
end
|
238
|
-
|
271
|
+
|
239
272
|
describe 'given a filter' do
|
240
273
|
before do
|
241
274
|
@filter = Object.new
|
242
275
|
def @filter.apply (value); value.is_a?(::String) ? value.upcase : value; end
|
243
276
|
end
|
244
|
-
|
277
|
+
|
245
278
|
it 'supports arbitrary conversion' do
|
246
279
|
e = @entry.convert(@filter)
|
247
280
|
assert_equal 'MOBY DICK', e.title
|
@@ -265,19 +298,19 @@ module BibTeX
|
|
265
298
|
assert_equal 'PENGUIN', e.publisher
|
266
299
|
assert_equal 'Penguin', @entry.publisher
|
267
300
|
end
|
268
|
-
|
301
|
+
|
269
302
|
end
|
270
|
-
|
303
|
+
|
271
304
|
describe 'LaTeX filter' do
|
272
305
|
before do
|
273
306
|
@entry.title = 'M\\"{o}by Dick'
|
274
307
|
end
|
275
|
-
|
308
|
+
|
276
309
|
describe '#convert' do
|
277
310
|
it 'converts LaTeX umlauts' do
|
278
311
|
@entry.convert(:latex).title.must_be :==, 'Möby Dick'
|
279
312
|
end
|
280
|
-
|
313
|
+
|
281
314
|
it 'does not change the original entry' do
|
282
315
|
e = @entry.convert(:latex)
|
283
316
|
e.wont_be :==, @entry
|
@@ -289,14 +322,14 @@ module BibTeX
|
|
289
322
|
it 'converts LaTeX umlauts' do
|
290
323
|
@entry.convert!(:latex).title.must_be :==, 'Möby Dick'
|
291
324
|
end
|
292
|
-
|
325
|
+
|
293
326
|
it 'changes the original entry in-place' do
|
294
327
|
e = @entry.convert!(:latex)
|
295
328
|
e.must_be :equal?, @entry
|
296
329
|
e.title.to_s.length.must_be :==, @entry.title.to_s.length
|
297
330
|
end
|
298
331
|
end
|
299
|
-
|
332
|
+
|
300
333
|
end
|
301
334
|
end
|
302
335
|
|
@@ -309,16 +342,16 @@ module BibTeX
|
|
309
342
|
e.parse_names
|
310
343
|
end
|
311
344
|
end
|
312
|
-
|
345
|
+
|
313
346
|
it 'should use non-dropping-particle by default' do
|
314
347
|
assert_equal 'van', @entry.to_citeproc['author'][0]['non-dropping-particle']
|
315
348
|
end
|
316
|
-
|
349
|
+
|
317
350
|
it 'should accept option to use non-dropping-particle' do
|
318
351
|
assert_equal 'van', @entry.to_citeproc(:particle => 'non-dropping-particle')['author'][0]['non-dropping-particle']
|
319
352
|
end
|
320
353
|
end
|
321
|
-
|
354
|
+
|
322
355
|
def test_simple
|
323
356
|
bib = BibTeX::Bibliography.open(Test.fixtures(:entry), :debug => false)
|
324
357
|
refute_nil(bib)
|
@@ -340,25 +373,25 @@ module BibTeX
|
|
340
373
|
assert_equal('Selected \\emph{Poetry} and `Tales\'', bib.data[0].title)
|
341
374
|
assert_equal('Tales and Sketches', bib.data[1].title)
|
342
375
|
end
|
343
|
-
|
376
|
+
|
344
377
|
def test_ghost_methods
|
345
378
|
bib = BibTeX::Bibliography.open(Test.fixtures(:entry), :debug => false)
|
346
379
|
|
347
380
|
assert_equal 'Poe, Edgar A.', bib[0].author.to_s
|
348
|
-
|
381
|
+
|
349
382
|
expected = 'Poe, Edgar Allen'
|
350
383
|
bib.data[0].author = expected
|
351
|
-
|
384
|
+
|
352
385
|
assert_equal expected, bib[0].author.to_s
|
353
386
|
end
|
354
|
-
|
355
|
-
def test_creation_simple
|
387
|
+
|
388
|
+
def test_creation_simple
|
356
389
|
entry = BibTeX::Entry.new
|
357
390
|
entry.type = :book
|
358
391
|
entry.key = :raven
|
359
392
|
entry.author = 'Poe, Edgar A.'
|
360
393
|
entry.title = 'The Raven'
|
361
|
-
|
394
|
+
|
362
395
|
assert_equal :book, entry.type
|
363
396
|
assert_equal 'raven', entry.key
|
364
397
|
assert_equal 'Poe, Edgar A.', entry.author
|
@@ -372,7 +405,7 @@ module BibTeX
|
|
372
405
|
:author => 'Poe, Edgar A.',
|
373
406
|
:title => 'The Raven'
|
374
407
|
})
|
375
|
-
|
408
|
+
|
376
409
|
assert_equal :book, entry.type
|
377
410
|
assert_equal 'raven', entry.key
|
378
411
|
assert_equal 'Poe, Edgar A.', entry.author
|
@@ -386,38 +419,38 @@ module BibTeX
|
|
386
419
|
e.author = 'Poe, Edgar A.'
|
387
420
|
e.title = 'The Raven'
|
388
421
|
end
|
389
|
-
|
422
|
+
|
390
423
|
assert_equal :book, entry.type
|
391
424
|
assert_equal 'raven', entry.key
|
392
425
|
assert_equal 'Poe, Edgar A.', entry.author
|
393
426
|
assert_equal 'The Raven', entry.title
|
394
427
|
end
|
395
|
-
|
428
|
+
|
396
429
|
def test_sorting
|
397
430
|
entries = []
|
398
431
|
entries << Entry.new({ :type => 'book', :key => 'raven3', :author => 'Poe, Edgar A.', :title => 'The Raven'})
|
399
432
|
entries << Entry.new({ :type => 'book', :key => 'raven2', :author => 'Poe, Edgar A.', :title => 'The Raven'})
|
400
433
|
entries << Entry.new({ :type => 'book', :key => 'raven1', :author => 'Poe, Edgar A.', :title => 'The Raven'})
|
401
434
|
entries << Entry.new({ :type => 'book', :key => 'raven1', :author => 'Poe, Edgar A.', :title => 'The Aven'})
|
402
|
-
|
435
|
+
|
403
436
|
entries.sort!
|
404
|
-
|
437
|
+
|
405
438
|
assert_equal ['raven1', 'raven1', 'raven2', 'raven3'], entries.map(&:key)
|
406
439
|
assert_equal ['The Aven', 'The Raven'], entries.map(&:title)[0,2]
|
407
440
|
|
408
441
|
end
|
409
|
-
|
442
|
+
|
410
443
|
describe 'default keys' do
|
411
444
|
before {
|
412
445
|
@e1 = Entry.new(:type => 'book', :author => 'Poe, Edgar A.', :title => 'The Raven', :editor => 'John Hopkins', :year => 1996)
|
413
446
|
@e2 = Entry.new(:type => 'book', :title => 'The Raven', :editor => 'John Hopkins', :year => 1996)
|
414
447
|
@e3 = Entry.new(:type => 'book', :author => 'Poe, Edgar A.', :title => 'The Raven', :editor => 'John Hopkins')
|
415
448
|
}
|
416
|
-
|
449
|
+
|
417
450
|
it 'should return "unknown-a" for an empty Entry' do
|
418
451
|
Entry.new.key.must_be :==, 'unknown-a'
|
419
452
|
end
|
420
|
-
|
453
|
+
|
421
454
|
it 'should return a key made up of author-year-a if all fields are present' do
|
422
455
|
@e1.key.must_be :==, 'poe1996a'
|
423
456
|
end
|
@@ -434,30 +467,30 @@ module BibTeX
|
|
434
467
|
@e3.key.must_be :==, 'poe-a'
|
435
468
|
end
|
436
469
|
end
|
437
|
-
|
470
|
+
|
438
471
|
describe 'when the entry is added to a Bibliography' do
|
439
472
|
before {
|
440
473
|
@e = Entry.new
|
441
474
|
@bib = Bibliography.new
|
442
475
|
}
|
443
|
-
|
476
|
+
|
444
477
|
it 'should register itself with its key' do
|
445
478
|
@bib << @e
|
446
479
|
@bib.entries.keys.must_include @e.key
|
447
480
|
end
|
448
|
-
|
481
|
+
|
449
482
|
describe "when there is already an element registered with the entry's key" do
|
450
483
|
before { @bib << Entry.new }
|
451
|
-
|
484
|
+
|
452
485
|
it "should find a suitable key" do
|
453
486
|
k = @e.key
|
454
487
|
@bib << @e
|
455
488
|
@bib.entries.keys.must_include @e.key
|
456
489
|
k.wont_be :==, @e.key
|
457
490
|
end
|
458
|
-
|
491
|
+
|
459
492
|
end
|
460
493
|
end
|
461
|
-
|
494
|
+
|
462
495
|
end
|
463
496
|
end
|