Changeset 150


Ignore:
Timestamp:
21-03-07 00:30:25 (6 years ago)
Author:
thomas
Message:
  • moap/test/test_util_ctags.py (TestTag?.testRepr, TestTag?.testParse, TestCTags.testGetLastTwo, TestCTags.testGetLastTag, TestCTagsFromString, TestCTagsFromString.testFromEmptyString, TestCTagsFromString.testFromString, TestCTagsFromString.testFromWrongString):
  • moap/util/ctags.py (CTags.getTags): Increase coverage to 100%. Fix small bugs exposed by adding tests to increase coverage.
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r149 r150  
     12007-03-21  Thomas Vander Stichele  <thomas at apestaart dot org> 
     2 
     3        * moap/test/test_util_ctags.py (TestTag.testRepr, TestTag.testParse, 
     4          TestCTags.testGetLastTwo, TestCTags.testGetLastTag, 
     5          TestCTagsFromString, TestCTagsFromString.testFromEmptyString, 
     6          TestCTagsFromString.testFromString, 
     7          TestCTagsFromString.testFromWrongString): 
     8        * moap/util/ctags.py (CTags.getTags): 
     9          Increase coverage to 100%. 
     10          Fix small bugs exposed by adding tests to increase coverage. 
     11 
    1122007-03-21  Thomas Vander Stichele  <thomas at apestaart dot org> 
    213 
  • trunk/moap/test/test_util_ctags.py

    r137 r150  
    1111    def setUp(self): 
    1212        self.tag = ctags.Tag() 
     13 
     14    def testRepr(self): 
     15        self.failUnless(repr(self.tag)) 
    1316 
    1417    def testParse(self): 
     
    5659        self.assertEquals(tags[0].name, 'detect') 
    5760 
     61    def testGetLastTwo(self): 
     62        # update starts on 106 
     63        tags = self.ctags.getTags('moap/vcs/cvs.py', 105, 1) 
     64        self.assertEquals(len(tags), 2) 
     65        self.assertEquals(tags[0].name, 'diff') 
     66        self.assertEquals(tags[1].name, 'update') 
     67 
    5868    def testGetLastTag(self): 
    59         tags = self.ctags.getTags('moap/vcs/cvs.py', 107, 0) 
     69        tags = self.ctags.getTags('moap/vcs/cvs.py', 106, 0) 
    6070        self.assertEquals(len(tags), 1) 
    6171        self.assertEquals(tags[0].name, 'update') 
     72 
     73class TestCTagsFromString(unittest.TestCase): 
     74    def testFromEmptyString(self): 
     75        self.ctags = ctags.CTags() 
     76        self.ctags.addString('') 
     77 
     78    def testFromString(self): 
     79        self.ctags = ctags.CTags() 
     80        self.ctags.addString('!_TAG_') 
     81 
     82    def testFromWrongString(self): 
     83        self.ctags = ctags.CTags() 
     84        self.assertRaises(KeyError, self.ctags.addString, 'wrongtype') 
  • trunk/moap/util/ctags.py

    r147 r150  
    8787        starts.sort() 
    8888        i = 0 
    89         # look for first tag beyond the line number 
    90         while tags[starts[i]].line < line: 
     89        # look for the tag right before the given line number 
     90        while tags[starts[i]].line <= line: 
    9191            i += 1 
    9292            if i == len(starts): 
    9393                # line number is past the last tag, so we only return 
    9494                # the last tag 
     95                self.debug('Returning only tag starting on %d' % starts[-1]) 
    9596                return [tags[starts[-1]], ] 
    9697 
    97         # go back one if we are not exactly on a tag start line 
    98         if tags[starts[i]].line > line: 
    99             i -= 1 
     98        # now i points to a tag on or beyond the given line number, so go back 
     99        # one 
     100        i -= 1 
    100101             
    101102        if i >= 0: 
    102             # there is in fact a tag started before the given line 
     103            # there is in fact a tag started before the given line, so append it 
     104            self.debug('appending tag starting on line %d' % starts[i]) 
    103105            ret.append(tags[starts[i]]) 
     106 
     107        # now we go back to the first tag starting on or past the given line 
     108        # number 
    104109        i += 1 
    105          
     110 
    106111        # now find all tags in the given range and append 
    107         while tags[starts[i]].line < line + count: 
     112        # it is possible we are already past the end of starts 
     113        while count and tags[starts[i]].line <= line + count: 
     114            self.debug('appending tag starting on line %d' % starts[i]) 
    108115            ret.append(tags[starts[i]]) 
    109116            i += 1 
     
    111118                break 
    112119 
     120        self.debug('returning %d tags' % len(ret)) 
    113121        return ret 
Note: See TracChangeset for help on using the changeset viewer.