Debian Codegraph @

lib/tests/test_autocomplete.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2008 Lukáš Lalinský <[email protected]om>
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
19 """Tests for QBzr plugin."""
20
21 from breezy.tests import TestCase
22 from io import StringIO
23 from breezy.plugins.qbrz.lib.autocomplete import get_wordlist_builder
24
25
26 class TestAutocomplete(TestCase):
27
28 def assertIn(self, item, container):
29 """Assert that `item` is present in `container`."""
30 if item not in container:
31 raise AssertionError("value(s) %r not present in container %r" % (item, container))
32
33 def test_cpp_header(self):
34 source = '''
35 class ClassName {
36 public:
37 ClassName() { calledFunction(); }
38 };
39 '''
40 words = list(get_wordlist_builder('.h').iter_words(StringIO(source)))
41 self.assertIn('ClassName', words)
42 self.assertIn('calledFunction', words)
43
44 def test_cpp_header_space_after_name(self):
45 # space between function name and opening parenthesis is legal in C
46 source = "void foo_bar (void);"
47 words = list(get_wordlist_builder('.h').iter_words(StringIO(source)))
48 self.assertIn('foo_bar', words)
49
50 def test_cpp_source(self):
51 source = '''
52 ClassName::function1()
53 {
54 function2()
55 }
56 '''
57 words = list(get_wordlist_builder('.cpp').iter_words(StringIO(source)))
58 self.assertIn('ClassName', words)
59 self.assertIn('ClassName::function1', words)
60 self.assertIn('function1', words)
61 self.assertIn('function2', words)
62
63 def test_c_source_space_after_name(self):
64 # space between function name and opening parenthesis is legal in C
65 source = """
66 void foo_bar (void)
67 {
68 return;
69 }
70 """
71 words = list(get_wordlist_builder('.c').iter_words(StringIO(source)))
72 self.assertIn('foo_bar', words)
73
74 def test_c_header_with_typedef(self):
75 source = """
76 typedef struct Foo
77 {
78 int i;
79 } Foo;
80
81 typedef union Bar {
82 int i;
83 float f;
84 } Bar;
85 """
86 words = list(get_wordlist_builder('.h').iter_words(StringIO(source)))
87 self.assertIn('Foo', words)
88 self.assertIn('Bar', words)
89
90 def test_java(self):
91 source = '''
92 package bar.foo;
93
94 public class ClassName1 extends ClassName2
95 {
96 public void function1()
97 {
98 }
99 }
100 '''
101 words = list(get_wordlist_builder('.java').iter_words(StringIO(source)))
102 self.assertIn('ClassName1', words)
103 self.assertIn('ClassName2', words)
104 self.assertIn('function1', words)
105
106 def test_python(self):
107 source = '''
108 class ClassName(object):
109
110 def function(self):
111 self.var = 1
112 '''
113 words = list(get_wordlist_builder('.py').iter_words(StringIO(source)))
114 self.assertIn('ClassName', words)
115 self.assertIn('function', words)
116 self.assertIn('var', words)