mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Only do real variable names.
This commit is contained in:
parent
8a9ca0bb06
commit
0f1842b18d
@ -262,7 +262,7 @@ def perlReToReplacer(s):
|
|||||||
else:
|
else:
|
||||||
return lambda s: r.sub(replace, s, 1)
|
return lambda s: r.sub(replace, s, 1)
|
||||||
|
|
||||||
_perlVarSubstituteRe = re.compile(r'\$\{([^}]+)\}|\$(\S+)')
|
_perlVarSubstituteRe = re.compile(r'\$\{([^}]+)\}|\$([a-zA-Z][a-zA-Z0-9]*)')
|
||||||
def perlVariableSubstitute(vars, text):
|
def perlVariableSubstitute(vars, text):
|
||||||
def replacer(m):
|
def replacer(m):
|
||||||
(braced, unbraced) = m.groups()
|
(braced, unbraced) = m.groups()
|
||||||
|
@ -183,6 +183,22 @@ class UtilsTest(SupyTestCase):
|
|||||||
f = utils.perlReToReplacer('s/\b(\w+)\b/\1./g')
|
f = utils.perlReToReplacer('s/\b(\w+)\b/\1./g')
|
||||||
self.assertEqual(f('foo bar baz'), 'foo. bar. baz.')
|
self.assertEqual(f('foo bar baz'), 'foo. bar. baz.')
|
||||||
|
|
||||||
|
def testPerlVariableSubstitute(self):
|
||||||
|
f = utils.perlVariableSubstitute
|
||||||
|
vars = {'foo': 'bar', 'b a z': 'baz', 'b': 'c', 'i': 100,
|
||||||
|
'f': lambda: 'called'}
|
||||||
|
self.assertEqual(f(vars, '$foo'), 'bar')
|
||||||
|
self.assertEqual(f(vars, '${foo}'), 'bar')
|
||||||
|
self.assertEqual(f(vars, '$b'), 'c')
|
||||||
|
self.assertEqual(f(vars, '${b}'), 'c')
|
||||||
|
self.assertEqual(f(vars, '$i'), '100')
|
||||||
|
self.assertEqual(f(vars, '${i}'), '100')
|
||||||
|
self.assertEqual(f(vars, '$f'), 'called')
|
||||||
|
self.assertEqual(f(vars, '${f}'), 'called')
|
||||||
|
self.assertEqual(f(vars, '${b a z}'), 'baz')
|
||||||
|
self.assertEqual(f(vars, '$b:$i'), 'c:100')
|
||||||
|
|
||||||
|
|
||||||
def testFindBinaryInPath(self):
|
def testFindBinaryInPath(self):
|
||||||
if os.name == 'posix':
|
if os.name == 'posix':
|
||||||
self.assertEqual(None, utils.findBinaryInPath('asdfhjklasdfhjkl'))
|
self.assertEqual(None, utils.findBinaryInPath('asdfhjklasdfhjkl'))
|
||||||
|
Loading…
Reference in New Issue
Block a user