| 1 |
|
| 2 |
|
| 3 |
om> |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 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 |
|
| 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 |
|
| 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) |