diff options
author | benadha <benawiadha@gmail.com> | 2022-01-05 17:37:27 +0700 |
---|---|---|
committer | benadha <benawiadha@gmail.com> | 2022-01-05 17:37:27 +0700 |
commit | 07f2cfedc47387ea4d7cf3b5ab435a971f7c6f02 (patch) | |
tree | ab1000ef8d399b3c4c4215c80073b0d3ea3f266a /tests.py | |
parent | b2b99fe7b1588616059de47edac567be442a983e (diff) | |
download | epy-07f2cfedc47387ea4d7cf3b5ab435a971f7c6f02.tar.gz |
Add tests
Diffstat (limited to 'tests.py')
-rw-r--r-- | tests.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tests.py b/tests.py new file mode 100644 index 0000000..f93370a --- /dev/null +++ b/tests.py @@ -0,0 +1,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)] |