diff options
Diffstat (limited to 'src/DisplayWidth.zig')
| -rw-r--r-- | src/DisplayWidth.zig | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/DisplayWidth.zig b/src/DisplayWidth.zig index 621b8c1..04e6b0c 100644 --- a/src/DisplayWidth.zig +++ b/src/DisplayWidth.zig | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | const options = @import("options"); | ||
| 3 | const ArrayList = std.ArrayList; | 4 | const ArrayList = std.ArrayList; |
| 4 | const mem = std.mem; | 5 | const mem = std.mem; |
| 5 | const simd = std.simd; | 6 | const simd = std.simd; |
| @@ -60,6 +61,7 @@ test "strWidth" { | |||
| 60 | const data = try DisplayWidthData.init(testing.allocator); | 61 | const data = try DisplayWidthData.init(testing.allocator); |
| 61 | defer data.deinit(); | 62 | defer data.deinit(); |
| 62 | const self = Self{ .data = &data }; | 63 | const self = Self{ .data = &data }; |
| 64 | const c0 = options.c0_width orelse 0; | ||
| 63 | 65 | ||
| 64 | try testing.expectEqual(@as(usize, 5), self.strWidth("Hello\r\n")); | 66 | try testing.expectEqual(@as(usize, 5), self.strWidth("Hello\r\n")); |
| 65 | try testing.expectEqual(@as(usize, 1), self.strWidth("\u{0065}\u{0301}")); | 67 | try testing.expectEqual(@as(usize, 1), self.strWidth("\u{0065}\u{0301}")); |
| @@ -74,19 +76,21 @@ test "strWidth" { | |||
| 74 | try testing.expectEqual(@as(usize, 1), self.strWidth("\u{2764}")); // Default text presentation | 76 | try testing.expectEqual(@as(usize, 1), self.strWidth("\u{2764}")); // Default text presentation |
| 75 | try testing.expectEqual(@as(usize, 1), self.strWidth("\u{2764}\u{FE0E}")); // Default text presentation with VS15 selector | 77 | try testing.expectEqual(@as(usize, 1), self.strWidth("\u{2764}\u{FE0E}")); // Default text presentation with VS15 selector |
| 76 | try testing.expectEqual(@as(usize, 2), self.strWidth("\u{2764}\u{FE0F}")); // Default text presentation with VS16 selector | 78 | try testing.expectEqual(@as(usize, 2), self.strWidth("\u{2764}\u{FE0F}")); // Default text presentation with VS16 selector |
| 77 | try testing.expectEqual(@as(usize, 0), self.strWidth("A\x08")); // Backspace | 79 | const expect_bs: usize = if (c0 == 0) 0 else 1 + c0; |
| 78 | try testing.expectEqual(@as(usize, 0), self.strWidth("\x7FA")); // DEL | 80 | try testing.expectEqual(expect_bs, self.strWidth("A\x08")); // Backspace |
| 79 | try testing.expectEqual(@as(usize, 0), self.strWidth("\x7FA\x08\x08")); // never less than o | 81 | try testing.expectEqual(expect_bs, self.strWidth("\x7FA")); // DEL |
| 82 | const expect_long_del: usize = if (c0 == 0) 0 else 1 + (c0 * 3); | ||
| 83 | try testing.expectEqual(expect_long_del, self.strWidth("\x7FA\x08\x08")); // never less than 0 | ||
| 80 | 84 | ||
| 81 | // wcwidth Python lib tests. See: https://github.com/jquast/wcwidth/blob/master/tests/test_core.py | 85 | // wcwidth Python lib tests. See: https://github.com/jquast/wcwidth/blob/master/tests/test_core.py |
| 82 | const empty = ""; | 86 | const empty = ""; |
| 83 | try testing.expectEqual(@as(usize, 0), self.strWidth(empty)); | 87 | try testing.expectEqual(@as(usize, 0), self.strWidth(empty)); |
| 84 | const with_null = "hello\x00world"; | 88 | const with_null = "hello\x00world"; |
| 85 | try testing.expectEqual(@as(usize, 10), self.strWidth(with_null)); | 89 | try testing.expectEqual(@as(usize, 10 + c0), self.strWidth(with_null)); |
| 86 | const hello_jp = "コンニチハ, セカイ!"; | 90 | const hello_jp = "コンニチハ, セカイ!"; |
| 87 | try testing.expectEqual(@as(usize, 19), self.strWidth(hello_jp)); | 91 | try testing.expectEqual(@as(usize, 19), self.strWidth(hello_jp)); |
| 88 | const control = "\x1b[0m"; | 92 | const control = "\x1b[0m"; |
| 89 | try testing.expectEqual(@as(usize, 3), self.strWidth(control)); | 93 | try testing.expectEqual(@as(usize, 3 + c0), self.strWidth(control)); |
| 90 | const balinese = "\u{1B13}\u{1B28}\u{1B2E}\u{1B44}"; | 94 | const balinese = "\u{1B13}\u{1B28}\u{1B2E}\u{1B44}"; |
| 91 | try testing.expectEqual(@as(usize, 3), self.strWidth(balinese)); | 95 | try testing.expectEqual(@as(usize, 3), self.strWidth(balinese)); |
| 92 | 96 | ||