-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathtest_go.py
95 lines (83 loc) · 3.23 KB
/
test_go.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# -*- coding: utf-8 -*-
import mock
import pytest
import completor
from completers.go import Go # noqa
from completor.compat import to_unicode
class TestGetCmdInfo(object):
expected = {
b'complete': {
'is_sync': False,
'input_content': 'package main\nvar _ = "哦"',
'cmd': [
'gocode', '-f=csv', 'autocomplete',
'/home/vagrant/bench.vim', 24
],
'ftype': 'go',
'is_daemon': False,
},
b'doc': {
'is_sync': False,
'cmd': ['gogetdoc', '-json', '-u', '-modified', '-pos',
'/home/vagrant/bench.vim:#24'],
'ftype': 'go',
'is_daemon': False,
'input_content': ('/home/vagrant/bench.vim\n26\n' +
to_unicode('package main\nvar _ = "哦"', 'utf-8'))
}
}
@pytest.mark.parametrize('action', [b'complete', b'doc'])
def test_get_cmd_info(self, vim_mod, create_buffer, action, monkeypatch):
vim_mod.funcs['line2byte'] = mock.Mock(return_value=20)
vim_mod.current.buffer = buf = create_buffer(1)
vim_mod.current.buffer.name = '/home/vagrant/bench.vim'
vim_mod.current.buffer.options = {
'fileencoding': 'utf-8', 'modified': True}
vim_mod.current.window.cursor = (1, 5)
vim_mod.eval = mock.Mock(return_value='1')
buf[:] = ['package main', 'var _ = "哦"']
go = completor.get('go')
info = go.get_cmd_info(action)
assert info == self.expected[action]
def test_parse():
data = [
b'func,,Errorf,,func(format string, a ...interface{}) error',
b'func,,Fprint,,func(w io.Writer, a ...interface{}) (n int, err error)', # noqa
]
go = completor.get('go')
assert go.on_complete(data) == [{
'word': b'Errorf',
'menu': b'func(format string, a ...interface{}) error',
}, {
'word': b'Fprint',
'menu': b'func(w io.Writer, a ...interface{}) (n int, err error)',
}]
class TestDoc(object):
data = [
b'{"name": "RuneCountInString", "import": "unicode/utf8", "pkg": '
b'"utf8", "decl": "func RuneCountInString(s string) (n int)", "doc": '
b'"RuneCountInString is like RuneCount but its input is a string'
b'.\\n", "pos": "/usr/local/Cellar/go/1.9/libexec/src/unicode/utf8'
b'/utf8.go:412:6"}'
]
expected = {
'on_doc': ['import "unicode/utf8"\n\nfunc RuneCountInString'
'(s string) (n int)\n\nRuneCountInString is like '
'RuneCount but its input is a string.\n'],
'on_definition': [{
'col': '6',
'filename': '/usr/local/Cellar/go/1.9/libexec/src/unicode/utf8/utf8.go', # noqa
'lnum': '412', 'name': 'RuneCountInString'}]
}
@pytest.fixture(autouse=True)
def reset_guru(self):
go = completor.get('go')
status = go.use_guru_for_def
go.use_guru_for_def = False
yield
go.use_guru_for_def = status
@pytest.mark.parametrize('action', ['on_doc', 'on_definition'])
def test_doc(self, action):
go = completor.get('go')
ret = getattr(go, action)(self.data)
assert ret == self.expected[action]