From 9a64ee562117f35c57051ac08b0043bfe2028cf5 Mon Sep 17 00:00:00 2001 From: Sam Atman Date: Wed, 14 May 2025 13:14:28 -0400 Subject: Add overlong test, which should fail But does not. --- src/code_point.zig | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/code_point.zig') 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 @@ -const std = @import("std"); - /// `CodePoint` represents a Unicode code point by its code, /// length, and offset in the source bytes. pub const CodePoint = struct { @@ -116,3 +114,18 @@ test "peek" { try std.testing.expectEqual(@as(?CodePoint, null), iter.peek()); try std.testing.expectEqual(@as(?CodePoint, null), iter.next()); } + +test "overlongs" { + // Should not pass! + const bytes = "\xC0\xAF"; + const res = decode(bytes, 0); + if (res) |cp| { + try testing.expectEqual(@as(u21, '/'), cp.code); + try testing.expectEqual(2, cp.len); + } else { + try testing.expect(false); + } +} + +const std = @import("std"); +const testing = std.testing; -- cgit v1.2.3