Beispiel #1
0
    def testGetCommandsByPos_in_03 (self):
        text = u'(:command:)'
        pos = 1

        result = getCommandsByPos (text, pos)
        self.assertEqual (len (result), 1)
        self.assertEqual (result[0].groupdict()['name'], u'command')
Beispiel #2
0
    def testGetCommandsByPos_nested_01 (self):
        text = u'(:command:)(:comamnd2:)(:command2end:)(:commandend:)'
        pos = 1

        result = getCommandsByPos (text, pos)
        self.assertEqual (len (result), 1)
        self.assertEqual (result[0].groupdict()['name'], u'command')
Beispiel #3
0
    def testGetCommandsByPos_nested_03(self):
        text = '(:command:)(:command2:)(:command2end:)(:commandend:)'
        pos = 25

        result = getCommandsByPos(text, pos)
        self.assertEqual(len(result), 2)
        self.assertEqual(result[0].groupdict()['name'], 'command')
        self.assertEqual(result[1].groupdict()['name'], 'command2')
Beispiel #4
0
    def testGetCommandsByPos_nested_03(self):
        text = '(:command:)(:command2:)(:command2end:)(:commandend:)'
        pos = 25

        result = getCommandsByPos(text, pos)
        self.assertEqual(len(result), 2)
        self.assertEqual(result[0].groupdict()['name'], 'command')
        self.assertEqual(result[1].groupdict()['name'], 'command2')
Beispiel #5
0
def getTableByPos(text, position):
    """
    Return suffix for command name for most nested (:tableNN:) command in the position
    """
    regex = re.compile(r'table(?P<suffix>\d*)$', re.UNICODE)
    matches = getCommandsByPos(text, position)
    matches.reverse()

    for match in matches:
        name = match.groupdict()['name']
        tableMatch = regex.match(name)
        if tableMatch:
            return tableMatch.groupdict()['suffix']

    return None
Beispiel #6
0
def getTableByPos(text, position):
    """
    Return suffix for command name for most nested (:tableNN:) command in the position
    """
    regex = re.compile(r'table(?P<suffix>\d*)$')
    matches = getCommandsByPos(text, position)
    matches.reverse()

    for match in matches:
        name = match.groupdict()['name']
        tableMatch = regex.match(name)
        if tableMatch:
            return tableMatch.groupdict()['suffix']

    return None
Beispiel #7
0
    def testGetCommandsByPos_empty (self):
        text = u''
        pos = 0

        result = getCommandsByPos (text, pos)
        self.assertEqual (result, [])
Beispiel #8
0
    def testGetCommandsByPos_in_04 (self):
        text = u'(:command2:)(:command:)(:commandend:)'
        pos = 12

        result = getCommandsByPos (text, pos)
        self.assertEqual (len (result), 0)
Beispiel #9
0
    def testGetCommandsByPos_out_02 (self):
        text = u'(:command:)(:commandend:)'
        pos = 25

        result = getCommandsByPos (text, pos)
        self.assertEqual (result, [])