FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
bpython/bpython/test/test_brackets_completion.py at main · BlenderCL/bpython · GitHub
BlenderCL
/
bpython
Public
forked from
bpython/bpython
Notifications
You must be signed in to change notification settings
Fork
1
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
bpython
/
bpython
/
test
/
test_brackets_completion.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
154 lines (128 loc) · 5.87 KB
Breadcrumbs
bpython
/
bpython
/
test
/
test_brackets_completion.py
Copy path
File metadata and controls
154 lines (128 loc) · 5.87 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import
os
from
typing
import
cast
from
bpython
.
test
import
FixLanguageTestCase
as
TestCase
,
TEST_CONFIG
from
bpython
.
curtsiesfrontend
import
repl
as
curtsiesrepl
from
bpython
import
config
from
curtsies
.
window
import
CursorAwareWindow
def
setup_config
(
conf
):
config_struct
=
config
.
Config
(
TEST_CONFIG
)
for
key
,
value
in
conf
.
items
():
if
not
hasattr
(
config_struct
,
key
):
raise
ValueError
(
f"
{
key
!r
}
is not a valid config attribute"
)
setattr
(
config_struct
,
key
,
value
)
return
config_struct
def
create_repl
(
brackets_enabled
=
False
,
**
kwargs
):
config
=
setup_config
(
{
"editor"
:
"true"
,
"brackets_completion"
:
brackets_enabled
}
)
repl
=
curtsiesrepl
.
BaseRepl
(
config
,
cast
(
CursorAwareWindow
,
None
),
**
kwargs
)
os
.
environ
[
"PAGER"
]
=
"true"
os
.
environ
.
pop
(
"PYTHONSTARTUP"
,
None
)
repl
.
width
=
50
repl
.
height
=
20
return
repl
class
TestBracketCompletionEnabled
(
TestCase
):
def
setUp
(
self
):
self
.
repl
=
create_repl
(
brackets_enabled
=
True
)
def
process_multiple_events
(
self
,
event_list
):
for
event
in
event_list
:
self
.
repl
.
process_event
(
event
)
def
test_start_line
(
self
):
self
.
repl
.
process_event
(
"("
)
self
.
assertEqual
(
self
.
repl
.
_current_line
,
"()"
)
self
.
assertEqual
(
self
.
repl
.
_cursor_offset
,
1
)
def
test_nested_brackets
(
self
):
self
.
process_multiple_events
([
"("
,
"["
,
"{"
])
self
.
assertEqual
(
self
.
repl
.
_current_line
,
"""([{}])"""
)
self
.
assertEqual
(
self
.
repl
.
_cursor_offset
,
3
)
def
test_quotes
(
self
):
self
.
process_multiple_events
([
"("
,
"'"
,
"x"
,
"<TAB>"
,
","
])
self
.
process_multiple_events
([
"["
,
'"'
,
"y"
,
"<TAB>"
,
"<TAB>"
,
"<TAB>"
])
self
.
assertEqual
(
self
.
repl
.
_current_line
,
"""('x',["y"])"""
)
self
.
assertEqual
(
self
.
repl
.
_cursor_offset
,
11
)
def
test_bracket_overwrite_closing_char
(
self
):
self
.
process_multiple_events
([
"("
,
"["
,
"{"
])
self
.
assertEqual
(
self
.
repl
.
_current_line
,
"""([{}])"""
)
self
.
assertEqual
(
self
.
repl
.
_cursor_offset
,
3
)
self
.
process_multiple_events
([
"}"
,
"]"
,
")"
])
self
.
assertEqual
(
self
.
repl
.
_current_line
,
"""([{}])"""
)
self
.
assertEqual
(
self
.
repl
.
_cursor_offset
,
6
)
def
test_brackets_move_cursor_on_tab
(
self
):
self
.
process_multiple_events
([
"("
,
"["
,
"{"
])
self
.
assertEqual
(
self
.
repl
.
_current_line
,
"""([{}])"""
)
self
.
assertEqual
(
self
.
repl
.
_cursor_offset
,
3
)
self
.
repl
.
process_event
(
"<TAB>"
)
self
.
assertEqual
(
self
.
repl
.
_current_line
,
"""([{}])"""
)
self
.
assertEqual
(
self
.
repl
.
_cursor_offset
,
4
)
self
.
repl
.
process_event
(
"<TAB>"
)
self
.
assertEqual
(
self
.
repl
.
_current_line
,
"""([{}])"""
)
self
.
assertEqual
(
self
.
repl
.
_cursor_offset
,
5
)
self
.
repl
.
process_event
(
"<TAB>"
)
self
.
assertEqual
(
self
.
repl
.
_current_line
,
"""([{}])"""
)
self
.
assertEqual
(
self
.
repl
.
_cursor_offset
,
6
)
def
test_brackets_non_whitespace_following_char
(
self
):
self
.
repl
.
current_line
=
"s = s.connect('localhost', 8080)"
self
.
repl
.
cursor_offset
=
14
self
.
repl
.
process_event
(
"("
)
self
.
assertEqual
(
self
.
repl
.
_current_line
,
"s = s.connect(('localhost', 8080)"
)
self
.
assertEqual
(
self
.
repl
.
_cursor_offset
,
15
)
def
test_brackets_deletion_on_backspace
(
self
):
self
.
repl
.
current_line
=
"def foo()"
self
.
repl
.
cursor_offset
=
8
self
.
repl
.
process_event
(
"<BACKSPACE>"
)
self
.
assertEqual
(
self
.
repl
.
_current_line
,
"def foo"
)
self
.
assertEqual
(
self
.
repl
.
cursor_offset
,
7
)
def
test_brackets_deletion_on_backspace_nested
(
self
):
self
.
repl
.
current_line
=
'([{""}])'
self
.
repl
.
cursor_offset
=
4
self
.
process_multiple_events
(
[
"<BACKSPACE>"
,
"<BACKSPACE>"
,
"<BACKSPACE>"
]
)
self
.
assertEqual
(
self
.
repl
.
_current_line
,
"()"
)
self
.
assertEqual
(
self
.
repl
.
cursor_offset
,
1
)
class
TestBracketCompletionDisabled
(
TestCase
):
def
setUp
(
self
):
self
.
repl
=
create_repl
(
brackets_enabled
=
False
)
def
process_multiple_events
(
self
,
event_list
):
for
event
in
event_list
:
self
.
repl
.
process_event
(
event
)
def
test_start_line
(
self
):
self
.
repl
.
process_event
(
"("
)
self
.
assertEqual
(
self
.
repl
.
_current_line
,
"("
)
self
.
assertEqual
(
self
.
repl
.
_cursor_offset
,
1
)
def
test_nested_brackets
(
self
):
self
.
process_multiple_events
([
"("
,
"["
,
"{"
])
self
.
assertEqual
(
self
.
repl
.
_current_line
,
"([{"
)
self
.
assertEqual
(
self
.
repl
.
_cursor_offset
,
3
)
def
test_bracket_overwrite_closing_char
(
self
):
self
.
process_multiple_events
([
"("
,
"["
,
"{"
])
self
.
assertEqual
(
self
.
repl
.
_current_line
,
"""([{"""
)
self
.
assertEqual
(
self
.
repl
.
_cursor_offset
,
3
)
self
.
process_multiple_events
([
"}"
,
"]"
,
")"
])
self
.
assertEqual
(
self
.
repl
.
_current_line
,
"""([{}])"""
)
self
.
assertEqual
(
self
.
repl
.
_cursor_offset
,
6
)
def
test_brackets_move_cursor_on_tab
(
self
):
self
.
process_multiple_events
([
"("
,
"["
,
"{"
])
self
.
assertEqual
(
self
.
repl
.
_current_line
,
"""([{"""
)
self
.
assertEqual
(
self
.
repl
.
_cursor_offset
,
3
)
self
.
repl
.
process_event
(
"<TAB>"
)
self
.
assertEqual
(
self
.
repl
.
_current_line
,
"""([{"""
)
self
.
assertEqual
(
self
.
repl
.
_cursor_offset
,
3
)
def
test_brackets_deletion_on_backspace
(
self
):
self
.
repl
.
current_line
=
"def foo()"
self
.
repl
.
cursor_offset
=
8
self
.
repl
.
process_event
(
"<BACKSPACE>"
)
self
.
assertEqual
(
self
.
repl
.
_current_line
,
"def foo"
)
self
.
assertEqual
(
self
.
repl
.
cursor_offset
,
7
)
def
test_brackets_deletion_on_backspace_nested
(
self
):
self
.
repl
.
current_line
=
'([{""}])'
self
.
repl
.
cursor_offset
=
4
self
.
process_multiple_events
(
[
"<BACKSPACE>"
,
"<BACKSPACE>"
,
"<BACKSPACE>"
]
)
self
.
assertEqual
(
self
.
repl
.
_current_line
,
"()"
)
self
.
assertEqual
(
self
.
repl
.
cursor_offset
,
1
)
Back
|
FazBrowse Home
|
New Git URL