Showing the changes to test/codepoint_width.c (1 of 9 files). Show all
Unified · Split
| @@ -17,9 +17,11 @@ · 16 unmodified lines | ||
| 17 | 17 | |
| 18 | 18 | #include "test_utils.h" |
| 19 | 19 | |
| 20 | +#include <limits.h> | |
| 21 | + | |
| 20 | 22 | #include "misc/codepoint_width.h" |
| 21 | 23 | |
| 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}) | |
| 23 | 25 | |
| 24 | 26 | int main(void) { |
| 25 | 27 | assert_int_equal(W("A"), 1); // Single ASCII character |
| @@ -64,4 +66,23 @@ int main(void) { · 38 unmodified lines | ||
| 64 | 66 | |
| 65 | 67 | // ASCII characters with carriage return |
| 66 | 68 | 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 | + } | |
| 67 | 88 | } |