-
Notifications
You must be signed in to change notification settings - Fork 771
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signature Help: Add simple gopls test
- Loading branch information
1 parent
88ba001
commit c3d0f0a
Showing
2 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package td | ||
|
||
import "fmt" | ||
|
||
func add(x int, y int) int { | ||
return x + y | ||
} | ||
|
||
func main() { | ||
fmt.Println(add(42, 13)) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# coding: utf-8 | ||
# | ||
# Copyright (C) 2019 ycmd contributors | ||
# | ||
# This file is part of ycmd. | ||
# | ||
# ycmd is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# ycmd is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with ycmd. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from __future__ import absolute_import | ||
from __future__ import unicode_literals | ||
from __future__ import print_function | ||
from __future__ import division | ||
# Not installing aliases from python-future; it's unreliable and slow. | ||
from builtins import * # noqa | ||
|
||
from nose.tools import eq_ | ||
from hamcrest import ( assert_that, | ||
contains, | ||
empty, | ||
has_entries ) | ||
import requests | ||
|
||
from ycmd.utils import ReadFile | ||
from ycmd.tests.go import PathToTestFile, SharedYcmd | ||
from ycmd.tests.test_utils import ( CombineRequest, | ||
ParameterMatcher, | ||
SignatureMatcher ) | ||
|
||
|
||
def ProjectPath( *args ): | ||
return PathToTestFile( 'extra_confs', | ||
'simple_extra_conf_project', | ||
'src', | ||
*args ) | ||
|
||
|
||
def RunTest( app, test ): | ||
""" | ||
Method to run a simple signature help test and verify the result | ||
test is a dictionary containing: | ||
'request': kwargs for BuildRequest | ||
'expect': { | ||
'response': server response code (e.g. httplib.OK) | ||
'data': matcher for the server response json | ||
} | ||
""" | ||
contents = ReadFile( test[ 'request' ][ 'filepath' ] ) | ||
|
||
app.post_json( '/event_notification', | ||
CombineRequest( test[ 'request' ], { | ||
'event_name': 'FileReadyToParse', | ||
'contents': contents, | ||
} ), | ||
expect_errors = True ) | ||
|
||
# We ignore errors here and we check the response code ourself. | ||
# This is to allow testing of requests returning errors. | ||
response = app.post_json( '/signature_help', | ||
CombineRequest( test[ 'request' ], { | ||
'contents': contents | ||
} ), | ||
expect_errors = True ) | ||
|
||
eq_( response.status_code, test[ 'expect' ][ 'response' ] ) | ||
|
||
assert_that( response.json, test[ 'expect' ][ 'data' ] ) | ||
|
||
|
||
@SharedYcmd | ||
def SignatureHelp_MethodTrigger_test( app ): | ||
RunTest( app, { | ||
'description': 'Trigger after (', | ||
'request': { | ||
'filetype' : 'go', | ||
'filepath' : PathToTestFile( 'td', 'signature_help.go' ), | ||
'line_num' : 10, | ||
'column_num': 18, | ||
}, | ||
'expect': { | ||
'response': requests.codes.ok, | ||
'data': has_entries( { | ||
'errors': empty(), | ||
'signature_help': has_entries( { | ||
'activeSignature': 0, | ||
'activeParameter': 0, | ||
'signatures': contains( | ||
SignatureMatcher( 'add(x int, y int) int', | ||
[ ParameterMatcher( 'x int' ), | ||
ParameterMatcher( 'y int' ) ] ) | ||
), | ||
} ), | ||
} ) | ||
} | ||
} ) |