mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-08 20:19: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:
|
||||
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 replacer(m):
|
||||
(braced, unbraced) = m.groups()
|
||||
|
@ -183,6 +183,22 @@ class UtilsTest(SupyTestCase):
|
||||
f = utils.perlReToReplacer('s/\b(\w+)\b/\1./g')
|
||||
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):
|
||||
if os.name == 'posix':
|
||||
self.assertEqual(None, utils.findBinaryInPath('asdfhjklasdfhjkl'))
|
||||
|
Loading…
Reference in New Issue
Block a user