diff options
| -rw-r--r-- | src/code_point.zig | 17 |
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 @@ | |||
| 1 | const 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. |
| 5 | pub const CodePoint = struct { | 3 | pub 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 | |||
| 118 | test "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 | |||
| 130 | const std = @import("std"); | ||
| 131 | const testing = std.testing; | ||