mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Added function commaAndify to turn a list of strings into a proper English foo, bar, and baz string.
This commit is contained in:
parent
15ba96b4eb
commit
01eb6934ef
11
src/utils.py
11
src/utils.py
@ -259,4 +259,15 @@ def findBinaryInPath(s):
|
||||
break
|
||||
return cmdLine
|
||||
|
||||
def commaAndify(L):
|
||||
if len(L) == 0:
|
||||
return ''
|
||||
elif len(L) == 1:
|
||||
return L[0]
|
||||
elif len(L) == 2:
|
||||
return '%s and %s' % (L[0], L[1])
|
||||
else:
|
||||
L[-1] = 'and %s' % L[-1]
|
||||
return ', '.join(L)
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||
|
@ -128,8 +128,17 @@ class UtilsTest(unittest.TestCase):
|
||||
self.assertEqual(f('fooba/rba/z'), 'foorz')
|
||||
|
||||
def testFindBinaryInPath(self):
|
||||
self.assertEqual(None, utils.findBinaryInPath('asdfhjklasdfhjkl'))
|
||||
self.assertEqual('/bin/sh', utils.findBinaryInPath('sh'))
|
||||
if os.name == 'posix':
|
||||
self.assertEqual(None, utils.findBinaryInPath('asdfhjklasdfhjkl'))
|
||||
self.assertEqual('/bin/sh', utils.findBinaryInPath('sh'))
|
||||
|
||||
def testCommaAndify(self):
|
||||
L = ['foo']
|
||||
self.assertEqual(utils.commaAndify(L), 'foo')
|
||||
L.append('bar')
|
||||
self.assertEqual(utils.commaAndify(L), 'foo and bar')
|
||||
L.append('baz')
|
||||
self.assertEqual(utils.commaAndify(L), 'foo, bar, and baz')
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user