Completed
Push — master ( 82760b...c05ef7 )
by Lambda
02:32
created

test_keystroke_str()   B

Complexity

Conditions 5

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
dl 0
loc 5
rs 8.5454
c 0
b 0
f 0
1
from curses import ascii
2
from collections import abc
3
from contextlib import ExitStack
4
5
from datetime import datetime, timedelta
6
from unittest.mock import MagicMock, patch
7
8
import pytest
9
10
from neovim_prompt.key import Key
11
from neovim_prompt.keystroke import Keystroke
12
13
14
def test_Keystroke_property(nvim):
15
    keys = Keystroke.parse(nvim, 'abc')
16
    assert isinstance(keys, abc.Hashable)
17
    assert isinstance(keys, abc.Container)
18
    assert isinstance(keys, abc.Sized)
19
20
21
def test_Keystroke_parse_with_sequence(nvim):
22
    expr = [
23
        Key.parse(nvim, 'a'),
24
        Key.parse(nvim, 'b'),
25
        Key.parse(nvim, 'c'),
26
    ]
27
    keys = Keystroke.parse(nvim, expr)
28
    assert keys == tuple(expr)
29
30
    keys = Keystroke.parse(nvim, tuple(expr))
31
    assert keys == tuple(expr)
32
33
34
def test_Keystroke_parse_with_bytes(nvim):
35
    expr = [
36
        Key.parse(nvim, 'a'),
37
        Key.parse(nvim, 'b'),
38
        Key.parse(nvim, 'c'),
39
    ]
40
    keys = Keystroke.parse(nvim, b'abc')
41
    assert keys == tuple(expr)
42
43
    expr = [
44
        Key.parse(nvim, '<C-T>'),
45
        Key.parse(nvim, 'b'),
46
        Key.parse(nvim, '<Home>'),
47
    ]
48
    keys = Keystroke.parse(nvim, b'<C-T>b<Home>')
49
    assert keys == tuple(expr)
50
51
52
def test_Keystroke_parse_with_str(nvim):
53
    expr = [
54
        Key.parse(nvim, 'a'),
55
        Key.parse(nvim, 'b'),
56
        Key.parse(nvim, 'c'),
57
    ]
58
    keys = Keystroke.parse(nvim, 'abc')
59
    assert keys == tuple(expr)
60
61
    expr = [
62
        Key.parse(nvim, '<C-T>'),
63
        Key.parse(nvim, 'b'),
64
        Key.parse(nvim, '<Home>'),
65
    ]
66
    keys = Keystroke.parse(nvim, '<C-T>b<Home>')
67
    assert keys == tuple(expr)
68
69
70
def test_keystroke_startswith(nvim):
71
    rhs1 = Keystroke.parse(nvim, '<C-A>')
72
    rhs2 = Keystroke.parse(nvim, '<C-A><C-B>')
73
    rhs3 = Keystroke.parse(nvim, '<C-A><C-C>')
74
75
    assert rhs1.startswith(Keystroke.parse(nvim, ''))
76
    assert rhs2.startswith(Keystroke.parse(nvim, ''))
77
    assert rhs3.startswith(Keystroke.parse(nvim, ''))
78
79
    assert rhs1.startswith(Keystroke.parse(nvim, '<C-A>'))
80
    assert rhs2.startswith(Keystroke.parse(nvim, '<C-A>'))
81
    assert rhs3.startswith(Keystroke.parse(nvim, '<C-A>'))
82
83
    assert not rhs1.startswith(Keystroke.parse(nvim, '<C-A><C-B>'))
84
    assert rhs2.startswith(Keystroke.parse(nvim, '<C-A><C-B>'))
85
    assert not rhs3.startswith(Keystroke.parse(nvim, '<C-A><C-B>'))
86
87
    assert not rhs1.startswith(Keystroke.parse(nvim, '<C-A><C-B><C-C>'))
88
    assert not rhs2.startswith(Keystroke.parse(nvim, '<C-A><C-B><C-C>'))
89
    assert not rhs3.startswith(Keystroke.parse(nvim, '<C-A><C-B><C-C>'))
90
91
92
def test_keystroke_str(nvim):
93
    assert str(Keystroke.parse(nvim, 'abc')) == 'abc'
94
    assert str(Keystroke.parse(nvim, '<C-H><C-H>')) == '\x08\x08'
95
    assert str(Keystroke.parse(nvim, '<Backspace><Delete>')) == ''
96
    assert str(Keystroke.parse(nvim, '<prompt:accept>')) == '<prompt:accept>'
97