@@ -70,7 +70,7 @@ def test_indent(self):
7070"""
7171 self .assertEqual (result , expected )
7272
73- def test_align (self ):
73+ def test_align_bool (self ):
7474 bib_database = BibDatabase ()
7575 bib_database .entries = [{'ID' : 'abc123' ,
7676 'ENTRYTYPE' : 'book' ,
@@ -87,6 +87,22 @@ def test_align(self):
8787"""
8888 self .assertEqual (result , expected )
8989
90+ bib_database = BibDatabase ()
91+ bib_database .entries = [{'ID' : 'veryveryverylongID' ,
92+ 'ENTRYTYPE' : 'book' ,
93+ 'a' : 'test' ,
94+ 'bb' : 'longvalue' }]
95+ writer = BibTexWriter ()
96+ writer .align_values = True
97+ result = bibtexparser .dumps (bib_database , writer )
98+ expected = \
99+ """@book{veryveryverylongID,
100+ a = {test},
101+ bb = {longvalue}
102+ }
103+ """
104+ self .assertEqual (result , expected )
105+
90106 with open ('bibtexparser/tests/data/multiple_entries_and_comments.bib' ) as bibtex_file :
91107 bib_database = bibtexparser .load (bibtex_file )
92108 writer = BibTexWriter ()
@@ -121,6 +137,70 @@ def test_align(self):
121137"""
122138 self .assertEqual (result , expected )
123139
140+ def test_align_int (self ):
141+ bib_database = BibDatabase ()
142+ bib_database .entries = [{'ID' : 'abc123' ,
143+ 'ENTRYTYPE' : 'book' ,
144+ 'author' : 'test' ,
145+ 'thisisaverylongkey' : 'longvalue' }]
146+ # Negative value should have no effect
147+ writer = BibTexWriter ()
148+ writer .align_values = - 20
149+ result = bibtexparser .dumps (bib_database , writer )
150+ expected = \
151+ """@book{abc123,
152+ author = {test},
153+ thisisaverylongkey = {longvalue}
154+ }
155+ """
156+ self .assertEqual (result , expected )
157+
158+ # Value smaller than longest field name should only impact the "short" field names
159+ writer = BibTexWriter ()
160+ writer .align_values = 10
161+ result = bibtexparser .dumps (bib_database , writer )
162+ expected = \
163+ """@book{abc123,
164+ author = {test},
165+ thisisaverylongkey = {longvalue}
166+ }
167+ """
168+ self .assertEqual (result , expected )
169+
170+
171+ with open ('bibtexparser/tests/data/multiple_entries_and_comments.bib' ) as bibtex_file :
172+ bib_database = bibtexparser .load (bibtex_file )
173+ writer = BibTexWriter ()
174+ writer .contents = ['entries' ]
175+ writer .align_values = 15
176+ result = bibtexparser .dumps (bib_database , writer )
177+ expected = \
178+ """@book{Toto3000,
179+ author = {Toto, A and Titi, B},
180+ title = {A title}
181+ }
182+
183+ @article{Wigner1938,
184+ author = {Wigner, E.},
185+ doi = {10.1039/TF9383400029},
186+ issn = {0014-7672},
187+ journal = {Trans. Faraday Soc.},
188+ owner = {fr},
189+ pages = {29--41},
190+ publisher = {The Royal Society of Chemistry},
191+ title = {The transition state method},
192+ volume = {34},
193+ year = {1938}
194+ }
195+
196+ @book{Yablon2005,
197+ author = {Yablon, A.D.},
198+ publisher = {Springer},
199+ title = {Optical fiber fusion slicing},
200+ year = {2005}
201+ }
202+ """
203+ self .assertEqual (result , expected )
124204
125205 def test_entry_separator (self ):
126206 bib_database = BibDatabase ()
@@ -206,17 +286,17 @@ def test_align_multiline_values_with_align(self):
206286 result = bibtexparser .dumps (bib_database , writer )
207287 expected = \
208288"""@article{Cesar2013,
209- author = {Jean César},
210- title = {A mutline line title is very amazing. It should be
211- long enough to test multilines... with two lines or should we
212- even test three lines... What an amazing title.},
213- year = {2013},
214- journal = {Nice Journal},
215- abstract = {This is an abstract. This line should be long enough to test
216- multilines... and with a french érudit word},
217- comments = {A comment},
218- keyword = {keyword1, keyword2,
219- multiline-keyword1, multiline-keyword2}
289+ author = {Jean César},
290+ title = {A mutline line title is very amazing. It should be
291+ long enough to test multilines... with two lines or should we
292+ even test three lines... What an amazing title.},
293+ year = {2013},
294+ journal = {Nice Journal},
295+ abstract = {This is an abstract. This line should be long enough to test
296+ multilines... and with a french érudit word},
297+ comments = {A comment},
298+ keyword = {keyword1, keyword2,
299+ multiline-keyword1, multiline-keyword2}
220300}
221301"""
222302 self .assertEqual (result , expected )
@@ -331,17 +411,17 @@ def test_align_multiline_values_with_align_with_indent(self):
331411 result = bibtexparser .dumps (bib_database , writer )
332412 expected = \
333413"""@article{Cesar2013,
334- author = {Jean César},
335- title = {A mutline line title is very amazing. It should be
336- long enough to test multilines... with two lines or should we
337- even test three lines... What an amazing title.},
338- year = {2013},
339- journal = {Nice Journal},
340- abstract = {This is an abstract. This line should be long enough to test
341- multilines... and with a french érudit word},
342- comments = {A comment},
343- keyword = {keyword1, keyword2,
344- multiline-keyword1, multiline-keyword2}
414+ author = {Jean César},
415+ title = {A mutline line title is very amazing. It should be
416+ long enough to test multilines... with two lines or should we
417+ even test three lines... What an amazing title.},
418+ year = {2013},
419+ journal = {Nice Journal},
420+ abstract = {This is an abstract. This line should be long enough to test
421+ multilines... and with a french érudit word},
422+ comments = {A comment},
423+ keyword = {keyword1, keyword2,
424+ multiline-keyword1, multiline-keyword2}
345425}
346426"""
347427 self .assertEqual (result , expected )
0 commit comments