File: test_basic.py

package info (click to toggle)
pypy 7.0.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 107,216 kB
  • sloc: python: 1,201,787; ansic: 62,419; asm: 5,169; cpp: 3,017; sh: 2,534; makefile: 545; xml: 243; lisp: 45; awk: 4
file content (116 lines) | stat: -rw-r--r-- 4,168 bytes parent folder | download | duplicates (7)
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
#   Copyright 2000-2004 Michael Hudson-Doyle <micahel@gmail.com>
#
#                        All Rights Reserved
#
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice appear in all copies and
# that both that copyright notice and this permission notice appear in
# supporting documentation.
#
# THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import pytest
from .infrastructure import read_spec


def test_basic():
    read_spec([(('self-insert', 'a'), ['a']),
               ( 'accept',            ['a'])])


def test_repeat():
    read_spec([(('digit-arg', '3'),   ['']),
               (('self-insert', 'a'), ['aaa']),
               ( 'accept',            ['aaa'])])


def test_kill_line():
    read_spec([(('self-insert', 'abc'), ['abc']),
               ( 'left',                None),
               ( 'kill-line',           ['ab']),
               ( 'accept',              ['ab'])])


def test_unix_line_discard():
    read_spec([(('self-insert', 'abc'), ['abc']),
               ( 'left',                None),
               ( 'unix-word-rubout',    ['c']),
               ( 'accept',              ['c'])])


def test_kill_word():
    read_spec([(('self-insert', 'ab cd'), ['ab cd']),
               ( 'beginning-of-line',     ['ab cd']),
               ( 'kill-word',             [' cd']),
               ( 'accept',                [' cd'])])


def test_backward_kill_word():
    read_spec([(('self-insert', 'ab cd'), ['ab cd']),
               ( 'backward-kill-word',    ['ab ']),
               ( 'accept',                ['ab '])])


def test_yank():
    read_spec([(('self-insert', 'ab cd'), ['ab cd']),
               ( 'backward-kill-word',    ['ab ']),
               ( 'beginning-of-line',     ['ab ']),
               ( 'yank',                  ['cdab ']),
               ( 'accept',                ['cdab '])])


def test_yank_pop():
    read_spec([(('self-insert', 'ab cd'), ['ab cd']),
               ( 'backward-kill-word',    ['ab ']),
               ( 'left',                  ['ab ']),
               ( 'backward-kill-word',    [' ']),
               ( 'yank',                  ['ab ']),
               ( 'yank-pop',              ['cd ']),
               ( 'accept',                ['cd '])])


# interrupt uses os.kill which doesn't go through signal handlers on windows
@pytest.mark.skipif("os.name == 'nt'")
def test_interrupt():
    with pytest.raises(KeyboardInterrupt):
        read_spec([('interrupt', [''])])


# test_suspend -- hah
def test_up():
    read_spec([(('self-insert', 'ab\ncd'), ['ab', 'cd']),
               ( 'up',                     ['ab', 'cd']),
               (('self-insert', 'e'),      ['abe', 'cd']),
               ( 'accept',                 ['abe', 'cd'])])


def test_down():
    read_spec([(('self-insert', 'ab\ncd'), ['ab', 'cd']),
               ( 'up',                     ['ab', 'cd']),
               (('self-insert', 'e'),      ['abe', 'cd']),
               ( 'down',                   ['abe', 'cd']),
               (('self-insert', 'f'),      ['abe', 'cdf']),
               ( 'accept',                 ['abe', 'cdf'])])


def test_left():
    read_spec([(('self-insert', 'ab'), ['ab']),
               ( 'left',               ['ab']),
               (('self-insert', 'c'),  ['acb']),
               ( 'accept',             ['acb'])])


def test_right():
    read_spec([(('self-insert', 'ab'), ['ab']),
               ( 'left',               ['ab']),
               (('self-insert', 'c'),  ['acb']),
               ( 'right',              ['acb']),
               (('self-insert', 'd'),  ['acbd']),
               ( 'accept',             ['acbd'])])