-
Notifications
You must be signed in to change notification settings - Fork 768
/
Copy pathget_skipped_ranges_test.py
99 lines (79 loc) · 2.91 KB
/
get_skipped_ranges_test.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
96
97
98
99
# Copyright (C) 2016 Davit Samvelyan
#
# 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
from future import standard_library
standard_library.install_aliases()
from builtins import * # noqa
from nose.tools import eq_
from hamcrest import ( assert_that, contains, empty )
from ycmd.tests.clang import PathToTestFile, SharedYcmd
from ycmd.tests.test_utils import BuildRequest
from ycmd.responses import ( BuildRangeData, Range, Location )
from ycmd.utils import ReadFile
import requests
_TEST_FILE = PathToTestFile( 'token_test_data',
'GetSkippedRanges_Clang_test.cc' )
@SharedYcmd
def setUpModule( app ):
app.post_json( '/load_extra_conf_file', {
'filepath': PathToTestFile( 'token_test_data', '.ycm_extra_conf.py' ) } )
def _SendReadyToParse( app, extra_flags = None ):
request = {
'filetype': 'cpp',
'filepath': _TEST_FILE,
'event_name': 'FileReadyToParse',
'contents': ReadFile( _TEST_FILE ),
'extra_conf_data': extra_flags,
}
app.post_json( '/event_notification', BuildRequest( **request ),
expect_errors = False )
def _BuildRangeData( sl, sc, el, ec ):
return BuildRangeData( Range( Location( sl, sc, _TEST_FILE ),
Location( el, ec, _TEST_FILE ) ) )
def _RunTest( app, expect ):
request = {
'filetypes': 'cpp',
'filepath': _TEST_FILE,
}
response = app.post_json( '/skipped_ranges', BuildRequest( **request ),
expect_errors = False )
eq_( response.status_code, requests.codes.ok )
assert_that( response.json[ 'skipped_ranges' ], expect )
@SharedYcmd
def InvalidFile_test( app ):
request = {
'filetypes': 'cpp',
'filepath': '',
}
response = app.post_json( '/skipped_ranges', BuildRequest( **request ),
expect_errors = True )
eq_( response.status_code, requests.codes.server_error )
@SharedYcmd
def SkippedRanges_test( app ):
_SendReadyToParse( app )
_RunTest( app,
contains(
_BuildRangeData( 2, 2, 4, 7 ),
_BuildRangeData( 11, 2, 13, 7 ),
) )
@SharedYcmd
def EmptySkippedRanges_test( app ):
_SendReadyToParse( app, [ '-DDEBUG' ] )
_RunTest( app, empty() )