-
-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ui-] fix clipdraw, add unit tests #2005
- Loading branch information
Showing
2 changed files
with
41 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import pytest | ||
from unittest.mock import Mock, call | ||
|
||
import visidata | ||
|
||
|
||
class TestClipText: | ||
@pytest.mark.parametrize('s, dispw', [ | ||
('abcdef', 6), | ||
('桜 高橋', 7), | ||
('[:onclick sidebar-toggle][:reverse] b to toggle sidebar [:]', 21), | ||
]) | ||
def test_dispwidth(self, s, dispw): | ||
assert visidata.dispwidth(s) == dispw | ||
|
||
@pytest.mark.parametrize('s, w, clippeds, clippedw', [ | ||
('b to', 4, 'b to', 4), | ||
('abcde', 8, 'abcde', 5), | ||
(' jsonl', 5, ' jso…', 5), | ||
]) | ||
def test_clipstr(self, s, w, clippeds, clippedw): | ||
clips, clipw = visidata.clipstr(s, w) | ||
assert clips == clippeds | ||
assert clipw == clippedw | ||
|
||
def test_clipdraw_chunks(self): | ||
prechunks = [ | ||
('', 'x'), | ||
('', 'jsonl'), | ||
] | ||
scr = Mock() | ||
scr.getmaxyx.return_value = (80,25) | ||
visidata.clipdraw_chunks(scr, 0, 0, prechunks, 0, w=5) | ||
scr.addstr.assert_has_calls([ | ||
call(0, 0, 'x', 0), | ||
call(0, 1, 'jso…', 0), | ||
], any_order=True) |