1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
from nose.tools import eq_
import inflect
def test_join():
p = inflect.engine()
# Three words...
words = "apple banana carrot".split()
eq_(p.join(words),
"apple, banana, and carrot", msg='plain 3 words')
eq_(p.join(words, final_sep=''),
"apple, banana and carrot", msg='3 words, no final sep')
eq_(p.join(words, final_sep='...'),
"apple, banana... and carrot", msg='3 words, different final sep')
eq_(p.join(words, final_sep='...', conj=''),
"apple, banana... carrot", msg='-->%s != %s<-- 3 words, different final sep, no conjunction' %
(p.join(words, final_sep='...', conj=''), "apple, banana... carrot"))
eq_(p.join(words, conj='or'),
"apple, banana, or carrot", msg='%s != %s 3 words, different conjunction' % (p.join(words, conj='or'),
"apple, banana, or carrot"))
# Three words with semicolons...
words = ('apple,fuji', 'banana', 'carrot')
eq_(p.join(words),
"apple,fuji; banana; and carrot",
msg='%s != %s<-- comma-inclusive 3 words' % (p.join(words), "apple,fuji, banana; and carrot"))
eq_(p.join(words, final_sep=''),
"apple,fuji; banana and carrot", msg='join(%s) == "%s" != "%s"' % (words, p.join(words, final_sep=''),
"apple,fuji) banana and carrot"))
eq_(p.join(words, final_sep='...'),
"apple,fuji; banana... and carrot", msg='comma-inclusive 3 words, different final sep')
eq_(p.join(words, final_sep='...', conj=''),
"apple,fuji; banana... carrot", msg='comma-inclusive 3 words, different final sep, no conjunction')
eq_(p.join(words, conj='or'),
"apple,fuji; banana; or carrot", msg='comma-inclusive 3 words, different conjunction')
# Two words...
words = ('apple', 'carrot')
eq_(p.join(words),
"apple and carrot", msg='plain 2 words')
eq_(p.join(words, final_sep=''),
"apple and carrot", msg='2 words, no final sep')
eq_(p.join(words, final_sep='...'),
"apple and carrot", msg='2 words, different final sep')
eq_(p.join(words, final_sep='...', conj=''),
"apple carrot", msg="join(%s, final_sep='...', conj='') == %s != %s" % (
words, p.join(words, final_sep='...', conj=''), 'apple carrot'))
eq_(p.join(words, final_sep='...', conj='', conj_spaced=False),
"applecarrot", msg="join(%s, final_sep='...', conj='') == %s != %s" % (
words, p.join(words, final_sep='...', conj=''), 'applecarrot'))
eq_(p.join(words, conj='or'),
"apple or carrot", msg='2 words, different conjunction')
# One word...
words = ['carrot']
eq_(p.join(words),
"carrot", msg='plain 1 word')
eq_(p.join(words, final_sep=''),
"carrot", msg='1 word, no final sep')
eq_(p.join(words, final_sep='...'),
"carrot", msg='1 word, different final sep')
eq_(p.join(words, final_sep='...', conj=''),
"carrot", msg='1 word, different final sep, no conjunction')
eq_(p.join(words, conj='or'),
"carrot", msg='1 word, different conjunction')
|