aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/prompt-toolkit/py2/tests/test_shortcuts.py
blob: 8c13510ea8349cba7fb0c4d09fee1dd15f26bccd (plain) (blame)
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
from prompt_toolkit.shortcuts import _split_multiline_prompt
from prompt_toolkit.token import Token


def test_split_multiline_prompt():
    # Test 1: no newlines:
    tokens = [(Token, 'ab')]
    has_before_tokens, before, first_input_line = _split_multiline_prompt(lambda cli: tokens)
    assert has_before_tokens(None) is False
    assert before(None) == []
    assert first_input_line(None) == [
        (Token, 'a'),
        (Token, 'b'),
    ]

    # Test 1: multiple lines.
    tokens = [(Token, 'ab\ncd\nef')]
    has_before_tokens, before, first_input_line = _split_multiline_prompt(lambda cli: tokens)
    assert has_before_tokens(None) is True
    assert before(None) == [
        (Token, 'a'),
        (Token, 'b'),
        (Token, '\n'),
        (Token, 'c'),
        (Token, 'd'),
    ]
    assert first_input_line(None) == [
        (Token, 'e'),
        (Token, 'f'),
    ]

    # Edge case 1: starting with a newline.
    tokens = [(Token, '\nab')]
    has_before_tokens, before, first_input_line = _split_multiline_prompt(lambda cli: tokens)
    assert has_before_tokens(None) is True
    assert before(None) == []
    assert first_input_line(None) == [
        (Token, 'a'),
        (Token, 'b')
    ]

    # Edge case 2: starting with two newlines.
    tokens = [(Token, '\n\nab')]
    has_before_tokens, before, first_input_line = _split_multiline_prompt(lambda cli: tokens)
    assert has_before_tokens(None) is True
    assert before(None) == [(Token, '\n')]
    assert first_input_line(None) == [
        (Token, 'a'),
        (Token, 'b')
    ]