aboutsummaryrefslogtreecommitdiffstats
path: root/tests.py
blob: f93370a4d5664241602244a4c4c3576f5a66b4c0 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
from collections import namedtuple

from epy import TextMark, resolve_path, count_marked_text_len, construct_wrapped_line_marks


def test_resolve_path():
    UnresolvedPath = namedtuple("UnresolvedPath", ["current_dir", "relative_path"])

    inputs = [
        UnresolvedPath("/aaa/bbb/book.html", "../ccc.png"),
        UnresolvedPath("/aaa/bbb/book.html", "../../ccc.png"),
        UnresolvedPath("aaa/bbb/book.html", "../../ccc.png"),
    ]

    expecteds = [
        "/aaa/ccc.png",
        "/ccc.png",
        "ccc.png",
    ]

    for input, expected in zip(inputs, expecteds):
        assert resolve_path(input.current_dir, input.relative_path) == expected


def test_count_marked_text():
    text = [
        "Lorem ipsum dolor sit amet,",
        "consectetur adipiscing elit.",
        "Curabitur rutrum massa",  #2
        "pretium, pulvinar ligula a,",  #3
        "aliquam est. Proin ut lectus",  #4
        "ac massa fermentum commodo.",  #5
        "Duis ac urna a felis mollis",
        "laoreet. Nullam finibus nibh",
        "convallis, commodo nisl sit",
        "amet, vestibulum mauris. Nulla",
        "lacinia ultrices lacinia. Duis",
        "auctor nunc non felis",
        "ultricies, ut egestas tellus",
        "rhoncus. Aenean ultrices",
        "efficitur lacinia. Aliquam",
        "eros lacus, luctus eu lacinia",
        "in, eleifend nec nunc. Nam",
        "condimentum malesuada",
        "facilisis.",
    ]

    assert count_marked_text_len(text, 2, 3, 2, 19) == 17
    assert count_marked_text_len(text, 2, 3, 3, 5) == 25
    assert count_marked_text_len(text, 2, 3, 5, 2) == 77


def test_construct_wrapped_line_marks():
    #    "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur rutrum massa"
    # 1st:       |col:7     |n:11

    wrapped_line = [
        "Lorem ipsum dolor sit amet,",
        "consectetur adipiscing elit.",
        "Curabitur rutrum massa",
    ]

    assert construct_wrapped_line_marks(wrapped_line, TextMark(row=0, col=7, n_letters=11)) == [TextMark(row=0, col=7, n_letters=11)]