summaryrefslogtreecommitdiff
path: root/src/code_point.zig
diff options
context:
space:
mode:
authorGravatar Sam Atman2025-05-14 13:14:28 -0400
committerGravatar Sam Atman2025-05-14 13:14:28 -0400
commit9a64ee562117f35c57051ac08b0043bfe2028cf5 (patch)
tree210ba4d3044df5985a1eff10932cc998007f04b8 /src/code_point.zig
parentMake DisplayWidth.setup public (diff)
downloadzg-9a64ee562117f35c57051ac08b0043bfe2028cf5.tar.gz
zg-9a64ee562117f35c57051ac08b0043bfe2028cf5.tar.xz
zg-9a64ee562117f35c57051ac08b0043bfe2028cf5.zip
Add overlong test, which should fail
But does not.
Diffstat (limited to 'src/code_point.zig')
-rw-r--r--src/code_point.zig17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/code_point.zig b/src/code_point.zig
index 13e38bf..e402554 100644
--- a/src/code_point.zig
+++ b/src/code_point.zig
@@ -1,5 +1,3 @@
1const std = @import("std");
2
3/// `CodePoint` represents a Unicode code point by its code, 1/// `CodePoint` represents a Unicode code point by its code,
4/// length, and offset in the source bytes. 2/// length, and offset in the source bytes.
5pub const CodePoint = struct { 3pub const CodePoint = struct {
@@ -116,3 +114,18 @@ test "peek" {
116 try std.testing.expectEqual(@as(?CodePoint, null), iter.peek()); 114 try std.testing.expectEqual(@as(?CodePoint, null), iter.peek());
117 try std.testing.expectEqual(@as(?CodePoint, null), iter.next()); 115 try std.testing.expectEqual(@as(?CodePoint, null), iter.next());
118} 116}
117
118test "overlongs" {
119 // Should not pass!
120 const bytes = "\xC0\xAF";
121 const res = decode(bytes, 0);
122 if (res) |cp| {
123 try testing.expectEqual(@as(u21, '/'), cp.code);
124 try testing.expectEqual(2, cp.len);
125 } else {
126 try testing.expect(false);
127 }
128}
129
130const std = @import("std");
131const testing = std.testing;