Revision: 1683837d6f2a
Author:   Pekka Klärck
Date:     Tue Jun 21 10:11:30 2011
Log: Moved VariableSplitter and its tests into own modules. Also whitespace.

Update issue 854
RF intro I was supposed to organize today was cancelled so I have some time to look at enhancing VariableSplitter to support internal curly braces better. At first moved VariableSplitter into its own module.
http://code.google.com/p/robotframework/source/detail?r=1683837d6f2a

Added:
 /src/robot/variables/variablesplitter.py
 /utest/variables/test_variablesplitter.py
Modified:
 /src/robot/variables/__init__.py
 /src/robot/variables/variables.py
 /utest/variables/test_variables.py

=======================================
--- /dev/null
+++ /src/robot/variables/variablesplitter.py    Tue Jun 21 10:11:30 2011
@@ -0,0 +1,122 @@
+#  Copyright 2008-2011 Nokia Siemens Networks Oyj
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+
+class VariableSplitter:
+
+    def __init__(self, string, identifiers):
+        self.identifier = None
+        self.base = None
+        self.index = None
+        self.start = -1
+        self.end = -1
+        self._identifiers = identifiers
+        self._may_have_internal_variables = False
+        if self._split(string):
+            self._finalize()
+
+    def get_replaced_base(self, variables):
+        if self._may_have_internal_variables:
+            return variables.replace_string(self.base)
+        return self.base
+
+    def _finalize(self):
+        self.identifier = self._variable_chars[0]
+        self.base = ''.join(self._variable_chars[2:-1])
+        self.end = self.start + len(self._variable_chars)
+        if self._index_chars and self._index_chars[-1] == ']':
+            self.index = ''.join(self._index_chars[1:-1])
+            self.end += len(self._index_chars)
+
+    def _split(self, string):
+        start_index, max_index = self._find_variable(string)
+        if start_index < 0:
+            return False
+        self.start = start_index
+        self._started_vars = 1
+        self._state_handler = self._variable_state_handler
+        self._variable_chars = [ string[start_index], '{' ]
+        self._index_chars = []
+        start_index += 2
+        for index, char in enumerate(string[start_index:]):
+            try:
+                self._state_handler(char)
+            except StopIteration:
+                break
+ if self._state_handler not in [ self._waiting_index_state_handler, + self._index_state_handler ] and start_index+index > max_index:
+                break
+        return True
+
+    def _find_variable(self, string):
+        max_index = string.rfind('}')
+        if max_index == -1:
+            return -1, -1
+        start_index = self._find_start_index(string, 1, max_index)
+        if start_index == -1:
+            return -1, -2
+        return start_index, max_index
+
+    def _find_start_index(self, string, start, end):
+        index = string.find('{', start, end) - 1
+        if index < 0:
+            return -1
+        elif self._start_index_is_ok(string, index):
+            return index
+        else:
+            return self._find_start_index(string, index+2, end)
+
+    def _start_index_is_ok(self, string, index):
+        if string[index] not in self._identifiers:
+            return False
+        backslash_count = 0
+        while index - backslash_count > 0:
+            if string[index - backslash_count - 1] == '\\':
+                backslash_count += 1
+            else:
+                break
+        return backslash_count % 2 == 0
+
+    def _variable_state_handler(self, char):
+        self._variable_chars.append(char)
+        if char == '}':
+            self._started_vars -= 1
+            if self._started_vars == 0:
+                if self._variable_chars[0] == '@':
+                    self._state_handler = self._waiting_index_state_handler
+                else:
+                    raise StopIteration
+        elif char in self._identifiers:
+ self._state_handler = self._internal_variable_start_state_handler
+
+    def _internal_variable_start_state_handler(self, char):
+        self._state_handler = self._variable_state_handler
+        if char == '{':
+            self._variable_chars.append(char)
+            self._started_vars += 1
+            self._may_have_internal_variables = True
+        else:
+            self._variable_state_handler(char)
+
+    def _waiting_index_state_handler(self, char):
+        if char == '[':
+            self._index_chars.append(char)
+            self._state_handler = self._index_state_handler
+        else:
+            raise StopIteration
+
+    def _index_state_handler(self, char):
+        self._index_chars.append(char)
+        if char == ']':
+            raise StopIteration
=======================================
--- /dev/null
+++ /utest/variables/test_variablesplitter.py   Tue Jun 21 10:11:30 2011
@@ -0,0 +1,138 @@
+import unittest
+
+from robot.variables import VariableSplitter
+from robot.utils.asserts import assert_equals
+
+
+class TestVariableSplitter(unittest.TestCase):
+
+    _identifiers = ['$','@','%','&','*']
+
+    def test_empty(self):
+        self._test('', None)
+
+    def test_no_vars(self):
+        for inp in ['hello world', '$hello', '{hello}', '$\\{hello}',
+                    '${hello', '$hello}' ]:
+            self._test(inp, None)
+
+    def test_backslashes(self):
+        for inp in ['\\', '\\\\', '\\\\\\\\\\',
+                    '\\hello\\\\world\\\\\\']:
+            self._test(inp, None)
+
+    def test_one_var(self):
+        self._test('${hello}', '${hello}', 0)
+        self._test('1 @{hello} more', '@{hello}', 2)
+        self._test('*{hi}}', '*{hi}', 0)
+        self._test('{%{{hi}}', '%{{hi}', 1)
+        self._test('-= ${} =-', '${}', 3)
+        # In this case splitter thinks there are internal but there aren't.
+ # Better check would probably spent more time than that is saved when
+        # variable base is processed again in this special case.
+        self._test('%{hi%{u}', '%{hi%{u}', 0, internal=True)
+
+    def test_multiple_vars(self):
+        self._test('${hello} ${world}', '${hello}', 0)
+        self._test('hi %{u}2 and @{u2} and also *{us3}', '%{u}', 3)
+        self._test('0123456789 %{1} and @{2', '%{1}', 11)
+
+    def test_escaped_var(self):
+        self._test('\\${hello}', None)
+        self._test('hi \\\\\\${hello} moi', None)
+
+    def test_not_escaped_var(self):
+        self._test('\\\\${hello}', '${hello}', 2)
+        self._test('\\hi \\\\\\\\\\\\${hello} moi', '${hello}',
+                   len('\\hi \\\\\\\\\\\\'))
+        self._test('\\ ${hello}', '${hello}', 2)
+        self._test('${hello}\\', '${hello}', 0)
+        self._test('\\ \\ ${hel\\lo}\\', '${hel\\lo}', 4)
+
+    def test_escaped_and_not_escaped_vars(self):
+        for inp, var, start in [
+                ('\\${esc} ${not}', '${not}', len('\\${esc} ')),
+                ('\\\\\\${esc} \\\\${not}', '${not}',
+                 len('\\\\\\${esc} \\\\')),
+ ('\\${esc}\\\\${not}${n2}', '${not}', len('\\${esc}\\\\')) ]:
+            self._test(inp, var, start)
+
+    def test_internal_vars(self):
+        for inp, var, start in [
+                ('${hello${hi}}', '${hello${hi}}', 0),
+                ('bef ${${hi}hello} aft', '${${hi}hello}', 4),
+ ('\\${not} ${hel${hi}lo} ', '${hel${hi}lo}', len('\\${not} ')),
+                ('${${hi}${hi}}\\', '${${hi}${hi}}', 0),
+                ('${${hi${hi}}} ${xx}', '${${hi${hi}}}', 0),
+                ('${xx} ${${hi${hi}}}', '${xx}', 0),
+                ('${\\${hi${hi}}}', '${\\${hi${hi}}}', 0),
+                ('\\${${hi${hi}}}', '${hi${hi}}', len('\\${')),
+ ('\\${\\${hi\\\\${hi}}}', '${hi}', len('\\${\\${hi\\\\')) ]:
+            internal = var.count('{') > 1
+            self._test(inp, var, start, internal=internal)
+
+    def test_index(self):
+        self._test('@{x}[0]', '@{x}', 0, '0')
+        self._test('.@{x}[42]..', '@{x}', 1, '42')
+        self._test('@{x}[${i}] ${xyz}', '@{x}', 0, '${i}')
+        self._test('@{x}[]', '@{x}', 0, '')
+        self._test('@{x}[inv]', '@{x}', 0, 'inv')
+        self._test('@{x}[0', '@{x}', 0, None)
+        self._test('@{x}}[0]', '@{x}', 0, None)
+        self._test('${x}[0]', '${x}', 0, None)
+        self._test('%{x}[0]', '%{x}', 0, None)
+        self._test('*{x}[0]', '*{x}', 0, None)
+        self._test('&{x}[0]', '&{x}', 0, None)
+
+    def test_custom_identifiers(self):
+        for inp, start in [ ('@{x}${y}', 4),
+                            ('%{x} ${y}', 5),
+                            ('*{x}567890${y}', 10),
+                            ('&{x}%{x}@{x}\\${x}${y}',
+                             len('&{x}%{x}@{x}\\${x}')) ]:
+            self._test(inp, '${y}', start, identifiers=['$'])
+
+    def test_identifier_as_variable_name(self):
+        for i in self._identifiers:
+            for count in 1,2,3,42:
+                var = '%s{%s}' % (i, i*count)
+                self._test(var, var)
+                self._test(var+'spam', var)
+                self._test('eggs'+var+'spam', var, start=4)
+                self._test(i+var+i, var, start=1)
+
+    def test_identifier_as_variable_name_with_internal_vars(self):
+        for i in self._identifiers:
+            for count in 1,2,3,42:
+                var = '%s{%s{%s}}' % (i, i*count, i)
+                self._test(var, var, internal=True)
+                self._test('eggs'+var+'spam', var, start=4, internal=True)
+                var = '%s{%s{%s}}' % (i, i*count, i*count)
+                self._test(var, var, internal=True)
+                self._test('eggs'+var+'spam', var, start=4, internal=True)
+
+    def _test(self, inp, variable, start=0, index=None, identifiers=None,
+              internal=False):
+        if variable is not None:
+            identifier = variable[0]
+            base = variable[2:-1]
+            end = start + len(variable)
+            if index is not None:
+                end += len(index) + 2
+        else:
+            identifier = base = None
+            start = end = -1
+        if not identifiers:
+            identifiers = self._identifiers
+        res = VariableSplitter(inp, identifiers)
+        assert_equals(res.base, base, "'%s' base" % inp)
+        assert_equals(res.start, start, "'%s' start" % inp)
+        assert_equals(res.end, end, "'%s' end" % inp)
+        assert_equals(res.identifier, identifier, "'%s' indentifier" % inp)
+        assert_equals(res.index, index, "'%s' index" % inp)
+        assert_equals(res._may_have_internal_variables, internal,
+                      "'%s' internal" % inp)
+
+
+if __name__ == '__main__':
+    unittest.main()
=======================================
--- /src/robot/variables/__init__.py    Fri Apr 15 14:27:57 2011
+++ /src/robot/variables/__init__.py    Tue Jun 21 10:11:30 2011
@@ -12,14 +12,14 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.

-
 import os
 import tempfile

 from robot import utils
 from robot.output import LOGGER

-from variables import Variables, VariableSplitter
+from variables import Variables
+from variablesplitter import VariableSplitter
 from isvar import is_var, is_scalar_var, is_list_var


=======================================
--- /src/robot/variables/variables.py   Wed Jun 15 15:46:57 2011
+++ /src/robot/variables/variables.py   Tue Jun 21 10:11:30 2011
@@ -27,6 +27,7 @@
 from robot.output import LOGGER

 from isvar import is_var, is_scalar_var
+from variablesplitter import VariableSplitter


 class Variables(utils.NormalizedDict):
@@ -333,112 +334,3 @@
             return True

     __contains__ = has_key
-
-
-class VariableSplitter:
-
-    def __init__(self, string, identifiers):
-        self.identifier = None
-        self.base = None
-        self.index = None
-        self.start = -1
-        self.end = -1
-        self._identifiers = identifiers
-        self._may_have_internal_variables = False
-        if self._split(string):
-            self._finalize()
-
-    def get_replaced_base(self, variables):
-        if self._may_have_internal_variables:
-            return variables.replace_string(self.base)
-        return self.base
-
-    def _finalize(self):
-        self.identifier = self._variable_chars[0]
-        self.base = ''.join(self._variable_chars[2:-1])
-        self.end = self.start + len(self._variable_chars)
-        if self._index_chars and self._index_chars[-1] == ']':
-            self.index = ''.join(self._index_chars[1:-1])
-            self.end += len(self._index_chars)
-
-    def _split(self, string):
-        start_index, max_index = self._find_variable(string)
-        if start_index < 0:
-            return False
-        self.start = start_index
-        self._started_vars = 1
-        self._state_handler = self._variable_state_handler
-        self._variable_chars = [ string[start_index], '{' ]
-        self._index_chars = []
-        start_index += 2
-        for index, char in enumerate(string[start_index:]):
-            try:
-                self._state_handler(char)
-            except StopIteration:
-                break
- if self._state_handler not in [ self._waiting_index_state_handler, - self._index_state_handler ] and start_index+index > max_index:
-                break
-        return True
-
-    def _find_variable(self, string):
-        max_index = string.rfind('}')
-        if max_index == -1:
-            return -1, -1
-        start_index = self._find_start_index(string, 1, max_index)
-        if start_index == -1:
-            return -1, -2
-        return start_index, max_index
-
-    def _find_start_index(self, string, start, end):
-        index = string.find('{', start, end) - 1
-        if index < 0:
-            return -1
-        elif self._start_index_is_ok(string, index):
-            return index
-        else:
-            return self._find_start_index(string, index+2, end)
-
-    def _start_index_is_ok(self, string, index):
-        if string[index] not in self._identifiers:
-            return False
-        backslash_count = 0
-        while index - backslash_count > 0:
-            if string[index - backslash_count - 1] == '\\':
-                backslash_count += 1
-            else:
-                break
-        return backslash_count % 2 == 0
-
-    def _variable_state_handler(self, char):
-        self._variable_chars.append(char)
-        if char == '}':
-            self._started_vars -= 1
-            if self._started_vars == 0:
-                if self._variable_chars[0] == '@':
-                    self._state_handler = self._waiting_index_state_handler
-                else:
-                    raise StopIteration
-        elif char in self._identifiers:
- self._state_handler = self._internal_variable_start_state_handler
-
-    def _internal_variable_start_state_handler(self, char):
-        self._state_handler = self._variable_state_handler
-        if char == '{':
-            self._variable_chars.append(char)
-            self._started_vars += 1
-            self._may_have_internal_variables = True
-        else:
-            self._variable_state_handler(char)
-
-    def _waiting_index_state_handler(self, char):
-        if char == '[':
-            self._index_chars.append(char)
-            self._state_handler = self._index_state_handler
-        else:
-            raise StopIteration
-
-    def _index_state_handler(self, char):
-        self._index_chars.append(char)
-        if char == ']':
-            raise StopIteration
=======================================
--- /utest/variables/test_variables.py  Thu Sep 23 05:58:15 2010
+++ /utest/variables/test_variables.py  Tue Jun 21 10:11:30 2011
@@ -1,6 +1,6 @@
 import unittest
 import sys
-
+
 from robot.variables import variables, is_list_var, is_scalar_var, is_var
 from robot.errors import *
 from robot import utils
@@ -24,31 +24,31 @@
         return '(%s, %s)' % (self.a, self.b)
     __repr__ = __str__

-if utils.is_jython:
-    import JavaObject
+if utils.is_jython:
+    import JavaObject



 class TestIsMethods(unittest.TestCase):
-
+
     def test_is_var(self):
         for ok in SCALARS + LISTS:
             assert is_var(ok)
         for nok in NOKS:
             assert not is_var(nok)
-
+
     def test_is_scalar_var(self):
         for ok in SCALARS:
             assert is_scalar_var(ok)
         for nok in LISTS + NOKS:
             assert not is_scalar_var(nok)
-
+
     def test_is_list_var(self):
         for ok in LISTS:
             assert is_list_var(ok)
         for nok in SCALARS + NOKS:
             assert not is_list_var(nok)
-
+

 class TestVariables(unittest.TestCase):

@@ -98,7 +98,7 @@

     def test_set_list(self):
         for var in LISTS:
-            for value in [ [], [''], ['str'], [10], ['hi','u'], ['hi',2],
+            for value in [ [], [''], ['str'], [10], ['hi','u'], ['hi',2],
                            [{'a':1,'b':2}, self, None] ]:
                 self.varz[var] = value
                 assert_equals(self.varz[var], value)
@@ -163,7 +163,7 @@
         self.varz['${n}'] = None
         assert_equal(self.varz.replace_scalar('${d}'), {'a':1,'b':2})
         assert_equal(self.varz.replace_scalar('${n}'), None)
-
+
     def test_replace_non_strings_inside_string(self):
         class Example:
             def __str__(self):
@@ -177,22 +177,22 @@
         self.varz['@{L}'] = ['v0','v1','v3']
         for inv in [ '@{L}[3]', '@{NON}[0]', '@{L[2]}' ]:
             self.assertRaises(DataError, self.varz.replace_list, [inv])
-
+
     def test_replace_non_existing_list(self):
self.assertRaises(DataError, self.varz.replace_list, ['${nonexisting}'])

     def test_replace_non_existing_scalar(self):
self.assertRaises(DataError, self.varz.replace_scalar, '${nonexisting}')
-
+
     def test_replace_non_existing_string(self):
self.assertRaises(DataError, self.varz.replace_string, '${nonexisting}')
-
+
     def test_replace_escaped(self):
         self.varz['${foo}'] = 'bar'
         for inp, exp in [ (r'\${foo}', r'${foo}'),
                           (r'\\${foo}', r'\bar'),
                           (r'\\\${foo}', r'\${foo}'),
-                          (r'\\\\${foo}', r'\\bar'),
+                          (r'\\\\${foo}', r'\\bar'),
                           (r'\\\\\${foo}', r'\\${foo}') ]:
             assert_equals(self.varz.replace_scalar(inp), exp)

@@ -202,7 +202,7 @@
assert_equals(self.varz['${test}'], '${exists} & ${does_not_exist}')
         self.varz['@{test}'] = ['${exists}', '&', '${does_not_exist}']
assert_equals(self.varz['@{test}'], '${exists} & ${does_not_exist}'.split())
-
+
     def test_variable_as_object(self):
         obj = PythonObject('a', 1)
         self.varz['${obj}'] = obj
@@ -210,7 +210,7 @@
         expected = ['Some text here %s and %s there' % (obj,obj)]
actual = self.varz.replace_list(['Some text here ${obj} and ${obj} there'])
         assert_equals(actual, expected)
-
+
     def test_extended_variables(self):
# Extended variables are vars like ${obj.name} when we have var ${obj}
         obj = PythonObject('a', [1,2,3])
@@ -247,11 +247,11 @@
         assert_equals(self.varz.replace_scalar('${my${name}}'), 'value')
         self.varz['${whos name}'] = 'my'
assert_equals(self.varz.replace_scalar('${${whos name} ${name}}'), 'value') - assert_equals(self.varz.replace_scalar('${${whos${name}}${name}}'), 'value') + assert_equals(self.varz.replace_scalar('${${whos${name}}${name}}'), 'value')
         self.varz['${my name}'] = [1,2,3]
assert_equals(self.varz.replace_scalar('${${whos${name}}${name}}'), [1,2,3]) assert_equals(self.varz.replace_scalar('- ${${whos${name}}${name}} -'), '- [1, 2, 3] -')
-
+
     def test_math_with_internal_vars(self):
         assert_equals(self.varz.replace_scalar('${${1}+${2}}'), 3)
         assert_equals(self.varz.replace_scalar('${${1}-${2}}'), -1)
@@ -283,151 +283,20 @@
         copy = varz.copy()
         assert_equals(copy['${foo}'], 'bar')
         assert_equals(copy._identifiers, ['$'])
-
+
     if utils.is_jython:
-
+
         def test_variable_as_object_in_java(self):
             obj = JavaObject('hello')
-            self.varz['${obj}'] = obj
+            self.varz['${obj}'] = obj
             assert_equals(self.varz['${obj}'], obj)
assert_equals(self.varz.replace_scalar('${obj} world'), 'hello world')
-
+
         def test_extended_variables_in_java(self):
             obj = JavaObject('my name')
             self.varz['${obj}'] = obj
assert_equals(self.varz.replace_list(['${obj.name}']), ['my name'])


-
-class TestVariableSplitter(unittest.TestCase):
-
-    _identifiers = ['$','@','%','&','*']
-
-    def test_empty(self):
-        self._test('', None)
-
-    def test_no_vars(self):
-        for inp in ['hello world', '$hello', '{hello}', '$\\{hello}',
-                    '${hello', '$hello}' ]:
-            self._test(inp, None)
-
-    def test_backslashes(self):
-        for inp in ['\\', '\\\\', '\\\\\\\\\\',
-                    '\\hello\\\\world\\\\\\']:
-            self._test(inp, None)
-
-    def test_one_var(self):
-        self._test('${hello}', '${hello}', 0)
-        self._test('1 @{hello} more', '@{hello}', 2)
-        self._test('*{hi}}', '*{hi}', 0)
-        self._test('{%{{hi}}', '%{{hi}', 1)
-        self._test('-= ${} =-', '${}', 3)
-        # In this case splitter thinks there are internal but there aren't.
- # Better check would probably spent more time than that is saved when
-        # variable base is processed again in this special case.
-        self._test('%{hi%{u}', '%{hi%{u}', 0, internal=True)
-
-    def test_multiple_vars(self):
-        self._test('${hello} ${world}', '${hello}', 0)
-        self._test('hi %{u}2 and @{u2} and also *{us3}', '%{u}', 3)
-        self._test('0123456789 %{1} and @{2', '%{1}', 11)
-
-    def test_escaped_var(self):
-        self._test('\\${hello}', None)
-        self._test('hi \\\\\\${hello} moi', None)
-
-    def test_not_escaped_var(self):
-        self._test('\\\\${hello}', '${hello}', 2)
-        self._test('\\hi \\\\\\\\\\\\${hello} moi', '${hello}',
-                   len('\\hi \\\\\\\\\\\\'))
-        self._test('\\ ${hello}', '${hello}', 2)
-        self._test('${hello}\\', '${hello}', 0)
-        self._test('\\ \\ ${hel\\lo}\\', '${hel\\lo}', 4)
-
-    def test_escaped_and_not_escaped_vars(self):
-        for inp, var, start in [
-                ('\\${esc} ${not}', '${not}', len('\\${esc} ')),
-                ('\\\\\\${esc} \\\\${not}', '${not}',
-                 len('\\\\\\${esc} \\\\')),
- ('\\${esc}\\\\${not}${n2}', '${not}', len('\\${esc}\\\\')) ]:
-            self._test(inp, var, start)
-
-    def test_internal_vars(self):
-        for inp, var, start in [
-                ('${hello${hi}}', '${hello${hi}}', 0),
-                ('bef ${${hi}hello} aft', '${${hi}hello}', 4),
- ('\\${not} ${hel${hi}lo} ', '${hel${hi}lo}', len('\\${not} ')),
-                ('${${hi}${hi}}\\', '${${hi}${hi}}', 0),
-                ('${${hi${hi}}} ${xx}', '${${hi${hi}}}', 0),
-                ('${xx} ${${hi${hi}}}', '${xx}', 0),
-                ('${\\${hi${hi}}}', '${\\${hi${hi}}}', 0),
-                ('\\${${hi${hi}}}', '${hi${hi}}', len('\\${')),
- ('\\${\\${hi\\\\${hi}}}', '${hi}', len('\\${\\${hi\\\\')) ]:
-            internal = var.count('{') > 1
-            self._test(inp, var, start, internal=internal)
-
-    def test_index(self):
-        self._test('@{x}[0]', '@{x}', 0, '0')
-        self._test('.@{x}[42]..', '@{x}', 1, '42')
-        self._test('@{x}[${i}] ${xyz}', '@{x}', 0, '${i}')
-        self._test('@{x}[]', '@{x}', 0, '')
-        self._test('@{x}[inv]', '@{x}', 0, 'inv')
-        self._test('@{x}[0', '@{x}', 0, None)
-        self._test('@{x}}[0]', '@{x}', 0, None)
-        self._test('${x}[0]', '${x}', 0, None)
-        self._test('%{x}[0]', '%{x}', 0, None)
-        self._test('*{x}[0]', '*{x}', 0, None)
-        self._test('&{x}[0]', '&{x}', 0, None)
-
-    def test_custom_identifiers(self):
-        for inp, start in [ ('@{x}${y}', 4),
-                            ('%{x} ${y}', 5),
-                            ('*{x}567890${y}', 10),
-                            ('&{x}%{x}@{x}\\${x}${y}',
-                             len('&{x}%{x}@{x}\\${x}')) ]:
-            self._test(inp, '${y}', start, identifiers=['$'])
-
-    def test_identifier_as_variable_name(self):
-        for i in self._identifiers:
-            for count in 1,2,3,42:
-                var = '%s{%s}' % (i, i*count)
-                self._test(var, var)
-                self._test(var+'spam', var)
-                self._test('eggs'+var+'spam', var, start=4)
-                self._test(i+var+i, var, start=1)
-
-    def test_identifier_as_variable_name_with_internal_vars(self):
-        for i in self._identifiers:
-            for count in 1,2,3,42:
-                var = '%s{%s{%s}}' % (i, i*count, i)
-                self._test(var, var, internal=True)
-                self._test('eggs'+var+'spam', var, start=4, internal=True)
-                var = '%s{%s{%s}}' % (i, i*count, i*count)
-                self._test(var, var, internal=True)
-                self._test('eggs'+var+'spam', var, start=4, internal=True)
-
-    def _test(self, inp, variable, start=0, index=None, identifiers=None,
-              internal=False):
-        if variable is not None:
-            identifier = variable[0]
-            base = variable[2:-1]
-            end = start + len(variable)
-            if index is not None:
-                end += len(index) + 2
-        else:
-            identifier = base = None
-            start = end = -1
-        if not identifiers:
-            identifiers = self._identifiers
-        res = variables.VariableSplitter(inp, identifiers)
-        assert_equals(res.base, base, "'%s' base" % inp)
-        assert_equals(res.start, start, "'%s' start" % inp)
-        assert_equals(res.end, end, "'%s' end" % inp)
-        assert_equals(res.identifier, identifier, "'%s' indentifier" % inp)
-        assert_equals(res.index, index, "'%s' index" % inp)
-        assert_equals(res._may_have_internal_variables, internal,
-                      "'%s' internal" % inp)
-
-
 if __name__ == '__main__':
     unittest.main()

Reply via email to