Skip to content

Commit c3d0f0a

Browse files
committed
Signature Help: Add simple gopls test
1 parent 88ba001 commit c3d0f0a

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package td
2+
3+
import "fmt"
4+
5+
func add(x int, y int) int {
6+
return x + y
7+
}
8+
9+
func main() {
10+
fmt.Println(add(42, 13))
11+
}
12+
13+

ycmd/tests/go/signature_help_test.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# coding: utf-8
2+
#
3+
# Copyright (C) 2019 ycmd contributors
4+
#
5+
# This file is part of ycmd.
6+
#
7+
# ycmd is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# ycmd is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with ycmd. If not, see <http://www.gnu.org/licenses/>.
19+
20+
from __future__ import absolute_import
21+
from __future__ import unicode_literals
22+
from __future__ import print_function
23+
from __future__ import division
24+
# Not installing aliases from python-future; it's unreliable and slow.
25+
from builtins import * # noqa
26+
27+
from nose.tools import eq_
28+
from hamcrest import ( assert_that,
29+
contains,
30+
empty,
31+
has_entries )
32+
import requests
33+
34+
from ycmd.utils import ReadFile
35+
from ycmd.tests.go import PathToTestFile, SharedYcmd
36+
from ycmd.tests.test_utils import ( CombineRequest,
37+
ParameterMatcher,
38+
SignatureMatcher )
39+
40+
41+
def ProjectPath( *args ):
42+
return PathToTestFile( 'extra_confs',
43+
'simple_extra_conf_project',
44+
'src',
45+
*args )
46+
47+
48+
def RunTest( app, test ):
49+
"""
50+
Method to run a simple signature help test and verify the result
51+
52+
test is a dictionary containing:
53+
'request': kwargs for BuildRequest
54+
'expect': {
55+
'response': server response code (e.g. httplib.OK)
56+
'data': matcher for the server response json
57+
}
58+
"""
59+
contents = ReadFile( test[ 'request' ][ 'filepath' ] )
60+
61+
app.post_json( '/event_notification',
62+
CombineRequest( test[ 'request' ], {
63+
'event_name': 'FileReadyToParse',
64+
'contents': contents,
65+
} ),
66+
expect_errors = True )
67+
68+
# We ignore errors here and we check the response code ourself.
69+
# This is to allow testing of requests returning errors.
70+
response = app.post_json( '/signature_help',
71+
CombineRequest( test[ 'request' ], {
72+
'contents': contents
73+
} ),
74+
expect_errors = True )
75+
76+
eq_( response.status_code, test[ 'expect' ][ 'response' ] )
77+
78+
assert_that( response.json, test[ 'expect' ][ 'data' ] )
79+
80+
81+
@SharedYcmd
82+
def SignatureHelp_MethodTrigger_test( app ):
83+
RunTest( app, {
84+
'description': 'Trigger after (',
85+
'request': {
86+
'filetype' : 'go',
87+
'filepath' : PathToTestFile( 'td', 'signature_help.go' ),
88+
'line_num' : 10,
89+
'column_num': 18,
90+
},
91+
'expect': {
92+
'response': requests.codes.ok,
93+
'data': has_entries( {
94+
'errors': empty(),
95+
'signature_help': has_entries( {
96+
'activeSignature': 0,
97+
'activeParameter': 0,
98+
'signatures': contains(
99+
SignatureMatcher( 'add(x int, y int) int',
100+
[ ParameterMatcher( 'x int' ),
101+
ParameterMatcher( 'y int' ) ] )
102+
),
103+
} ),
104+
} )
105+
}
106+
} )

0 commit comments

Comments
 (0)