Skip to content

Commit

Permalink
BibConvert: re-fix formatting option WORDS
Browse files Browse the repository at this point in the history
* Amends previous fix to formatting option which caused
  some tests to fail.

* Adds regression test.
  • Loading branch information
jalavik authored and tiborsimko committed Mar 28, 2011
1 parent 56d46d5 commit 9f80dfe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
14 changes: 8 additions & 6 deletions modules/bibconvert/lib/bibconvert.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,17 +1005,19 @@ def FormatField(value, fn):
out = value

elif (fn == "WORDS"):
wordlist = [value]
par = set_par_defaults(par, ",")
max_num_words = int(par[0])
if (par[1] == "R"):
words = value.split(" ")
wordlist = words[:max_num_words]
words = value.split(" ")
try:
max_num_words = int(par[0])
except ValueError:
max_num_words = len(words)

if (par[1] == "L"):
words = value.split(" ")
words.reverse()
wordlist = words[:max_num_words]
wordlist.reverse()
else:
wordlist = words[:max_num_words]
out = " ".join(wordlist)

elif (fn == "MINL"):
Expand Down
6 changes: 6 additions & 0 deletions modules/bibconvert/lib/bibconvert_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ def test_words_right(self):
self.assertEqual("Sep",
bibconvert.FormatField(test_input, "WORDS(1,R)"))

def test_words_exceed_wordcount(self):
"""bibconvert - WORDS(2,R) when less then 2 words in value"""
test_input = "ab"
self.assertEqual(test_input,
bibconvert.FormatField(test_input, "WORDS(2,R)"))

class TestBCCL(unittest.TestCase):
"""Test bibconvert BCCL compliance"""

Expand Down

0 comments on commit 9f80dfe

Please sign in to comment.