Debian Codegraph @

extra_tests/test_pyrepl/test_basic.py

raw symbols SCIP
1 # Copyright 2000-2004 Michael Hudson-Doyle <[email protected]>
2 #
3 # All Rights Reserved
4 #
5 #
6 # Permission to use, copy, modify, and distribute this software and
7 # its documentation for any purpose is hereby granted without fee,
8 # provided that the above copyright notice appear in all copies and
9 # that both that copyright notice and this permission notice appear in
10 # supporting documentation.
11 #
12 # THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
13 # THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
14 # AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
15 # INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
16 # RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
17 # CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
18 # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 import pytest
20 from .infrastructure import read_spec
21
22
23 def test_basic():
24 read_spec([(('self-insert', 'a'), ['a']),
25 ( 'accept', ['a'])])
26
27
28 def test_repeat():
29 read_spec([(('digit-arg', '3'), ['']),
30 (('self-insert', 'a'), ['aaa']),
31 ( 'accept', ['aaa'])])
32
33
34 def test_kill_line():
35 read_spec([(('self-insert', 'abc'), ['abc']),
36 ( 'left', None),
37 ( 'kill-line', ['ab']),
38 ( 'accept', ['ab'])])
39
40
41 def test_unix_line_discard():
42 read_spec([(('self-insert', 'abc'), ['abc']),
43 ( 'left', None),
44 ( 'unix-word-rubout', ['c']),
45 ( 'accept', ['c'])])
46
47
48 def test_kill_word():
49 read_spec([(('self-insert', 'ab cd'), ['ab cd']),
50 ( 'beginning-of-line', ['ab cd']),
51 ( 'kill-word', [' cd']),
52 ( 'accept', [' cd'])])
53
54
55 def test_backward_kill_word():
56 read_spec([(('self-insert', 'ab cd'), ['ab cd']),
57 ( 'backward-kill-word', ['ab ']),
58 ( 'accept', ['ab '])])
59
60 def test_forward_backward_word():
61 read_spec([(('self-insert', 'ab cd'), ['ab cd']),
62 ( 'backward-word', ['ab cd']),
63 (('self-insert', 'ef '), ['ab ef cd']),
64 ( 'forward-word', ['ab ef cd']),
65 (('self-insert', ' gh'), ['ab ef cd gh']),
66 ( 'accept', ['ab ef cd gh'])])
67
68
69 def test_yank():
70 read_spec([(('self-insert', 'ab cd'), ['ab cd']),
71 ( 'backward-kill-word', ['ab ']),
72 ( 'beginning-of-line', ['ab ']),
73 ( 'yank', ['cdab ']),
74 ( 'accept', ['cdab '])])
75
76
77 def test_yank_pop():
78 read_spec([(('self-insert', 'ab cd'), ['ab cd']),
79 ( 'backward-kill-word', ['ab ']),
80 ( 'left', ['ab ']),
81 ( 'backward-kill-word', [' ']),
82 ( 'yank', ['ab ']),
83 ( 'yank-pop', ['cd ']),
84 ( 'accept', ['cd '])])
85
86
87 # interrupt uses os.kill which doesn't go through signal handlers on windows
88 @pytest.mark.skipif("os.name == 'nt'")
89 def test_interrupt():
90 with pytest.raises(KeyboardInterrupt):
91 read_spec([('interrupt', [''])])
92
93
94 # test_suspend -- hah
95 def test_up():
96 read_spec([(('self-insert', 'ab\ncd'), ['ab', 'cd']),
97 ( 'up', ['ab', 'cd']),
98 (('self-insert', 'e'), ['abe', 'cd']),
99 ( 'accept', ['abe', 'cd'])])
100
101
102 def test_down():
103 read_spec([(('self-insert', 'ab\ncd'), ['ab', 'cd']),
104 ( 'up', ['ab', 'cd']),
105 (('self-insert', 'e'), ['abe', 'cd']),
106 ( 'down', ['abe', 'cd']),
107 (('self-insert', 'f'), ['abe', 'cdf']),
108 ( 'accept', ['abe', 'cdf'])])
109
110
111 def test_left():
112 read_spec([(('self-insert', 'ab'), ['ab']),
113 ( 'left', ['ab']),
114 (('self-insert', 'c'), ['acb']),
115 ( 'accept', ['acb'])])
116
117
118 def test_right():
119 read_spec([(('self-insert', 'ab'), ['ab']),
120 ( 'left', ['ab']),
121 (('self-insert', 'c'), ['acb']),
122 ( 'right', ['acb']),
123 (('self-insert', 'd'), ['acbd']),
124 ( 'accept', ['acbd'])])