History

msg: allow to truncate the message to terminal width

Kacper Michajłow committed 2 years ago

Commit bf025cd1 parent 95f00469 files · +106 −15Browse files

Showing the changes to test (1 of 9 files). Show all

Unified · Split

test/codepoint_width.c+22−1
@@ -17,9 +17,11 @@ · 16 unmodified lines
1717
1818 #include "test_utils.h"
1919
20+#include <limits.h>
21+
2022 #include "misc/codepoint_width.h"
2123
22−#define W(s) term_disp_width((bstr)bstr0_lit(s))
24+#define W(s) term_disp_width((bstr)bstr0_lit(s), INT_MAX, &(const unsigned char *){NULL})
2325
2426 int main(void) {
2527 assert_int_equal(W("A"), 1); // Single ASCII character
@@ -64,4 +66,23 @@ int main(void) { · 38 unmodified lines
6466
6567 // ASCII characters with carriage return
6668 assert_int_equal(W("ABC\rDEF"), 3);
69+
70+ bstr str = bstr0("ABCDEF");
71+ const unsigned char *cut_pos;
72+
73+ cut_pos = NULL;
74+ assert_int_equal(term_disp_width(str, 3, &cut_pos), 3);
75+ assert_int_equal(cut_pos - str.start, 3);
76+
77+ cut_pos = NULL;
78+ assert_int_equal(term_disp_width(str, -2, &cut_pos), 0);
79+ assert_int_equal(cut_pos - str.start, 0);
80+
81+ cut_pos = NULL;
82+ assert_int_equal(term_disp_width(str, str.len, &cut_pos), 6);
83+ if (cut_pos) {
84+ printf("%s:%d: cut_pos != NULL\n", __FILE__, __LINE__);
85+ fflush(stdout);
86+ abort();
87+ }
6788 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t