summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;