FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-language-server/test/test_document.py at develop · palantir/python-language-server · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
palantir
/
python-language-server
Public
Notifications
You must be signed in to change notification settings
Fork
294
Star
2.7k
Code
Issues
161
Pull requests
27
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
python-language-server
/
test
/
test_document.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
99 lines (81 loc) · 2.91 KB
Breadcrumbs
python-language-server
/
test
/
test_document.py
Copy path
File metadata and controls
99 lines (81 loc) · 2.91 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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 2017 Palantir Technologies, Inc.
from
test
.
fixtures
import
DOC_URI
,
DOC
from
pyls
.
workspace
import
Document
def
test_document_props
(
doc
):
assert
doc
.
uri
==
DOC_URI
assert
doc
.
source
==
DOC
def
test_document_lines
(
doc
):
assert
len
(
doc
.
lines
)
==
4
assert
doc
.
lines
[
0
]
==
'import sys
\n
'
def
test_document_source_unicode
(
workspace
):
document_mem
=
Document
(
DOC_URI
,
workspace
,
u'my source'
)
document_disk
=
Document
(
DOC_URI
,
workspace
)
assert
isinstance
(
document_mem
.
source
,
type
(
document_disk
.
source
))
def
test_offset_at_position
(
doc
):
assert
doc
.
offset_at_position
({
'line'
:
0
,
'character'
:
8
})
==
8
assert
doc
.
offset_at_position
({
'line'
:
1
,
'character'
:
5
})
==
16
assert
doc
.
offset_at_position
({
'line'
:
2
,
'character'
:
0
})
==
12
assert
doc
.
offset_at_position
({
'line'
:
2
,
'character'
:
4
})
==
16
assert
doc
.
offset_at_position
({
'line'
:
4
,
'character'
:
0
})
==
51
def
test_word_at_position
(
doc
):
""" Return the position under the cursor (or last in line if past the end) """
# import sys
assert
doc
.
word_at_position
({
'line'
:
0
,
'character'
:
8
})
==
'sys'
# Past end of import sys
assert
doc
.
word_at_position
({
'line'
:
0
,
'character'
:
1000
})
==
'sys'
# Empty line
assert
doc
.
word_at_position
({
'line'
:
1
,
'character'
:
5
})
==
''
# def main():
assert
doc
.
word_at_position
({
'line'
:
2
,
'character'
:
0
})
==
'def'
# Past end of file
assert
doc
.
word_at_position
({
'line'
:
4
,
'character'
:
0
})
==
''
def
test_document_empty_edit
(
workspace
):
doc
=
Document
(
'file:///uri'
,
workspace
,
u''
)
doc
.
apply_change
({
'range'
: {
'start'
: {
'line'
:
0
,
'character'
:
0
},
'end'
: {
'line'
:
0
,
'character'
:
0
}
},
'text'
:
u'f'
})
assert
doc
.
source
==
u'f'
def
test_document_line_edit
(
workspace
):
doc
=
Document
(
'file:///uri'
,
workspace
,
u'itshelloworld'
)
doc
.
apply_change
({
'text'
:
u'goodbye'
,
'range'
: {
'start'
: {
'line'
:
0
,
'character'
:
3
},
'end'
: {
'line'
:
0
,
'character'
:
8
}
}
})
assert
doc
.
source
==
u'itsgoodbyeworld'
def
test_document_multiline_edit
(
workspace
):
old
=
[
"def hello(a, b):
\n
"
,
" print a
\n
"
,
" print b
\n
"
]
doc
=
Document
(
'file:///uri'
,
workspace
,
u''
.
join
(
old
))
doc
.
apply_change
({
'text'
:
u'print a, b'
,
'range'
: {
'start'
: {
'line'
:
1
,
'character'
:
4
},
'end'
: {
'line'
:
2
,
'character'
:
11
}
}})
assert
doc
.
lines
==
[
"def hello(a, b):
\n
"
,
" print a, b
\n
"
]
def
test_document_end_of_file_edit
(
workspace
):
old
=
[
"print 'a'
\n
"
,
"print 'b'
\n
"
]
doc
=
Document
(
'file:///uri'
,
workspace
,
u''
.
join
(
old
))
doc
.
apply_change
({
'text'
:
u'o'
,
'range'
: {
'start'
: {
'line'
:
2
,
'character'
:
0
},
'end'
: {
'line'
:
2
,
'character'
:
0
}
}})
assert
doc
.
lines
==
[
"print 'a'
\n
"
,
"print 'b'
\n
"
,
"o"
,
]
Back
|
FazBrowse Home
|
New Git URL