source: trunk/moap/test/test_util_ctags.py @ 336

Revision 336, 3.2 KB checked in by thomas, 5 years ago (diff)
  • moap/test/test_util_ctags.py:
  • moap/util/ctags.py: Allow spaces in the first column of a ctags file. Fixes #281.
RevLine 
[129]1# -*- Mode: Python; test-case-name: moap.test.test_doap_doap -*-
2# vi:si:et:sw=4:sts=4:ts=4
3
4import os
5
6from common import unittest
7
8from moap.util import ctags
9
10class TestTag(unittest.TestCase):
11    def setUp(self):
12        self.tag = ctags.Tag()
13
[150]14    def testRepr(self):
15        self.failUnless(repr(self.tag))
16
[129]17    def testParse(self):
18        self.tag.parse('diff\tmoap/vcs/cvs.py\t/^    def diff(self, path):$/;"\tm\tline:98\tlanguage:Python\tclass:CVS')
19        self.assertEquals(self.tag.name, "diff")
20        self.assertEquals(self.tag.file, "moap/vcs/cvs.py")
21        self.assertEquals(self.tag.line, 98)
22        self.assertEquals(self.tag.language, 'Python')
23        self.assertEquals(self.tag.klazz, 'CVS')
24
[336]25    def test281(self):
26        # in moap.util.ctags, the tagMatcher originally had non-spaces for
27        # the first column; ticket 281 has a space in the first column.
28        self.tag.parse('line operator =\t/home/murrayc/svn/gnome220/branches/glom-1-6/glom/libglom/data_structure/field.cc\t/^Field& Field::operator=(const Field& src)$/;"\tf\tline:58\tlanguage:C++\tclass:Glom::Field\tsignature:(const Field& src)')
29
[129]30class TestCTags(unittest.TestCase):
31    def setUp(self):
32        file = os.path.join(os.path.dirname(__file__), 'ctags', 'tags')
33        self.ctags = ctags.CTags()
34        self.ctags.addFile(file)
35
36    def testGetManyTags(self):
[214]37        tags = self.ctags.getTags('moap/vcs/cvs.py', 93, 11)
[129]38        self.assertEquals(tags[0].name, 'commit')
39        self.assertEquals(tags[1].name, 'diff')
40
41    def testGetBeforeFirstTag(self):
42        # asking for tags before there are any should return no tags
[214]43        tags = self.ctags.getTags('moap/vcs/cvs.py', 5, 6)
[129]44        self.failIf(tags)
45
46    def testGetWithFirstTag(self):
47        # asking for tags before and in first tag should give first tag
[214]48        tags = self.ctags.getTags('moap/vcs/cvs.py', 15, 6)
[129]49        self.assertEquals(len(tags), 1)
50        self.assertEquals(tags[0].name, 'detect')
51
52    def testGetTagBeforeTagLine(self):
[214]53        tags = self.ctags.getTags('moap/vcs/cvs.py', 15)
[129]54        self.failIf(tags)
55
56    def testGetTagOnTagLine(self):
[214]57        tags = self.ctags.getTags('moap/vcs/cvs.py', 16)
[129]58        self.assertEquals(len(tags), 1)
59        self.assertEquals(tags[0].name, 'detect')
60
61    def testGetTagAfterTagLine(self):
[214]62        tags = self.ctags.getTags('moap/vcs/cvs.py', 17)
[129]63        self.assertEquals(len(tags), 1)
64        self.assertEquals(tags[0].name, 'detect')
[137]65
[150]66    def testGetLastTwo(self):
67        # update starts on 106
[214]68        tags = self.ctags.getTags('moap/vcs/cvs.py', 105, 2)
[150]69        self.assertEquals(len(tags), 2)
70        self.assertEquals(tags[0].name, 'diff')
71        self.assertEquals(tags[1].name, 'update')
72
[137]73    def testGetLastTag(self):
[214]74        tags = self.ctags.getTags('moap/vcs/cvs.py', 106)
[137]75        self.assertEquals(len(tags), 1)
76        self.assertEquals(tags[0].name, 'update')
[150]77
78class TestCTagsFromString(unittest.TestCase):
79    def testFromEmptyString(self):
80        self.ctags = ctags.CTags()
81        self.ctags.addString('')
82
83    def testFromString(self):
84        self.ctags = ctags.CTags()
85        self.ctags.addString('!_TAG_')
86
87    def testFromWrongString(self):
88        self.ctags = ctags.CTags()
89        self.assertRaises(KeyError, self.ctags.addString, 'wrongtype')
Note: See TracBrowser for help on using the repository browser.